cryptopals

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

commit 931e3bc27e51dadfb856737a201ab74697fd7533
parent 05e2ca10d3d3700e70642e27eda6a4580b20458b
Author: mpizzzle <michael.770211@gmail.com>
Date:   Tue, 31 Oct 2017 21:16:41 +0000

set 3 challenge 18 complete

Diffstat:
Aset3/aes_in_ctr_mode.py | 18++++++++++++++++++
1 file changed, 18 insertions(+), 0 deletions(-)

diff --git a/set3/aes_in_ctr_mode.py b/set3/aes_in_ctr_mode.py @@ -0,0 +1,18 @@ +from Crypto.Cipher import AES + +ciphertext = "L77na/nrFsKvynd6HzOoG7GHTLXsTVu9qvY/2syLXzhPweyyMTJULu/6/kXX0KSvoOLSFQ==".decode("base64") +blocks = [ciphertext[i:i + AES.block_size] for i in range(0, len(ciphertext), AES.block_size)] + +key = "YELLOW SUBMARINE" +aes = AES.new(key, AES.MODE_ECB) + +nonce = ''.join(['\x00' for i in range(AES.block_size / 2)]) +block_count = ['\x00' for i in range(AES.block_size / 2)] + +plaintext = "" + +for block in blocks: + plaintext += ''.join([chr(ord(a) ^ ord(b)) for a, b in zip(block, aes.encrypt(nonce + ''.join(block_count)))]) + block_count[0] = chr((ord(block_count[0]) + 1) % 256) #you get the point + +print plaintext