add decryption function
This commit is contained in:
parent
ae00a5783c
commit
f1d1876fcc
18
index.py
18
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__':
|
||||
|
|
Loading…
Reference in New Issue