MD5 algorithm description (Turn)

Source: Internet
Author: User
Tags array integer md5
Algorithm MD5 algorithm Description

1, MD5 algorithm is the input of the data to complement, so that if the data bit length Len to 512 of the result is 448.
That is, the data is extended to k*512+448 bits. That is, k*64+56 Byte, K is an integer.
Specific complement operation: Fill a 1, and then fill 0 to meet the above requirements

2, fill the length of the data:
The original length B of the data is represented by a 64-digit number, and B is represented by two 32 digits. The data is then filled
Make up a multiple of 512 digits in length.

3. Initialize MD5 parameters
Four 32-bit integers (a,b,c,d) are used to compute the information digest, initialized with a hexadecimal-represented number

a=0x01234567
B=0x89abcdef
C=0xfedcba98
d=0x76543210

4, the processing bit operation function

X,y,z is a 32-bit integer.
F (x,y,z) = x&y| Not (X) &z
G (x,y,z) = x&z| Y Not (Z)
H (x,y,z) = X xor Y xor Z
I (x,y,z) = Y xor (X|not (Z))

5, the main transformation process:
Use constant group t[1 ... ], T[i] is a 32-bit integer in 16-digit notation, with 16 32-bit integers for the data
Number Array m[] represents.

The specific process is as follows:

* * Processing Data Original/*
For i = 0 to N/16-1 do

* Each time, the original data is stored in an array x of 16 elements. */
For j = 0 Todo
Set X[j] to m[i*16+j].
End/ending loop to J

/* Save A as AA, B as BB, C as CC, and D as DD.
*/
AA = A
BB = B
CC = C
DD = D

/* 1th Round * *
/* with [ABCD K S] to represent the following operations
A = B + ((A + F (b,c,d) + x[k] + t[i]) <<< s). */

/* Do the following operations. */
[ABCD 0 7 1] [DABC 1 12 2] [Cdab 2 17 3] [BCDA 3
22 4]
[ABCD 4 7 5] [DABC 5 12 6] [Cdab 6 17 7] [BCDA 7
22 8]
[ABCD 8 7 9] [DABC 9 12 10] [Cdab 10 17 11] [BCDA
11 22 12]
[ABCD 12 7 13] [DABC 13 12 14] [Cdab 14 17 15]
[BCDA 15 22 16]

* * * * * 2nd round * * *
/* with [ABCD K S] to represent the following operations
A = B + ((A + G (b,c,d) + x[k] + t[i]) <<< s). */
/* Do the following operations. */
[ABCD 1 5 17] [DABC 6 9 18] [Cdab 11 14 19] [BCDA
0 20 20]
[ABCD 5 5 21] [DABC 10 9 22] [Cdab 15 14 23]
[BCDA 4 20 24]
[ABCD 9 5 25] [DABC 14 9 26] [Cdab 3 14 27] [BCDA
8 20 28]
[ABCD 13 5 29] [DABC 2 9 30] [Cdab 7 14 31] [BCDA
12 20 32]

/* 3rd Round * *
/* with [ABCD K S] to represent the following operations
A = B + ((A + H (b,c,d) + x[k] + t[i]) <<< s). */
/* Do the following operations. */
[ABCD 5 4 33] [DABC 8 11 34] [Cdab 11 16 35]
[BCDA 14 23 36]
[ABCD 1 4 37] [DABC 4 11 38] [Cdab 7 16 39] [BCDA
10 23 40]
[ABCD 13 4 41] [DABC 0 11 42] [Cdab 3 16 43]
[BCDA 6 23 44]
[ABCD 9 4 45] [DABC 12 11 46] [Cdab 15 16 47]
[BCDA 2 23 48]

/* 4th round * *
/* with [ABCD K S] to represent the following operations
A = B + ((A + I (b,c,d) + x[k] + t[i]) <<< s). */
/* Do the following operations. */
[ABCD 0 6 49] [DABC 7 10 50] [Cdab 14 15 51]
[BCDA 5 21 52]
[ABCD 12 6 53] [DABC 3 10 54] [Cdab 10 15 55]
[BCDA 1 21 56]
[ABCD 8 6 57] [DABC 15 10 58] [Cdab 6 15 59]
[BCDA 13 21 60]
[ABCD 4 6 61] [DABC 11 10 62] [Cdab 2 15 63]
[BCDA 9 21 64]

/* Then do the following: *
A = a + AA
B = B + BB
c = C + CC
D = d + DD

End//ending loop on I/*


6, output results.




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.