Is the result of the hash the same as the original value?

This is more a matter of cryptography theory, but is it possible that the result of the hash algorithm will always be the same value as the source? For example, let's say I have a line:

baf34551fecb48acc3da868eb85e1b6dac9de356 

If I get the SHA1 hash, the result:

 4d2f72adbafddfe49a726990a1bcb8d34d3da162 

In theory, is there ever a case where these two values ​​will correspond? I am not specifically asking about SHA1 here - this is just my example. I'm just wondering if hashing algorithms are built in such a way as to prevent this.

+4
source share
4 answers

Well, that will depend on the hashing algorithm - but I would be surprised to see that something would clearly prevent this. In the end, it really doesn't matter.

I suspect this is very unlikely, of course (for cryptographic hashes) ... but even so, this should not cause a problem.

For non-critical hashes (used in hash tables, etc.) it would be wise to return the original value in some cases. For example, in Java, Integer.hashCode() simply returns an inline value.

+8
source

Of course, the Python hashing algorithm for integers returns the value of an integer. So hash (1) == 1.

+4
source

Given a good hashing algorithm that returns seemingly random output, I believe that on average there should be one input that gives the result. Let them say that a hash can give N possible outputs. This means that there are N possible inputs for which this is possible. For each of them, the coefficients of the output signal corresponding to the input are 1 / N, so the expected number of fixed points is N * 1 / N or 1.

+4
source

A hash function can be defined to avoid "fixed points, where hash (x) == x, but your hash queen is slightly different in that you take the string representation in a hexadecimal hash rather than a binary one. In my opinion, a hash design that could break this is unacceptable, and this is mathematically less interesting, since it depends on the arbitrary mapping of 0-F character codes to ASCII.

See Is there a fixed point MD5 where md5 (x) == x? to discuss fixed points in MD5. The calculation of probability will be equally true for hexadecimal hash quines and any other hash function with 128 bits of output.

+2
source

All Articles