-
-
Save chrisolido/71c3f0f31584c78581723ac7eba377db to your computer and use it in GitHub Desktop.
Some throwaway code I used to demonstrate the blowfish cipher with the PyCrypto library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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