Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2013
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.69 KB | None | 0 0
  1. import itertools
  2. import string
  3. import hashlib
  4. import timing
  5. import json
  6. import os
  7. import csv
  8.  
  9. value = raw_input("Enter your MD5 hash: ")
  10.  
  11. if os.path.isfile("degenerated.txt") == False:
  12.     # Generate lists of character combinations, and then combine them in to one
  13.     # big list to be hashed into hashed_list
  14.     oneChar = map(''.join, itertools.product(string.ascii_lowercase, repeat=1))
  15.     twoChar = map(''.join, itertools.product(string.ascii_lowercase, repeat=2))
  16.     threeChar = map(''.join, itertools.product(string.ascii_lowercase, repeat=3))
  17.     fourChar = map(''.join, itertools.product(string.ascii_lowercase, repeat=4))
  18.  
  19.     possibleValues = oneChar + twoChar + threeChar + fourChar
  20.  
  21.     print "List of possible combinations created..."
  22.  
  23.     json.dump(possibleValues, open("degenerated.txt", 'w'))
  24.  
  25.     print "... and written to file."
  26. else:
  27.     print "Values list found, moving on..."
  28.     possibleValues = json.load(open("degenerated.txt"))
  29.  
  30. if os.path.isfile("diction.txt") == False:
  31.  
  32.     hashed_list = (str(hashlib.md5(char).hexdigest()) for char in possibleValues)
  33.     print "Hashed list created..."
  34.     dictToSearch = dict(itertools.izip(hashed_list, possibleValues))
  35.  
  36.     myfile = open('hashdict.csv', 'wb')
  37.     fieldnames = ('md5', 'value')
  38.     myWriter = csv.DictWriter(myfile, fieldnames=fieldnames)
  39.     headers = dict((n,n) for n in fieldnames)
  40.     myWriter.writerow(headers)
  41.     for n in dictToSearch:
  42.         myWriter.writerow(n)
  43.     myfile.close()
  44.    
  45.     #json.dump(dictToSearch, open("diction.txt", 'w'))
  46.     print "... and written to file."
  47.  
  48. else:
  49.     print "Dictionary found, moving on..."
  50.     dictToSearch = json.load(open("diction.txt"))
  51.    
  52. try:
  53.     print "Key = " + dictToSearch[value]
  54. except KeyError:
  55.     print "Hash unable to be decoded"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement