MD5 algorithm implementation
1, the MD5 algorithm is an entered data, so that if the result of the data bit length LEN pair 512 is 448. That is, data is expanded to K * 512 448 bits. That is, k * 64 56 bytes, K is an integer. Specific complex operation: make up one 1, then supplement 0 to satisfy the above requirements 2, the length of the data indicate the original length B of the data with a 64-bit number, indicate B with two 32 digits. At this time, the data is filled with a multiple of 512 bits. 3. Initializing the MD5 parameter four 32-bit integers (A, B, C, D) used to calculate information summary, initialization is the number of hexadecimal representations A = 0x01234567 b = 0x89abcdef c = 0xFedcba98 d = 0x76543210 4, The processing bit operation function X, Y, Z is 32-bit integers. 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 the constant group T [1 ... 64], T [i] is 16-binding of the 32-bit integer, 16, 16 32-bit integer array m [] is represented.
The specific process is as follows: / * Processing data original * / for i = 0 to n / 16-1 do / * Each time, the data original text is stored in the array x of 16 elements. * / For j = 0 to 15 do set X [j] to m [i * 16 j]. END / End to j's cycle / * Save A AA, B AS BB, C AS CC, And D as dd. * / Aa = a bb = b cc = C DD = D / * The first round * / / * is indicated by [ABCD KSI] A = B ((A F (B, C, D) X [K] T [I]) < << s). * / / * do the folload 16 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] [BCDA 7 22 8] [ABC 9 12 10] [CDAB 10 17 11] [BCDA 11 22 12] [ABCD 12 7 13] [DABC 13 12 14 ] [CDAB 14 17 15] / * The second round * * / / * is represented by [ABCD KSI] A = B ((A G (B, C, D) X [ K] T [I]) <<< s). * / / * do the folload 16 Operations. * / [Abcd 1 5 17] [DABC 6 9 18] [CDAB 11 14 19] [BCDA 0 20 20] [ABCD 5 5 21] [CDAB 15 14 23] [ABCD 9 5 25] [DABC 14 9 26] [CDAB 3 14 27] [BCDA 8 20 28] [ABCD [DABC 2 9 30] [BCDA 12 20 32] / * The third round * / / * is indicated by [ABCD KSI] A = B ((A H (B) , C, D) X [K] T [I]) <<< S ). * / / * Do the folload 16 Operations. * / [Abcd 5 4 33] [CDAB 11 16 35] [BCDA 14 23 36] [ABCD 1 4 37] [DABC 4 11 38] [CDAB 7 16 39] [ABCD 13 4 41] [CDAB 3 16 43] [BCDA 6 23 44] [ABCD 9 4 45] [DABC 12 11 46] [CDAB [BCDA 2 23 48] / * The fourth round * / / * is represented by [ABCD KSI] A = B ((A I (B, C, D) X [K] T [i]) <<<