From f1d1876fcca94d8c898909ebbbd5b70d0dfb7e3c Mon Sep 17 00:00:00 2001 From: Vicky Rampin Date: Thu, 11 Nov 2021 23:18:05 -0500 Subject: [PATCH] add decryption function --- index.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/index.py b/index.py index 11de23e..653ecd6 100644 --- a/index.py +++ b/index.py @@ -19,9 +19,11 @@ def encrypt(text, key): return cipher_text -def decrypt(): - greet = '\nhello decryption' - return greet +def decrypt(text, key): + # make decrypter + decrypter = AES.new(key, AES.MODE_CFB) + plain_text = decrypter.decrypt(text) + return plain_text def main(): @@ -36,14 +38,20 @@ def main(): # read the text file in and make it a string with no line breaks text = args.file.read().replace('\n', '') + # print encrypted text + print("Original file contents:") + print(text) + # encrypt the file encrypted_text = encrypt(str.encode(text), key) # print encrypted text - print("Encrypted file created. Contents:") + print("\nEncrypted file created. Contents:") print(encrypted_text) - print(decrypt()) + # decrypt and print decrypted text + print("\nDecrypted file. Contents:") + print(decrypt(encrypted_text, key)) if __name__ == '__main__':