Advertisement
Guest User

Untitled

a guest
Sep 26th, 2022
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | Software | 0 0
  1. #pycryptodome
  2. from Crypto.Cipher import AES
  3.  
  4. key = bytearray.fromhex('11111111111111111111111111111111')
  5. iv = bytearray.fromhex('4D4554000000000100000000')
  6. aad = bytearray.fromhex('3033333333333333333333333333333333')
  7. #TSecurity.AuthenticationEncryption + 16 * 0x33
  8.  
  9. cipher = AES.new(key, AES.MODE_GCM, nonce=iv)
  10.  
  11. ciphertext = bytearray.fromhex('b662a493a5dfdbccc1dc832271bae416945f2e0474d102d2c7941fcd50c678534083e5d1520ae04c3038a281d176b6b2a1ce6e15fe861f4689b7fe7909f309908a40f843e9ceff7675f00b0e217b7620')
  12.  
  13. och = ciphertext.hex()
  14. print(f'Original ciphertext is {och}\n')
  15. plaintext = cipher.decrypt(ciphertext)
  16. plaintext = plaintext[:-12]
  17. plth = plaintext.hex()
  18. print(f'Plaintext is {plth}\n')
  19.  
  20. cipher2 = AES.new(key, AES.MODE_GCM, nonce=iv, mac_len=16)
  21. cipher2.update(aad)
  22. genciphertext, tag = cipher2.encrypt_and_digest(plaintext)
  23.  
  24. tagh = tag.hex()
  25. gcph = genciphertext.hex()
  26. print(f'Generated ciphertext is {gcph} with tag {tagh}\n')
  27.  
  28. #cipher3 = AES.new(key, AES.MODE_GCM, nonce=iv, mac_len=12)
  29. #cipher3.update(aad)
  30. #data = cipher3.decrypt_and_verify(ciphertext[:-12], ciphertext[-12:]);
  31.  
  32. #datah = data.hex()
  33. #print(f'Plaintext is {datah}\n')
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement