Skip to content

Instantly share code, notes, and snippets.

@bngsudheer
Created January 28, 2013 08:58
Show Gist options
  • Save bngsudheer/4654029 to your computer and use it in GitHub Desktop.
Save bngsudheer/4654029 to your computer and use it in GitHub Desktop.
Encrypt and decrypt using DES
# Encrpyt the string 'abcdefghijklmnop'
from Crypto.Cipher import DES
from Crypto import Random
iv = Random.get_random_bytes(8)
des1 = DES.new('issecret', DES.MODE_CFB, iv)
text = 'abcdefghijklmnop'
cipher_text = des1.encrypt(text)
print cipher_text
# Decrpyt the cipher text
des2 = DES.new('issecret', DES.MODE_ECB)
print des2.decrypt(cipher_text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment