Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pycryptodome
- from Crypto.Cipher import AES
- key = bytearray.fromhex('11111111111111111111111111111111')
- iv = bytearray.fromhex('4D4554000000000100000000')
- aad = bytearray.fromhex('3033333333333333333333333333333333')
- #TSecurity.AuthenticationEncryption + 16 * 0x33
- cipher = AES.new(key, AES.MODE_GCM, nonce=iv)
- ciphertext = bytearray.fromhex('b662a493a5dfdbccc1dc832271bae416945f2e0474d102d2c7941fcd50c678534083e5d1520ae04c3038a281d176b6b2a1ce6e15fe861f4689b7fe7909f309908a40f843e9ceff7675f00b0e217b7620')
- och = ciphertext.hex()
- print(f'Original ciphertext is {och}\n')
- plaintext = cipher.decrypt(ciphertext)
- plaintext = plaintext[:-12]
- plth = plaintext.hex()
- print(f'Plaintext is {plth}\n')
- cipher2 = AES.new(key, AES.MODE_GCM, nonce=iv, mac_len=16)
- cipher2.update(aad)
- genciphertext, tag = cipher2.encrypt_and_digest(plaintext)
- tagh = tag.hex()
- gcph = genciphertext.hex()
- print(f'Generated ciphertext is {gcph} with tag {tagh}\n')
- #cipher3 = AES.new(key, AES.MODE_GCM, nonce=iv, mac_len=12)
- #cipher3.update(aad)
- #data = cipher3.decrypt_and_verify(ciphertext[:-12], ciphertext[-12:]);
- #datah = data.hex()
- #print(f'Plaintext is {datah}\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement