I read SHA-1 and MD5 algorithms.

Source: Internet
Author: User

I have always heard of these two algorithms and occasionally used them, but I have never thought about how to complete them.

Fear of the unknown will prompt us to continue learning. Then there came the famous saying of Zhuangzi: knowledge is infinite, life is limited, and infinite knowledge is achieved with limited life. Actually, 2B. Even so, some handy knowledge can still take some time to look.

Of course, the first thing we should do is wiki. Here we will give a thumbs up for the Wiki. When we are idle, We will write and donate as soon as we have money.

Security Hash Algorithm(Secure Hash AlgorithmHttp://zh.wikipedia.org/wiki/SHA1

Message Digest algorithm version 5(Message-Digest algorithm 5, abbreviatedMD5Http://zh.wikipedia.org/wiki/MD5

I don't need to handle the algorithms. It's just like that, and the two algorithms are the same. What's important is that the above two full names are true for many serious issues.

In my understanding, algorithms are the same in both the MD5 and Sha series. what is different is some of the details and the final output length. Among them, the hash value initialization and the number and key value initialization, the difference between these three aspects, derived from a series of different algorithms. We can see that MD5 is bits, sha1 is 160bits, and a bunch of self-explanatory algorithms, shaits/sha256/sha384/sha512, generally, we can see that the length of the string is the length of the bits mentioned above divided by 4. Intuitively, the longer the security, the more secure it is. Right, the concept of security here is actually that it is not easy to "collide", that is, to get the same hash value for different content. This kind of thing will inevitably happen, once this happens, it may be terrible.

I describe this algorithm in a straightforward language to show that I really understand it.

The input is a pile of data, and the data is 0 and 1. The data in the computer is both 0 and 1.

Data has a length. for processing convenience, the first step is to add the data to a multiple length of 512. The first part is 1, and the middle part is 0, the following is a 64-bit representation of the actual length of the data. Of course, MD5 is small-end, and Sha series is large-end. I don't know why, but it is written like this in the algorithm.

The second step is to divide the 512 n data into N parts, each of which is bits.

The third step is to process each part cyclically and perform n operations. Before doing this, we will define a bunch of numbers of H, which can be regarded as hash seeds, but I don't know how people call it, 32-bit or 64-bit, 4: 5 or 8. It is the specific algorithm.

Step 4: Check every n times. Divide the data of bits into 32 bits * 16, and then extend the number of 16 to 64 or 80. Of course, this is also based on the algorithm. As for how to expand, it is to take a few, it's just a bit of basic budget.

The fifth step is to cycle the number of 64 or 80, and calculate the number of hash seeds defined in the previous step. Then, let's go back and forth and make the hash seed a little effort. Every time you perform this operation, you can calculate a pile of numbers and add the logarithm to the corresponding hash seed.

We can see that after 64n or 80n times of tossing in step 4 and step 5, the hash seeds initially initialized are completely invisible, which is the result of hash.

Step 6 is to concatenate the hash fruit and close the job. For example, if there are four 32-bit hash fruits, the 128-bit MD5 value is obtained after being concatenated.

In this way, we can change the data of any length to the information data of a fixed length, and in fact it is still difficult to reverse push, from which a large number of logical operations can be seen. Theoretically ...... In theory, it can be calculated, that is, the amount of computing is a bit large.

 

I read SHA-1 and MD5 algorithms.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.