ulvis.paste.net

Paste Search Dynamic
Recent pastes
Crypton Cipher
  1. # your code goes here
  2.  
  3. from Crypto.Cipher import AES
  4. import random
  5.  
  6. print ("enter a message to encrypt")
  7. msg = raw_input().encode('utf-8')
  8. #message used for encryption
  9.  
  10. # same key for encryption and decryption both
  11.  
  12. iv = ''.join([chr(random.randint(0, 0xFF)) for i in range(16)])
  13. #random iv value
  14.  
  15. msg  += ' ' * (16 - len(msg) % 16)
  16. #padded message in 16 bytes format
  17.  
  18. cipher_encrypt = AES.new(key,AES.MODE_CBC,IV = iv)
  19. # encryption of IV using AES
  20.  
  21. cipher_txt = cipher_encrypt.encrypt(msg)
  22. #encrypting user entered message
  23.  
  24. print ("encrypted value : " + cipher_txt)
  25.  
  26. #print "IV value : " + iv
  27.  
  28. cipher_decrypt = AES.new(key,AES.MODE_CBC,IV = iv)
  29. #decryting user entered message
  30. print ("Decrypted Message : " + cipher_decrypt.decrypt(cipher_txt))
  31.  
Parsed in 0.008 seconds