Task2_7.py 483 B

12345678910111213
  1. def encryptInCTR(key,data,fileNameToEncrypt):
  2. data=bytes(data, 'utf-8')
  3. cipher = AES.new(key, AES.MODE_CTR)
  4. start = timer()
  5. ct_bytes = cipher.encrypt(data)
  6. end= timer()
  7. print("Time Taken to Encrypt is ",(end-start))
  8. print("Time Taken to Decrypt per byte is ",(end-start)/len(data))
  9. nonce = b64encode(cipher.nonce).decode('utf-8')
  10. ct = b64encode(ct_bytes).decode('utf-8')
  11. writeFileInBytes(bytes(ct,"utf-8"),fileNameToEncrypt)
  12. return nonce