Would it be possible to find a hash of a string that itself includes the hash result?

Something like:

$$h = Hash(\texttt{"Some String"} \mathbin\| h)$$

• I think that will break the pre-image property. Oct 3, 2022 at 19:49
• If the hash function is random-looking, then no. It's hard to reduce this to any of the usual security notions, as far as I can tell, and I think you can construct silly counterexamples. Note that you can find solutions to $h = Hash(blah || f(h))$ for some interesting functions $f$, such as in your favourite signature scheme.
– K.G.
Oct 4, 2022 at 6:48
• Here's a GIF that displays its own MD5 hash. Note that this does not imply that the answer to the question is affirmative. Nov 5, 2022 at 3:59

Yes, it is possible. You can create many such functions. For instance, define hash function as last 16 symbols or bytes of the original message:

$$h(x) = substring(x, length(x)-16, length(x))$$

As @kelalaka noticed, it is trivial to find preimages for any hash that fits your requirement. That's why such functions are useless for typical cryptographic purposes.

• This answer is only correct for a definition of the word “hash” that does not include any security properties. This is a site about cryptography, so the word “hash” means a cryptographic hash function (or in some contexts, but not here, a password hashing function), or at least (since we can't even prove that such a function exists) a function that is or was widely believed to be one. Truncating the input is unambiguously not a cryptographic hash function. Oct 6, 2022 at 16:32
• @Gilles'SO-stopbeingevil': No. According to your logic, any mention of PRNG should be treated as CSPRNG. But that is not true. We treat PRNG namely as PRNG. And when CSPRNG is impotant, is is mentioned explicitly as such. That's why as long as there is no requirements about cryptographic properties of hash it means hash function in the generic meaning. Furthermore, I pointed out that such function is useless for cryptographic purposes. I find your comment not helpful. Oct 6, 2022 at 18:19

If you have a cryptographic hash that is not 'broken', yet, essentially the only way to create this special string is through brute force.

Yes, in theory if you apply enough brute force computations, you can find such strings.