### Reversible Hash Function?

• Is there any reversible hash function?

The hash function like SHA and MD5 are not reversible. I would like to know if there exist some reversible hash functions?

If it's reversible it isn't a hash.

Reversible hash is referred to as encryption. This might be more suited for crypto SE

The context here, "security.stackexchange" is criptography... But, suppose that is not: **the term "hash function" is not exclusive of cryptography**, it is general, and "crytographic hash function" is only a special subclass of *hash function*... So this question seems more generic tham the answers and comments posted here. "reversible function" is an existential concept... "reversible hash function" is only a supposition about inverse function existence (as @EricLagergren commented).

Read up on the difference between pseudorandom functions (PRFs) and pseudorandom permutations (PRPs).

think you just want to encode/decode data. if you really are needing something akin to indexing, you can use the trie-family of data structures for similar performance to hashes. each branch of the trie tree will have so many elements, and your total path is an array of indexes. almost like a url `myTree/23/4/240/12`. Just make an array of each index, encode() those indices, send the array as json or your favorite format and decode() them later. if you keep all indices under 256 you can just convert to/from ascii or utf-8 and use a string instead of an array, which COULD also be encrypted

7 years ago

The definition of a cryptographic hash function includes resistance to preimages: given h(x), it should be infeasible to recover x. A hash function being "reversible" is the exact opposite of that property. Therefore, you can have no more a "reversible hash function" than you can have a fish allergic to water.

Possibly you might want a hash function which, for most people, is a cryptographic hash function with all its property, but which also includes some sort of trapdoor which allow reversing it if you know some specific secret. This sort of things might exist but requires mathematics, like asymmetric cryptography. I am not aware of such a construction right now, but one might possibly jury-rig something based on a RSA modulus, or maybe an elliptic curve with coordinates taken modulo a RSA modulus (I don't have a precise design in mind, but I have the intuition that it can be done that way).

I know OP already accepted the answer, but I interpreted the question as though OP was looking for a non-cryptographic hash function.

The context here, "security.stackexchange" is criptography... But, suppose that is not: **the term "hash function" is not exclusive of cryptography**, it is general, and "crytographic hash function" is only a special subclass of *hash function*.

not exactly a hash, as it would be of variable size, but simply run length encoding (or otherwise compressing the data eg zlib) and then xoring that against a known secret psuedo random value would in theory give a reversible hash. but it might not end up being much smaller than the original data