# Why can't hash coding be reversed?

Why is it impossible to reverse a hash code? There could be some way to crack this coding?

Because, in general, hashing is not injective.

Being injective is a property of a function which states that each distinct element of the domain is mapped to distinct element of codomain. It means that given a value of a function, you will (if it is a valid value) know from what it came from. For more on this, see injective function.

Therefore, if hashing function $h$ is not injective, it can happen that two elements $A,B$ could be mapped to $H =: h(A) = h(B)$ and from knowing only $H$ you cannot determine whether it is the result of hashing $A$ or $B$.

But, there is a concept of perfect hashing which is injective.

If your question is about cryptographic nature of hashing, then the reason is the same as why any good cipher is "unbreakable". It is not that it is impossible to decrypt it (it surely cannot be the case, because then the reciever of cipher could not do it), but is just very very time consuming without knowing the key. You can find out more on that at Cryptography Stack Exchange.

As Sandro said, the issue is that a hash function is not injective.

This is easily understood by recognizing that you are mapping from a larger set to a smaller set, and thus losing information.

Perhaps it's easier to understand in terms of other non-injective functions. Say you have pairs of integers $$(x,y)$$ and you map them to their projection $$y$$. You have sacrificed the information $$x$$ to perform this mapping, and there is no way to regain it. If you ask me what is the inverse of 3, I am unable to tell you a unique answer, because every $$(x,3)$$ maps to 3.