123456789101112131415161718192021222324252627282930 |
- def decryptInCTR(key,fileNameToDecrypt,nonce,fileNameToSavePT):
- ct = b64decode(getDataInBytes(fileNameToDecrypt))
- nonce = b64decode(nonce)
- cipher = AES.new(key, AES.MODE_CTR, nonce=nonce)
- start=timer()
- pt = cipher.decrypt(ct)
- end=timer()
- print("Time Taken to Decrypt is ",(end-start))
- print("Time Taken to Decrypt per byte is ",((end-start)/len(pt)))
- pt=pt.decode("utf-8")
- writeFile(pt,fileNameToSavePT)
- return pt
- generateFiles()
- key=generateKey(16)
- kbData=getData("kbfile.txt")
- mbData=getData("mbfile.txt")
- nonce=encryptInCTR(key,kbData,"Encrypted_kbfile.txt")
- ptKb=decryptInCTR(key,"Encrypted_kbfile.txt",nonce,"Decypted_kbfile.txt")
- nonce=encryptInCTR(key,mbData,"Encrypted_mbfile.txt")
- ptMb=decryptInCTR(key,"Encrypted_mbfile.txt",nonce,"Decypted_mbfile.txt")
- if ptKb==kbData and ptMb==mbData:
- print("Encryption and decryption done successfully")
- else:
- print("Error in Encryption and Decryption")
|