commit bb32ac7587c90cd99c68e33a9c202768bee443da parent b04061a8d718ab0181f02ba9361ff37951baffdf Author: mpizzzle <michael.770211@gmail.com> Date: Sat, 7 Oct 2017 11:49:34 +0100 alternate solutions for challenge 3 & 4 Diffstat:
| A | set1/detect_single_character_xor_char_frequency.py | | | 23 | +++++++++++++++++++++++ |
| A | set1/single_byte_xor_cipher_char_frequency.py | | | 20 | ++++++++++++++++++++ |
2 files changed, 43 insertions(+), 0 deletions(-)
diff --git a/set1/detect_single_character_xor_char_frequency.py b/set1/detect_single_character_xor_char_frequency.py @@ -0,0 +1,22 @@ +import sys + +with open('files/4.txt') as f: + hex_strings = f.read().splitlines() + +frequent_letters = "etaoi " +candidate = "" +candidate_frequency = 0 + +for hex in hex_strings: + for plaintext in [''.join([chr(x ^ ord(a)) for a in hex.decode("hex")]) for x in range(128)]: + frequency = 0 + + for char in plaintext: + if char in frequent_letters: + frequency += 1 + + if frequency > candidate_frequency: + candidate = plaintext + candidate_frequency = frequency + +print candidate+ \ No newline at end of file diff --git a/set1/single_byte_xor_cipher_char_frequency.py b/set1/single_byte_xor_cipher_char_frequency.py @@ -0,0 +1,19 @@ +import sys + +hex = "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736" +frequent_letters = "etaoi " +candidate = "" +candidate_frequency = 0 + +for plaintext in [''.join([chr(x ^ ord(a)) for a in hex.decode("hex")]) for x in range(128)]: + frequency = 0 + + for char in plaintext: + if char in frequent_letters: + frequency += 1 + + if frequency > candidate_frequency: + candidate = plaintext + candidate_frequency = frequency + +print candidate+ \ No newline at end of file