# hash算法(Hash algorithm)-其他

## hash算法(Hash algorithm)

### 介绍

hash算法，是把任意长度的输入（又叫做预映射pre-image）通过散列算法变换成固定长度的输出，该输出就是散列值，hash值。

hash算法准确的说是一种思想，是算法分类。MD4、MD5、SH1等具有hash算法的特征。

1、输出长度固定

2、多对一

（1）hash值相同，原数据可能相同，可能不同。当然，相同数据的hash必然相同
（2）hash无法准确逆推

1、获取hash算法

2、获取hash原文

————————

### introduce

Hash algorithm is to transform the input of any length (also known as pre mapping pre image) into the output of fixed length through hash algorithm. The output is hash value and hash value.

Hash algorithm is exactly an idea and algorithm classification. MD4, MD5 and sh1 have the characteristics of hash algorithm.

1. Fixed output length

Regardless of the input length, the output is fixed bit or byte data.

2. Many to one

The input is infinite and the output is limited. Therefore, there is an inevitable phenomenon, that is, different inputs get the same value through hash algorithm.

Can launch:

(1) If the hash value is the same, the original data may be the same or different. Of course, the hash of the same data must be the same
(2) Hash cannot be pushed back accurately

### Verify data integrity

For example, the website provides file download function, which generally provides hash algorithm and official hash value calculated for files.
After downloading, the user can calculate the file through the hash algorithm and check with the official results to ensure the consistency between the downloaded file and the official file.

### Sorting and quick find

If it is a data set of large quantities and large text, it is very troublesome and slow to quickly find out whether there is a certain data, delete and update a certain data according to the text sequence.

An optimization idea is to hash each text. Further, you can sort the hash value and find a data. You can calculate the hash value of the data, and then find it in turn. If you want to delete or update, take out the implicit text of the matched hash value.

### hash破解

1. Get hash algorithm

There are two ideas. One is to input data and then observe whether the output is the result of known commonly used hash algorithms.
Second, whether the algorithm process can be obtained through the commonly used hash algorithm ideas, such as rolling division and address space.

2. Get the original hash

As mentioned earlier, due to the characteristics of hash algorithm, it is impossible to accurately deduce the original text according to the hash value.

However, in a fixed context, input has strong similarity and relevance, such as setting password.

Collect and calculate the original text and hash value of the weak password in advance. Assuming that the hash value of the password is obtained, obtain the original text of the password by looking up the table, and then carry out the next test.