Created
February 16, 2011 23:50
-
-
Save johnpena/830588 to your computer and use it in GitHub Desktop.
Generating a rainbow table for md5
This file contains hidden or 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
| import hashlib | |
| def allstrings(alphabet, length): | |
| """ Get all strings made of characters from `alphabet` up to length of `length`.""" | |
| if length <= 0 or len(alphabet) == 0: return [] | |
| alphabet = set([alpha for alpha in alphabet]) | |
| allstr = set([ch for ch in alphabet]) | |
| length -= 1 | |
| while length > 0 : | |
| new_level = [x + y for x in allstr for y in alphabet] | |
| allstr.update(new_level) | |
| length -= 1 | |
| return allstr | |
| def generate_md5_rainbow(plaintext_passwords, salt=None): | |
| rainbow_table = {} | |
| for p in plaintext_passwords: | |
| if salt: | |
| rainbow_table[p] = hashlib.md5(salt + p).hexdigest() | |
| else: | |
| rainbow_table[p] = hashlib.md5(p).hexdigest() | |
| return rainbow_table | |
| if __name__ == '__main__': | |
| import string | |
| rainbow_table = generate_md5_rainbow(allstrings('abcd1234', 4)) | |
| f = open('/tmp/md5rainbowtable.txt', 'w') | |
| f.write(str(rainbow_table)) | |
| f.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment