Created
March 8, 2011 21:07
-
-
Save MarkNenadov/861057 to your computer and use it in GitHub Desktop.
Some throwaway code I used to demonstrate the RC5 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 RC5 | |
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 = RC5.new('abcdefghijklmnop', RC5.MODE_ECB) | |
ciphertext = crypt_obj.encrypt(pad_string(plaintext)) | |
print "Plaintext: " + plaintext | |
print "RC5 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
I wonder though, seems like thus far, I can't find RC5 in Py 2.7*?