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
|
return cipher_text
|
||||||
|
|
||||||
|
|
||||||
def decrypt():
|
def decrypt(text, key):
|
||||||
greet = '\nhello decryption'
|
# make decrypter
|
||||||
return greet
|
decrypter = AES.new(key, AES.MODE_CFB)
|
||||||
|
plain_text = decrypter.decrypt(text)
|
||||||
|
return plain_text
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -36,14 +38,20 @@ def main():
|
||||||
# read the text file in and make it a string with no line breaks
|
# read the text file in and make it a string with no line breaks
|
||||||
text = args.file.read().replace('\n', '')
|
text = args.file.read().replace('\n', '')
|
||||||
|
|
||||||
|
# print encrypted text
|
||||||
|
print("Original file contents:")
|
||||||
|
print(text)
|
||||||
|
|
||||||
# encrypt the file
|
# encrypt the file
|
||||||
encrypted_text = encrypt(str.encode(text), key)
|
encrypted_text = encrypt(str.encode(text), key)
|
||||||
|
|
||||||
# print encrypted text
|
# print encrypted text
|
||||||
print("Encrypted file created. Contents:")
|
print("\nEncrypted file created. Contents:")
|
||||||
print(encrypted_text)
|
print(encrypted_text)
|
||||||
|
|
||||||
print(decrypt())
|
# decrypt and print decrypted text
|
||||||
|
print("\nDecrypted file. Contents:")
|
||||||
|
print(decrypt(encrypted_text, key))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue