# Is it possible to work out the hash algorithm from a list of known message-hash pairs?

For example, in my situation I know hash(20) = 486e9638177faf1f34e49910491b77af. I also know the hashes for all values from 0 to 20.

Is it possible to work out the algorithm used to hash these values?

-

In practice, maybe, if you got additional information, such as that the hash function is known to conform to some published standard (you just don't know which).

Theoretically, though, for any finite list of values, there is always more than one bounded algorithm that generates the list. You can never be absolutely sure you figured out the correct algorithm.

-

A hash function is not supposed to provide this kind of security: if you have access to some message m and H(m), you can compute h(m) yourself for a given hash function h and check if they match. So, if you really have hash outputs, you can test the usual suspects MD4, MD5, SHA-1, SHA-2, RIPEMD and a few others depending on the hash length. If it's a custom design you will not find it, but that's security by obscurity which is outside the security model we generally use in crypto.

However, if it is a MAC, then it's expected to be impossible to recover the MAC key.

-