Current location - Quotes Website - Personality signature - Brief introduction of hash algorithm
Brief introduction of hash algorithm
Hash algorithm, also known as hash algorithm, is a method to extract small numbers from arbitrary data. Hash algorithm is a sign to ensure the uniqueness of data with short information. This symbol is related to every byte of data, and it is difficult to find the opposite law. Therefore, when the original data changes, its flag value will also change.

An excellent hash algorithm will realize:

However, in different usage scenarios, such as data structure and security field, some features will be emphasized.

Take HashMap as an example, the key (hash value) corresponds to one (or more data), and the function of the key is that the requirements for anti-collision are not so high. In other words, the keys generated by hashing only need to ensure that the values are roughly evenly placed in different buckets. But the set performance of the whole algorithm is directly related to the speed of hash value generation, so the speed of hash value generation is particularly important at this time, such as String.hashCode () of JDK:

In cryptography, the function of hash algorithm is mainly used for message summarization and signature, which verifies the integrity of the whole message. This requires extremely high anti-collision and anti-tampering ability, followed by speed. Take MD5 as an example, its output length is 128 bits, and the designed expected collision probability is 1/(2 128), which is a very small number.

At present, the popular hash algorithms are MD5, SHA- 1 and SHA-2.

It can be seen that the most important difference between these popular algorithms is "strong anti-collision".