From 740fb62cc5f364ed84e4fddec952fd2bdb22a260 Mon Sep 17 00:00:00 2001 From: Bill Buchanan Date: Mon, 8 Feb 2021 18:34:15 +0000 Subject: [PATCH] Update possible_ans.md --- unit02_symmetric/lab/possible_ans.md | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/unit02_symmetric/lab/possible_ans.md b/unit02_symmetric/lab/possible_ans.md index 0cbc467..6ce6a70 100644 --- a/unit02_symmetric/lab/possible_ans.md +++ b/unit02_symmetric/lab/possible_ans.md @@ -285,22 +285,25 @@ def decrypt(ciphertext,key, mode): encobj = AES.new(key,mode) return(encobj.decrypt(ciphertext)) -key = hashlib.sha256(password).digest() +key = hashlib.sha256(password.encode()).digest() plaintext = Padding.appendPadding(plaintext,blocksize=Padding.AES_blocksize,mode='CMS') -print "After padding (CMS): "+binascii.hexlify(bytearray(plaintext)) +print ("After padding (CMS): ",binascii.hexlify(plaintext.encode())) -ciphertext = encrypt(plaintext,key,AES.MODE_ECB) -print "Cipher (ECB): "+binascii.hexlify(bytearray(ciphertext)) +ciphertext = encrypt(plaintext.encode(),key,AES.MODE_ECB) +print ("Cipher (ECB): ",binascii.hexlify(ciphertext)) plaintext = decrypt(ciphertext,key,AES.MODE_ECB) -plaintext = Padding.removePadding(plaintext,mode='CMS') -print " decrypt: "+plaintext + +plaintext = Padding.removePadding(plaintext.decode(),blocksize=Padding.AES_blocksize,mode='CMS') -plaintext=val +print (" decrypt: ",plaintext) + ``` +A sample is [here](https://repl.it/@billbuchanan/ch02an03#main.py). + A sample run is:
 napier@napier-virtual-machine:~$ python d1.py hello hello123