Q:

Is a hash result ever the same as the source value?

This is more of a cryptography theory question, but is it possible that the result of a hash algorithm will ever be the same value as the source? For example, say I have a string:
baf34551fecb48acc3da868eb85e1b6dac9de356

If I get the SHA1 hash on it, the result is:
4d2f72adbafddfe49a726990a1bcb8d34d3da162

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

A:

Well, it would depend on the hashing algorithm - but I'd be surprised to see anything explicitly prevent this. After all, it really shouldn't matter.
I suspect it's very unlikely to happen, of course (for cryptographic hashes)... but even if it does, that shouldn't cause a problem.
For non-crypto hashes (used in hash tables etc) it would be perfectly reasonable to return the source value in some cases. For example, in Java, Integer.hashCode() just returns the embedded value.

A:

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

A:

Given a good hashing algorithm, one that returns a seemingly random output, I believe there should be on average one input that gives itself as the output.  Let's say the hash can give N possible outputs.  That means there are N possible inputs for which this is possible.  For each of those, the odds of the output matching the input is 1/N, so there the expected number of fixed points is N*1/N, or 1.

