Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverse the hash() function in python

Tags:

python

not sure if this is possible but in python there is a hash() function which takes a string or an integer and generates a [EDIT not-unique] integer representation of that input.

My question is (after searching online), how to reverse the generated integer back into the original String.

Thanks.

like image 899
Lucas Ou-Yang Avatar asked Jun 30 '13 19:06

Lucas Ou-Yang


1 Answers

You can't theoretically do that, at least not in an efficient manner (read: "in reasonable time"), even if the hash is not cryptographically secure.

Now if your search space is small enough (say, for example, if the only possible input is a list of 1000 words), you might pre-compute a sorted table of all possible hashes (as a key) and their corresponding inputs and perform a O(log(n)) a lookup on that.

This would of course give you a list of possible results, as hashes are not unique. Now, again, if your search space is small enough, you may only have unique results for each and every input. But we can't say anything sure about it unless we know more about the source of your data.

like image 112
ereOn Avatar answered Oct 14 '22 08:10

ereOn