Skip to content

Instantly share code, notes, and snippets.

@MarkNenadov
Created March 8, 2011 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarkNenadov/861061 to your computer and use it in GitHub Desktop.
Save MarkNenadov/861061 to your computer and use it in GitHub Desktop.
Some throwaway code I used to demonstrate the IDEA cipher with the PyCrypto library
# Sample code by Mark Nenadov.
#
# Warning, this is OLD legacy code. It hasn't been tested in semi recent versions
# of Python or PyCrypto.
#
# You may use this however you wish, but I retain no responsibility whatsoever for how
# you use it and provide it with no warranty, either.
from Crypto.Cipher import IDEA
INPUT_SIZE = 8
def pad_string(str):
new_str = str
pad_chars = INPUT_SIZE - (len(str) % INPUT_SIZE)
if pad_chars != 0:
for x in range(pad_chars):
new_str += " "
return new_str
plaintext = "Meet me and Charles at 7pm at the bridge."
crypt_obj = IDEA.new('abcdefghijklmnop', IDEA.MODE_ECB)
ciphertext = crypt_obj.encrypt(pad_string(plaintext))
print "Plaintext: " + plaintext
print "IDEA Cyphertext: " + ciphertext
print "Back to Plaintext: " + crypt_obj.decrypt(ciphertext)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment