Skip to content

Instantly share code, notes, and snippets.

@johnpena
Created February 16, 2011 23:50
Show Gist options
  • Select an option

  • Save johnpena/830588 to your computer and use it in GitHub Desktop.

Select an option

Save johnpena/830588 to your computer and use it in GitHub Desktop.
Generating a rainbow table for md5
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