Reputation:
If I have two strings that are identical in value, is it guaranteed that hash(s1) == hash(s2)
without using hashlib
? Also, what is the upper bound on the number of digits in the hash?
Is there an alternative to hash
that is invertable? I understand hash functions are not meant to be used like this. But a 1-1 mapping from strings to short hexadecimal strings that can be inverted and is guaranteed to be different for each string?
Will this work:
import zlib
# compress
zlib.compress("foo")
zlib.decompress(zlib.compress("foo")) == "foo" # always true?
Thanks.
Upvotes: 0
Views: 899
Reputation: 250951
YES.
>>>help(hash)
Help on built-in function hash in module builtins:
hash(...)
hash(object) -> integer
Return a hash value for the object. Two objects with the same value have
the same hash value. The reverse is not necessarily true, but likely.
Upvotes: 7