Can I identify a hash algorithm based on the initi

2020-05-27 15:52发布

问题:

If I have both the initial key and the hash that was created, is there any way to determine what hashing algorithm was used?

For example:

  • Key: higher
  • Hash: df072c8afcf2385b8d34aab3362020d0
  • Algorithm: ?

回答1:

Well, given that there are a finite number of popular hash algorithms, maybe what you propose is not so ridiculous.

But suppose I asked you this:

If I have an input and an output, can I determine the function?

Generally speaking, no, you cannot determine the inner-workings of any function simply from knowing one input and one output, without any additional information.

// very, very basic illustration
if (unknownFunction(2) == 4) {
    // what does unknownFunction do?
    // return x + 2?
    // or return x * 2?
    // or return Math.Pow(x, 2)?
    // or return Math.Pow(x, 3) - 4?
    // etc.
}


回答2:

By looking at the length, you can decide which algorithms to try. MD5 and MD2 produce 16-byte digests. SHA-1 produces 20 bytes of output. Etc. Then perform each hash on the input and see if it matches the output. If so, that's your algorithm.

Of course, if more than the "key" was hashed, you'll need to know that too. And depending on the application, hashes are often applied iteratively. That is, the output of the hash is hashed again, and that output is hashed… often thousands of times. So if you know in advance how many iterations were performed, that can help too.

There's nothing besides the length in the output of a cryptographic hash that would help narrow down the algorithm that produced it.



回答3:

  1. The hash seems to contain only hexadecimal characters (each character represents 4bits)

  2. Total count is 32 characters -> this is a 128-bits length hash.

  3. Standard hashing algorithms that comply with these specs are: haval, md2, md4, md5 and ripemd128.

  4. Highest probability is that MD5 was used.

  5. md5("higher") != df072c8afcf2385b8d34aab3362020d0

  6. Highest probability is that some salt was used.

  7. Highest probability still remains MD5.



回答4:

Didn't match any of the common hashing algorithms:

http://www.fileformat.info/tool/hash.htm?text=higher

Perhaps a salt was added prior to hashing...



回答5:

Not other than trying out a bunch that you know and seeing if any match.