top | item 7857996

(no title)

pedrox | 11 years ago

This hash is very weak. You can actually find many preimages of a given hash value in seconds with a meet-in-the-middle attack: https://gist.github.com/pedrox/eb8d674bf2b8be63da0f

discuss

order

lunixbochs|11 years ago

You can brute force it insanely fast by iterating from the rightmost character and caching the entire hash prefix.

This hash doesn't scramble input very well, so you can fiddle with individual characters to converge on any desired hash value.

Record the "closest" hash value to your target generated by this loop, apply (only) that character change, repeat. If the hash value stops converging, add a character. This naive version pretty often does the job in 5 full iterations or so, which means (5 * len(s) * len(alphabet)) = maybe ~3000 total hashes to get a solution.

    for i in xrange(len(s)):
        copy = s
        for c in alphabet:
            copy[i] = c
            diff = abs(hash(copy) - 666)
            best = min(diff, best)

pedrox|11 years ago

Also, this hash function is linear so it has the equivalent substrings property. One can take advantage of it and be able to generate preimages even faster. Take a preimage and find m equivalent strings for n substrings of it. Replacing the substring with their equivalent will get you n to the m-th preimages that hash to the same value.