Question: Write a Linux Python utility aes.py for encrypting and decrypting a single text file. The text file is encrypted on the command line by using
Write a Linux Python utility aes.py for encrypting and decrypting a single text file. The text file is encrypted on the command line by using the AES standard encryption method.
$python aes.py e filename.txt filename.txtaes for encrypting filename.txt with output file named filename.txtaes
$python aes.py d filename.txtaes filename.txtback AESkey for dencrypting filename.txtaes with output file named filename.txtback
Note: Do not wite the program from scratch, just complete the code for the function decrypt of the program template below:
import sys
from cryptography.fernet import Fernet
def encryptinfile outfile:
key Fernet.generatekey
printAES Key: key
fernet Fernetkey
for line in infile:
name line.strip
encName fernet.encryptnameencode
outfile.writeencNamedecode
with openAESKeysysargvw as aeskey: aeskey.writekeydecode
infile.close
outfile.close
def decryptinfile outfile, key:
# TODO for homework
infile.close
outfile.close
# Call the main function.
if namemain:
if lensysargv:
printUsage: python aes.py mode infile.txt outfile.txt key"
exit
operation sysargv
infile opensysargvr
outfile opensysargvw
key sysargv
if operation e:
# encrypts
encryptinfileoutfile
elif operation d:
# decrypt
decryptinfileoutfile,key
else:
# error
printInvalid operation."
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
