cryptopals

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 49211a163b7743a59220a9e189fe5b9a3bb9c866
parent e071794ffd90ed473d9daeca62388f3d17b45800
Author: mpizzzle <michael.770211@gmail.com>
Date:   Sat,  7 Oct 2017 15:41:14 +0100

formatting

Diffstat:
Mset1/break_repeating_key_xor.py | 8++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/set1/break_repeating_key_xor.py b/set1/break_repeating_key_xor.py @@ -4,7 +4,7 @@ frequent_letters = "etaoi ETAOI" def distance(str1, str2): return ''.join([bin(ord(a) ^ ord(b)) for a, b in zip(str1, str2)]).count('1') - + def get_candidate_key_length(file, accuracy): candidate_distance = sys.float_info.max candidate_length = 0 @@ -39,12 +39,12 @@ def decrypt(key, msg): return ''.join([chr(ord(key[i % len(key)]) ^ ord(char)) for i, char in enumerate(msg)]) with open('files/6.txt') as f: - file = f.read().decode("base64") - + file = f.read().decode("base64") + key_length = get_candidate_key_length(file, 10) split_file = [file[i:i + key_length] for i in range(0, len(file), key_length)] transposed_blocks = [''.join([block[x] for block in split_file[:len(split_file)- 1]]) for x in range(key_length)] - key = ''.join([get_candidate_xor_byte(transposed_block) for transposed_block in transposed_blocks]) + print key print decrypt(key, file) \ No newline at end of file