Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Crypto.Cipher import AES
- from Crypto.Util.strxor import strxor
- from binascii import hexlify
- from Crypto.Random import get_random_bytes
- # Random generation
- K = get_random_bytes(AES.block_size)
- cipher = AES.new(K, AES.MODE_CBC)
- # Original Message
- M1 = K #bytes(K,encoding="utf-8")
- M2 = K #bytes(K,encoding="utf-8")
- Cm0 = cipher.encrypt(('\0' * AES.block_size).encode("utf-8"))
- Cm1 = cipher.encrypt(strxor(Cm0, M1))
- Tm = Cm2 = cipher.encrypt(strxor(Cm1, M2))
- N1 = get_random_bytes(AES.block_size)#'qwertyuiop'.encode("utf-8")
- # Inject second message after the first message
- Cx0 = cipher.encrypt(('\0' * AES.block_size).encode("utf-8"))
- Cx1 = cipher.encrypt(strxor(Cx0, M1))
- Cx2 = cipher.encrypt(strxor(Cx1, N1))
- # X needs to *encrypt* to the same value as Cm1
- #X = strxor(cipher.decrypt(Cx1), Cx2)
- X = strxor(strxor(Cx0, M1), Cx2)
- Cx3 = cipher.encrypt(strxor(Cx2, X))
- Tx = Cx4 = cipher.encrypt(strxor(Cx3, M2))
- # MAC should be same here
- print("Tm = '%s'" % hexlify(Tm))
- print("Tx = '%s'" % hexlify(Tx))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement