HACKER Q&A
📣 sebmellen

Is There a Known Recursive Hash?


As a point of curiosity, I have been wondering if there is a known string, which when hashed with a hashing algorithm, results in a hash which has the same content as the string (a recursive hash).

The following example does not work, but is only for illustration:

Say we have a hex string like "6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b". When hashed with , this hash would then result in the same hex string: "6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b".

I know the chance of this is near zero, but it would be interesting to know nonetheless! I haven't been able to find anything online.


  👤 s-tear Accepted Answer ✓
I’ll do you one better; I’ve managed to use my highly advanced engineer body to birth a “pure recursive hashing algorithm”.

def MY_HASHING_ALGORITHM(s): return s

To answer your question; In theory, yes. In practice highly unlikely. Hash _functions_ attempt to store arbitrary inputs in unique indices within some dimensional space. This is predominantly achieved through performing some math against the Unicode (think integer) representation of said input (think string).

It may surprise you to find out that most hashed data structure implementations closely model how we think of Arrays/Lists. The result of the hash function is the index where we “put” your “value”; when you attempt to “get” that “value” again we use the same hash function to find where in memory we initially “put” that “value”.

With regard to data structures; good hash functions avoid “collisions”, a collision is when multiple unique inputs to your hash function result in a non-unique output. Given that hash functions are designed around avoiding this we must understand that to accommodate even moderately large data-sets a by-product of most hash functions is a seemingly arbitrary, mostly unrecognizable and likely numerical value.

But I still haven’t answered your question; and I won’t; there’s a stupid mathematical way (depending on the function) to quickly answer this question but I think doing some curious investigation on your own behalf will provide you with more benefit.

So I’ll leave you with a couple of questions:

What are the most common hash functions? How can I implement them in my language of choice? How can I generate millions of “inputs” and verify each of their corresponding “outputs”?

By then, you should be close to or in possession of your answer.


👤 FatalLogic
It's probably not the kind of hash you mean, but CRC32 0xFFFFFFFF outputs 0xFFFFFFFF