cryptopals

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

commit 05e2ca10d3d3700e70642e27eda6a4580b20458b
parent 4a233b969ad61659fca447ee1578beefc22c7d4e
Author: mpizzzle <michael.770211@gmail.com>
Date:   Tue, 31 Oct 2017 20:23:13 +0000

fixing the same off by 1 error in all challenges (even though it doesn't apply to some)

Diffstat:
Mset1/break_repeating_key_xor.py | 2+-
Mset1/detect_single_character_xor.py | 2+-
Mset1/detect_single_character_xor_char_frequency.py | 2+-
Mset1/single_byte_xor_cipher.py | 2+-
Mset1/single_byte_xor_cipher_char_frequency.py | 2+-
Mset2/byte_at_a_time_ecb_decryption.py | 2+-
Mset2/byte_at_a_time_ecb_decryption_harder.py | 2+-
Mset3/cbc_padding_oracle.py | 2+-
8 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/set1/break_repeating_key_xor.py b/set1/break_repeating_key_xor.py @@ -21,7 +21,7 @@ def get_candidate_key_byte(transposed_block): candidate = '' candidate_frequency = 0 - for c in range(0xff): + for c in range(256): plaintext = ''.join([chr(c ^ ord(a)) for a in transposed_block]) frequency = sum([plaintext.count(frequent_letters[n]) for n in range(len(frequent_letters))]) diff --git a/set1/detect_single_character_xor.py b/set1/detect_single_character_xor.py @@ -2,6 +2,6 @@ with open('files/4.txt') as f: hex_strings = f.read().splitlines() for hex in hex_strings: - for plaintext in [''.join([chr(x ^ ord(a)) for a in hex.decode("hex")]) for x in range(128)]: + for plaintext in [''.join([chr(x ^ ord(a)) for a in hex.decode("hex")]) for x in range(256)]: if " the " in plaintext: print plaintext diff --git a/set1/detect_single_character_xor_char_frequency.py b/set1/detect_single_character_xor_char_frequency.py @@ -6,7 +6,7 @@ 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)]: + for plaintext in [''.join([chr(x ^ ord(a)) for a in hex.decode("hex")]) for x in range(256)]: frequency = sum([plaintext.count(frequent_letters[n]) for n in range(len(frequent_letters))]) if frequency > candidate_frequency: diff --git a/set1/single_byte_xor_cipher.py b/set1/single_byte_xor_cipher.py @@ -1,5 +1,5 @@ hex = "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736" -for plaintext in [''.join([chr(x ^ ord(a)) for a in hex.decode("hex")]) for x in range(128)]: +for plaintext in [''.join([chr(x ^ ord(a)) for a in hex.decode("hex")]) for x in range(256)]: if " a " in plaintext: print plaintext diff --git a/set1/single_byte_xor_cipher_char_frequency.py b/set1/single_byte_xor_cipher_char_frequency.py @@ -3,7 +3,7 @@ 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)]: +for plaintext in [''.join([chr(x ^ ord(a)) for a in hex.decode("hex")]) for x in range(256)]: frequency = sum([plaintext.count(frequent_letters[n]) for n in range(len(frequent_letters))]) if frequency > candidate_frequency: diff --git a/set2/byte_at_a_time_ecb_decryption.py b/set2/byte_at_a_time_ecb_decryption.py @@ -21,7 +21,7 @@ def find_len_of_padding(): aaa = buf = "AAAAAAAAAAAAAAA" for i in range(len(encryption_oracle('')) - find_len_of_padding()): - dict = {encryption_oracle(aaa[i:] + chr(j))[:AES.block_size] : chr(j) for j in range(0xff)} + dict = {encryption_oracle(aaa[i:] + chr(j))[:AES.block_size] : chr(j) for j in range(256)} cipher = encryption_oracle(buf[i % AES.block_size:]) aaa += dict[cipher[AES.block_size * (i / AES.block_size) : AES.block_size * ((i + AES.block_size) / AES.block_size)]] diff --git a/set2/byte_at_a_time_ecb_decryption_harder.py b/set2/byte_at_a_time_ecb_decryption_harder.py @@ -49,7 +49,7 @@ buf = aaa = "AAAAAAAAAAAAAAA" aa = ''.join("A" for i in range(mod)) for i in range(len(encryption_oracle('')) - prefix - len_of_padding()): - dict = {encryption_oracle(aa + aaa[i:] + chr(j))[mod + prefix : mod + prefix + AES.block_size] : chr(j) for j in range(0xff)} + dict = {encryption_oracle(aa + aaa[i:] + chr(j))[mod + prefix : mod + prefix + AES.block_size] : chr(j) for j in range(256)} cipher = encryption_oracle(aa + buf[i % AES.block_size:]) aaa += dict[cipher[mod + prefix + (AES.block_size * (i / AES.block_size)) : mod + prefix + (AES.block_size * ((i + AES.block_size) / AES.block_size))]] diff --git a/set3/cbc_padding_oracle.py b/set3/cbc_padding_oracle.py @@ -39,7 +39,7 @@ for b_idx in reversed(range((len(ciphertext) / AES.block_size) - 1)): guessed_byte = block[AES.block_size - i - 1] found = False - for c in range(0xff + 1): + for c in range(256): if chr(c) != guessed_byte: block[AES.block_size - i - 1] = chr(c) blocks[b_idx] = ''.join(block)