cryptopals

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

commit ed6e472c272093e1fbc331faf037c79522fc32e4
parent 3bb622bcd3eb5c3c166a586fd554c37a96306744
Author: mpizzzle <michael.770211@gmail.com>
Date:   Sat, 21 Oct 2017 15:49:42 +0100

completely abstracting plaintext into oracle function

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

diff --git a/set2/byte_at_a_time_ecb_decryption.py b/set2/byte_at_a_time_ecb_decryption.py @@ -11,13 +11,13 @@ key = Random.new().read(AES.block_size) plaintext = str(pt1 + pt2 + pt3 + pt4).decode("base64") # no peeking! def encryption_oracle(msg): - return AES.new(key, AES.MODE_ECB).encrypt(msg + ''.join(['\x04' for i in range(AES.block_size - (len(msg) % AES.block_size))]) if len(msg) % AES.block_size != 0 else msg) + return AES.new(key, AES.MODE_ECB).encrypt(msg + plaintext + ''.join(['\x04' for i in range(AES.block_size - (len(msg + plaintext) % AES.block_size))]) if len(msg + plaintext) % AES.block_size != 0 else msg + plaintext) aaa = buf = "AAAAAAAAAAAAAAA" -for i in range(len(plaintext)): - dict = {encryption_oracle(aaa[i:] + chr(j)) : chr(j) for j in range(0xff)} - cipher = encryption_oracle(buf[i % AES.block_size:] + plaintext) +for i in range(len(encryption_oracle(''))): + dict = {encryption_oracle(aaa[i:] + chr(j))[:AES.block_size] : chr(j) for j in range(0xff)} + 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)]] print aaa[AES.block_size - 1:]