Write a script in Python to implement the AES algorithm. The official documentat
ID: 3745613 • Letter: W
Question
Write a script in Python to implement the AES algorithm. The official documentation of AES can be found at: http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf. Your script must comply to the following requirements:
1. It should read input from a text file plaintext.txt, write the encrypted output in HEX form to another text file encryptedtext.txt and subsequently decrypt encryptedtext.txt and save the decrypted output to decryptedtext.txt.
2. The file plaintext.txt
should contain the following text. In your output, you are supposed to
encrypt and than decrypt the following text:
“This is an unusual paragraph. I’m curious how quickly you can find out what is so unusual
about it? It looks so plain you would think nothing was wrong with it! In fact, nothing is
wrong with it! It is unusual though. Study it, and think about it, but you still may not
find anything odd. But if you work at it a bit, you might find out! Try to do so without
any coaching! You most probably won’t, at first, find anything particularly odd or unusual
or in any way dissimilar to any ordinary composition. That is not at all surprising, for it is
no strain to accomplish in so short a paragraph a stunt similar to that which an author did
throughout all of his book, without spoiling a good writing job, and it was no small book at
that.”
3. Use the following as your key:
lukeimyourf ather
Explanation / Answer
key=lukeimyourf ather
fi have created two functions 1)encrypt 2)decrypt.
i am using plaintext file to read data and then i am sending msg for encryption.
After encryption i store data in encrypt.txt , then i read that file and decrypt data and stores it in decrypt.txt.
//////////////////////////////////////////////////
def decrypt(self):
f=fopen(encryptedtxt.txt,”r”)
F1=f.readlines();
For x in f1:
Msg=msg+x;
enc = base64.b64decode(msg)
cipher = AES.new(self.key, AES.MODE_CBC, iv())
dec = cipher.decrypt(msg)
f=fopen(decryptedtxt.txt,”a”)
f.writelines(msg);
f.close()
//////////////////////////////
def encrypt(key,msg):
iv = Random.new().read(BS)
cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=AES.block_size * 8)
encrypted_msg = cipher.encrypt(pad(str(msg)))
f=fopen(encryptedtxt.txt,”a”)
f.writelines(encrypted_msg);
f.close()
////////////////////////////////////////
F=open(“plaintext.txt”,”r”);
F1=f.readlines();
For x in f1:
msg=msg+x;
f.close()
encrypt(keyVal, msg)
decrypt()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.