From 25b8edae4ac888674fea95a59a49140867e1b4eb Mon Sep 17 00:00:00 2001 From: RubenCGomes Date: Tue, 19 Nov 2024 20:29:00 +0000 Subject: [PATCH] makes decrypt return text or write into file --- delivery1/lib/asymmetric_functs.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/delivery1/lib/asymmetric_functs.py b/delivery1/lib/asymmetric_functs.py index 638a533..6d2569a 100644 --- a/delivery1/lib/asymmetric_functs.py +++ b/delivery1/lib/asymmetric_functs.py @@ -107,14 +107,17 @@ def decrypt_hybrid(private_key, encrypted_data): # main function to decrypt the file -def decrypt_file(private_key, encrypted_file, decrypted_file): +def decrypt_file(private_key, encrypted_file, decrypted_file=None): with open(encrypted_file, 'rb') as f: encrypted_content = f.read() decrypted_content = decrypt_hybrid(private_key, encrypted_content) - with open(decrypted_file, 'wb') as f: - f.write(decrypted_content) + if decrypted_file is None: + return decrypted_content + else: + with open(decrypted_file, 'wb') as f: + f.write(decrypted_content) # function to load a private key from a file