Skip to content

Instantly share code, notes, and snippets.

@MarkNenadov
Created March 8, 2011 21:00
Show Gist options
  • Save MarkNenadov/861037 to your computer and use it in GitHub Desktop.
Save MarkNenadov/861037 to your computer and use it in GitHub Desktop.
Some throwaway code I used to demonstrate the blowfish 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 Blowfish
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 = Blowfish.new('abcdefghijklmnop', Blowfish.MODE_ECB)
ciphertext = crypt_obj.encrypt(pad_string(plaintext))
print "Plaintext: " + plaintext
print "Blowfish 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