0

I found a hash of an encrypted PIN code (in this case 9999) which I know to be encrypted using AES CTR.

Problem is, I can't figure how to write this in python. I know the key and the IV are the same however I understand CTR mode does not require an IV but instead uses a counter. I just can't figure out how to use the IV/Counter part of CTR.

from Crypto.Cipher import AES
from Crypto.Util import Counter
import base64
import binascii


hashed = "aEotxA=="
encrypted = base64.b64decode(hashed)

key = b'4170ac2a2782a1516fe9e13d7322ae48'
iv = b'4170ac2a2782a1516fe9e13d7322ae48'

aes = AES.new(key, AES.MODE_CTR)


print (binascii.hexlify(aes.decrypt(encrypted)))

I've also tried using Counter:

ctr = Counter.new(128, initial_value=int_of_string(iv[:16]))
aes = AES.new(key, AES.MODE_CTR, ctr)

Any help would be great thank you.

Decrypt3d
  • 1
  • 2
  • 1
    A bit terminology; the CTR mode once initiated increments the IV where the IV usually set to be full counter or 95-bit nonce 32 bit counter. For each encryption, under the same key, the nonce ( number used only once) must be distinct.t – kelalaka May 12 '21 at 11:04
  • If the formerly posted key was a productive key, it should no longer be used because SO has a history. Then it's probably better to delete the whole post (however, the post is still visible for members with a reputation > 10K). – Topaco May 14 '21 at 18:06

0 Answers0