Created
January 4, 2012 12:41
-
-
Save stattrak-dragonlore/ee722ceec4b0f5caeb8c to your computer and use it in GitHub Desktop.
Revisions
-
stattrak-dragonlore revised this gist
Jan 4, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,7 @@ def mul32(x, y): table = {} def meet_in_the_middle(target, len, charset=string.letters): global table for chars in itertools.product(charset, repeat=len/2): s = "".join(chars) -
stattrak-dragonlore revised this gist
Jan 4, 2012 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -46,9 +46,9 @@ def meet_in_the_middle(target, len, charset=string.letters+string.digits): x = ord(s[0]) << 7 for c in s: x = mul32(1000003, x) ^ ord(c) if x in table: for e in table[x]: print s + e def main(): -
stattrak-dragonlore created this gist
Jan 4, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,60 @@ # http://www.nruns.com/_downloads/advisory28122011.pdf # http://bugs.python.org/issue13703 import sys import string import itertools # hash function used by python string object def hash(s): slen = len(s) x = ord(s[0]) << 7 for c in s: x = mul32(1000003, x) ^ ord(c) x = x ^ slen if x == -1: x = -2 return x def mul32(x, y): z = (x * y) & 0xffffffff if z & 0x80000000: z -= 0x100000000 return z table = {} def meet_in_the_middle(target, len, charset=string.letters+string.digits): global table for chars in itertools.product(charset, repeat=len/2): s = "".join(chars) x = target ^ len for c in s[::-1]: #extended-euclid(1000003, 2**32) -> 2021759595 x = mul32(x ^ ord(c), 2021759595) if x not in table: table[x] = [s,] else: table[x].append(s) for chars in itertools.product(charset, repeat=len/2): s = "".join(chars) x = ord(s[0]) << 7 for c in s: x = mul32(1000003, x) ^ ord(c) if x in table: for e in table[x]: print s + e def main(): hash_target = 9 meet_in_the_middle(target=hash_target, len=6) print "hash value is %d" % hash_target if __name__ == "__main__": main()