From 68d8db56d55bda74076ce51d08dfedaa49a2afb9 Mon Sep 17 00:00:00 2001 From: Bill Buchanan Date: Thu, 3 Feb 2022 12:46:28 +0000 Subject: [PATCH] Update README.md --- unit02_symmetric/lab/README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/unit02_symmetric/lab/README.md b/unit02_symmetric/lab/README.md index d609857..65e0408 100644 --- a/unit02_symmetric/lab/README.md +++ b/unit02_symmetric/lab/README.md @@ -202,26 +202,27 @@ The code should be: ```python from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.primitives import padding +from cryptography.hazmat.backends import default_backend import hashlib import sys import binascii val='hello' -password='hello' +password='hello123' plaintext=val def encrypt(plaintext,key, mode): method=algorithms.AES(key) - cipher = Cipher(method, mode) + cipher = Cipher(method,mode, default_backend()) encryptor = cipher.encryptor() ct = encryptor.update(plaintext) + encryptor.finalize() return(ct) def decrypt(ciphertext,key, mode): method=algorithms.AES(key) - cipher = Cipher(method, mode) + cipher = Cipher(method, mode, default_backend()) decryptor = cipher.decryptor() pl = decryptor.update(ciphertext) + decryptor.finalize() return(pl) @@ -240,6 +241,8 @@ def unpad(data,size=128): key = hashlib.sha256(password.encode()).digest() +print("Before padding: ",plaintext) + plaintext=pad(plaintext.encode()) print("After padding (CMS): ",binascii.hexlify(bytearray(plaintext))) @@ -251,6 +254,8 @@ plaintext = decrypt(ciphertext,key,modes.ECB()) plaintext = unpad(plaintext) print(" decrypt: ",plaintext.decode()) + + ``` The Repl.it code is [here](https://repl.it/@billbuchanan/aes01#main.py)