Skip to content

Instantly share code, notes, and snippets.

@stattrak-dragonlore
Created January 4, 2012 12:41
Show Gist options
  • Select an option

  • Save stattrak-dragonlore/ee722ceec4b0f5caeb8c to your computer and use it in GitHub Desktop.

Select an option

Save stattrak-dragonlore/ee722ceec4b0f5caeb8c to your computer and use it in GitHub Desktop.

Revisions

  1. stattrak-dragonlore revised this gist Jan 4, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion meet-in-the-middle.py
    Original 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+string.digits):
    def meet_in_the_middle(target, len, charset=string.letters):
    global table
    for chars in itertools.product(charset, repeat=len/2):
    s = "".join(chars)
  2. stattrak-dragonlore revised this gist Jan 4, 2012. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions meet-in-the-middle.py
    Original 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
    if x in table:
    for e in table[x]:
    print s + e


    def main():
  3. stattrak-dragonlore created this gist Jan 4, 2012.
    60 changes: 60 additions & 0 deletions meet-in-the-middle.py
    Original 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()