Skip to content

Instantly share code, notes, and snippets.

@lopes
Last active August 7, 2024 13:39
Show Gist options
  • Save lopes/9d358d9881317e82f94b to your computer and use it in GitHub Desktop.
Save lopes/9d358d9881317e82f94b to your computer and use it in GitHub Desktop.
Just a test of AES usage I wrote while coursing Cryptography I on Stanford (via Coursera) #python #cryptography #exercise #aes
#!/usr/bin/python
from Crypto.Cipher import AES
from Crypto.Util import Counter
key = bytes.fromhex('36f18357be4dbd77f050515c73fcf9f2')
ciphertext = bytes.fromhex('69dda8455c7dd4254bf353b773304eec0ec7702330098ce7f7520d1cbbb20fc388d1b0adb5054dbd7370849dbf0b88d393f252e764f1f5f7ad97ef79d59ce29f5f51eeca32eabedd9afa9329')
iv = ciphertext[:16] #not needed for CTR, mult. of 16
cipher = ciphertext[16:]
mode = AES.MODE_CTR#CBC
counter = Counter.new(256, prefix=iv)#, initial_value=int('69dda8455c7dd425', 16))
decryptor = AES.new(key, mode, iv, counter=counter)
plain = decryptor.decrypt(cipher)
print(plain.decode('utf-8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment