Created
April 12, 2009 20:57
-
-
Save gcr/94141 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env python | |
| #-*- coding:utf-8 -*- | |
| import sha | |
| import sys | |
| # Note: This must be in lower case | |
| target = '30b72655c3877e8954c846ba0ff9f0fa78078802' | |
| # Uppercase template. | |
| template = "8 %s ON AN %s" | |
| # Uppercase letters | |
| begin_letters = ("T", "O") | |
| # This script cracks tests on http://intelligence-test.net/ | |
| # by matching template agains all words that start with begin_letters | |
| # until one is found that matches target's SHA-1 hash. | |
| # 8 T____ ON AN O____ -> 8 TENTACLES ON AN OCTOPUS | |
| # Show confirmation | |
| print "Cracking: " + template % tuple([x + "___" for x in begin_letters]) | |
| # Thanks to http://code.activestate.com/recipes/190465/ | |
| def combinations(items, n=0): | |
| # combinations( [[1, 3, 5], [2, 4, 6]]) -> [1, 2], [1, 4], [1, 6], [3, 2], ... | |
| if n==len(items): | |
| yield [] | |
| else: | |
| for item in items[n]: | |
| for cc in combinations(items, n+1): | |
| yield [item] + cc | |
| # Get a word list | |
| # FOR each line in the dictionary that begins with one of the starting letters but | |
| # is not a name (/usr/share/dict/words usually contains names), | |
| # take that line and convert it to uppercase, then strip the trailing newline. | |
| words = [] | |
| print "Loading dictionary..." | |
| for letter in begin_letters: | |
| words.append( [ line.upper().strip() for line in file('/usr/share/dict/words') | |
| if line.upper().startswith(letter) | |
| and not line[0].isupper() | |
| ] ) | |
| print "Have %d words." % sum([len(l) for l in words]) | |
| print "Guessing %d combinations" % reduce(lambda x,y: x*y, [len(w) for w in words]) | |
| count = 0 | |
| found = False | |
| sys.stdout.write("%10d " % 0) | |
| for guess in combinations(words): | |
| count+=1 | |
| if count % 20000 == 0: | |
| sys.stdout.write(".") | |
| sys.stdout.flush() | |
| if count % 1000000 == 0: | |
| sys.stdout.write(" (%s)\n" % (template % tuple(guess))) | |
| sys.stdout.write("%10d " % count) | |
| hash = sha.new(template % tuple(guess)).hexdigest() | |
| if hash == target: | |
| print "\nHit: " + template % tuple(guess) | |
| found = True | |
| print "Took %d guesses." % count | |
| break | |
| print "" | |
| if not found: | |
| print "No match. Sorry." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment