cryptopals

https://cryptopals.com/
Log | Files | Refs

aes_in_cbc_mode.py (464B)


      1 from Crypto.Cipher import AES
      2 
      3 file = open('files/10.txt') .read().decode("base64")
      4 
      5 split_file = [file[i:i + AES.block_size] for i in range(0, len(file), AES.block_size)]
      6 key = "YELLOW SUBMARINE"
      7 aes = AES.new(key, AES.MODE_ECB)
      8 iv = ''.join(['x00' for i in range(AES.block_size)])
      9 plaintext = ""
     10 
     11 for cipher_text in split_file:
     12     plaintext += ''.join([chr(ord(a) ^ ord(b)) for a, b in zip(iv, aes.decrypt(cipher_text))])
     13     iv = cipher_text
     14 
     15 print plaintext