fork(2) download
  1. '''
  2. In this project you will implement two encryption/decryption systems, one using AES in CBC mode and another using AES in counter mode (CTR). In both cases the 16-byte encryption IV is chosen at random and is prepended to the ciphertext. For CBC encryption we use the PKCS5 padding scheme discussed in class (13:50).
  3.  
  4. While we ask that you implement both encryption and decryption, we will only test the decryption function. In the following questions you are given an AES key and a ciphertext (both are hex encoded) and your goal is to recover the plaintext and enter it in the input boxes provided below.
  5.  
  6. For an implementation of AES you may use an existing crypto library such as PyCrypto (Python), Crypto++ (C++), or any other. While it is fine to use the built-in AES functions, we ask that as a learning experience you implement CBC and CTR modes yourself.
  7. '''
  8.  
  9. from Crypto.Cipher import AES
  10. from binascii import a2b_base64
  11.  
  12. def AES_128_ECB_decrypt(data, key):
  13. cipher = AES.new(key, AES.MODE_ECB)
  14. return cipher.decrypt(data)
  15.  
  16. key = 'YELLOW SUBMARINE'
  17. data = a2b_base64("dsnfK5ED5srKjK7Fz4Q38/ttd+stL/9WnDzlJvAo7WBsjI5YJc2gmAYayNfm")
  18. print AES_128_ECB_decrypt(data, key)
Runtime error #stdin #stdout #stderr 0.02s 6940KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 18, in <module>
  File "prog.py", line 14, in AES_128_ECB_decrypt
  File "/usr/lib/python2.7/dist-packages/Crypto/Cipher/blockalgo.py", line 295, in decrypt
    return self._cipher.decrypt(ciphertext)
ValueError: Input strings must be a multiple of 16 in length