0% found this document useful (0 votes)
8 views6 pages

MD5 Algorithm

The document outlines the steps of the MD5 algorithm, starting with converting a message into bits and padding it to fit a specific length. It details the initialization of vectors, the splitting of the message into blocks, and the use of mathematical functions to process these blocks through multiple rounds. The final steps involve modular arithmetic and bit manipulation to produce a hash value.

Uploaded by

Quân Phạm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views6 pages

MD5 Algorithm

The document outlines the steps of the MD5 algorithm, starting with converting a message into bits and padding it to fit a specific length. It details the initialization of vectors, the splitting of the message into blocks, and the use of mathematical functions to process these blocks through multiple rounds. The final steps involve modular arithmetic and bit manipulation to produce a hash value.

Uploaded by

Quân Phạm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

MD5 Algorithm

Step 1: Convert the message into bits using ASCII table


A fox = 01100001 00100000 01100110 01101111 01111000 (40 bits)
[A] [] [f] [o] [x]

Step 2: Add a 1 to the end of the converted message, then add zeros until it reach 448 mod 512 bits
long
Add 1 to the end: 01100001 00100000 01100110 01101111 01111000 1 (41 bit)

We want the message to consist of a length of a number that mod 512 = 448. So we add 407 zeros (0) to the end
of the message. The message becomes:

01100001 00100000 01100110 01101111 01111000 10000000 00000000 00000000


00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

Step 3: Convert the length of the initial message to a 64-bit value, then added to the end of the
padded message to create a multiply-of-512-bit-long message.
The length of the initial message (40 bits) is convert to binary in form of a 64-bit length then added to the
message. 40 (DEC)= 101000 (BIN).

So the added message is 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00101000.

The full message now is :

01100001 00100000 01100110 01101111 01111000 10000000 00000000 00000000


00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00101000

Step 4: Initialization vectors (A, B, C, D)


Using:

A = 01 23 45 67 (01234567) (HEX) = 00000001001000110100010101100111 (BIN) = 19088743 (DEC)

B = 89 ab cd ef (89abcdef) (HEX) = 10001001101010111100110111101111 (BIN) = 2309737967 (DEC)

C = fe dc ba 98 (fedcba98) (HEX) = 11111110110111001011101010011000 (BIN) = 4275878552 (DEC)


D = 76 54 32 10 (76543210) (HEX) = 01110110010101000011001000010000 (BIN) = 1985229328 (DEC)

Step 5: The input M and the constant K


The full message will now be split into 16 32-bit block as and labeled as follows:

M0 - 01100001 00100000 01100110 01101111 (BIN) = 6120666F (HEX) = 1629513327 (DEC)


M1 - 01111000 10000000 00000000 00000000 (BIN) = 78800000 (HEX) = 2021654528 (DEC)
M2 - 00000000 00000000 00000000 00000000 (BIN) = 00000000 (HEX) = 0 (DEC)
M3 - 00000000 00000000 00000000 00000000 (BIN) = 00000000 (HEX) = 0 (DEC)
M4 - 00000000 00000000 00000000 00000000 (BIN) = 00000000 (HEX) = 0 (DEC)
M5 - 00000000 00000000 00000000 00000000 (BIN) = 00000000 (HEX) = 0 (DEC)
M6 - 00000000 00000000 00000000 00000000 (BIN) = 00000000 (HEX) = 0 (DEC)
M7 - 00000000 00000000 00000000 00000000 (BIN) = 00000000 (HEX) = 0 (DEC)
M8 - 00000000 00000000 00000000 00000000 (BIN) = 00000000 (HEX) = 0 (DEC)
M9 - 00000000 00000000 00000000 00000000 (BIN) = 00000000 (HEX) = 0 (DEC)
M10 - 00000000 00000000 00000000 00000000 (BIN) = 00000000 (HEX) = 0 (DEC)
M11 - 00000000 00000000 00000000 00000000 (BIN) = 00000000 (HEX) = 0 (DEC)
M12 - 00000000 00000000 00000000 00000000 (BIN) = 00000000 (HEX) = 0 (DEC)
M13 - 00000000 00000000 00000000 00000000 (BIN) = 00000000 (HEX) = 0 (DEC)
M14 - 00000000 00000000 00000000 00000000 (BIN) = 00000000 (HEX) = 0 (DEC)
M15 - 00000000 00000000 00000000 00101000 (BIN) = 00000028 (HEX) = 40 (DEC)
The constant K will use the function floor(abs(sin(i + 1)) × 232) with i from 0 to 63. Therefore we will have 64
constant (K1 - K64) (Note: the sin is in rad)

K1 – D76AA478 (HEX) = 3614090360 (DEC) K11 – FFFF5BB1 (HEX) = 4294925233 (DEC)


K2 – E8C7B756 (HEX) = 3905402710 (DEC) K12 – 895CD7BE (HEX) = 2304563134 (DEC)
K3 – 242070DB (HEX) = 606105819 (DEC) K13 – 6B901122 (HEX) = 1804603682 (DEC)
K4 – C1BDCEEE (HEX) = 3250441966 (DEC) K14 – FD987193 (HEX) = 4254626195 (DEC)
K5 – F57C0FAF (HEX) = 4118548399 (DEC) K15 – A679438E (HEX) = 2792965006 (DEC)
K6 – 4787C62A (HEX) = 1200080426 (DEC) K16 – 49B40821 (HEX) = 1236535329 (DEC)
K7 – A8304613 (HEX) = 2821735955 (DEC) K17 – F61E2562 (HEX) = 4129170786 (DEC)
K8 – FD469501 (HEX) = 4249261313 (DEC) K18 – C040B340 (HEX) = 3225465664 (DEC)
K9 – 698098D8 (HEX) = 1770035416 (DEC) K19 – 265E5A51 (HEX) = 643717713 (DEC)
K10 – 8B44F7AF (HEX) = 2336552879 (DEC) K20 – E9B6C7AA (HEX) = 3921069994 (DEC)
K21 – D62F105D (HEX) = 3593408605 (DEC) K43 – D4EF3085 (HEX) =
K22 – 02441453 (HEX) = 38016083 (DEC) K44 – 04881D05 (HEX) =
K23 – D8A1E681 (HEX) = K45 – D9D4D039 (HEX) =
K24 – E7D3FBC8 (HEX) = K46 – E6DB99E5 (HEX) =
K25 – 21E1CDE6 (HEX) = K47 – 1FA27CF8 (HEX) =
K26 – C33707D6 (HEX) = K48 – C4AC5665 (HEX) =
K27 – F4D50D87 (HEX) = K49 – F4292244 (HEX) =
K28 – 455A14ED (HEX) = K50 – 432AFF97 (HEX) =
K29 – A9E3E905 (HEX) = K51 – AB9423A7 (HEX) =
K30 – FCEFA3F8 (HEX) = K52 – FC93A039 (HEX) =
K31 – 676F02D9 (HEX) = K53 – 655B59C3 (HEX) =
K32 – 8D2A4C8A (HEX) = K54 – 8F0CCC92 (HEX) =
K33 – FFFA3942 (HEX) = K55 – FFEFF47D (HEX) =
K34 – 8771F681 (HEX) = K56 – 85845DD1 (HEX) =
K35 – 699D6122 (HEX) = K57 – 6FA87E4F (HEX) =
K36 – FDE5380C (HEX) = K58 – FE2CE6E0 (HEX) =
K37– A4BEEA44 (HEX) = K59 – A3014314 (HEX) =
K38 – 4BDECFA9 (HEX) = K60 – 4E0811A1 (HEX) =
K39 – F6BB4B60 (HEX) = K61 – F7537E82 (HEX) =
K40 – BEBFBC70 (HEX) = K62 – BD3AF235 (HEX) =
K41 – 289B7EC6 (HEX) = K63 – 2AD7D2BB (HEX) =
K42 – EAA127FA (HEX) = K64 – EB86D391 (HEX) =
Step 6: F, G, H, I functions:
The full algorithms consist of 4 rounds, each round has 16 operations using the same function.

Round 1: F(B, C, D) = (B ∧ C) ∨ (¬B ∧ D)

Round 2: G(B, C, D) = (B ∧ D) ∨ (C ∧ ¬D)

Round 3: H(B, C, D) =B ⊕ C ⊕ D

Round 4: I(B, C, D) = C ⊕ (B ∨ ¬D)

Denote: ∧: AND; ∨: OR; ¬: NOT; ⊕: XOR

Round 1 Operation 1:

1. Compute F(B, C, D) = (B ∧ C) ∨ (¬B ∧ D)


F(B, C, D) = F(89abcdef, fedcba98, 76543210) = (89abcdef ∧ fedcba98) ∨ (¬89abcdef ∧ 76543210)

(89abcdef ∧ fedcba98) = (10001001101010111100110111101111 ∧ 11111110110111001011101010011000) =


10001000100010001000100010001000

(¬89abcdef ∧ 76543210) = (¬10001001101010111100110111101111 ∧


01110110010101000011001000010000) = (01110110010101000011001000010000 ∧
01110110010101000011001000010000) = 01110110010101000011001000010000

F(B, C, D) = 10001000100010001000100010001000 V 01110110010101000011001000010000

F(B, C, D) = 11111110110111001011101010011000 (BIN) = fedcba98 (HEX) = 4275878552 (DEC)

2. Compute modular addition (A + F(B, C, D)) mod 232 (4294967296)

(A + F(B, C, D)) = (19088743 + 4275878552) = 4294967295

4294967295 mod 4294967296 = 4294967295 (DEC)

(A + F(B, C, D)) mod 232 = ffffffff (HEX) = 4294967295 (DEC)

3. Compute modular addition (M0 + (A + F(B, C, D)) mod 232) mod 232

(M0 + (A + F(B, C, D)) mod 232) = (1629513327 + 4294967295) = 5924480622

5924480622 mod 4294967296 = 1629513326 (DEC)

(M0 + (A + F(B, C, D)) mod 232) mod 232 = 6120666e (HEX) = 1629513326 (DEC)

4. Compute (K1 + ((M0 + (A + F(B, C, D)) mod 232) mod 232)) mod 232

(K1 + ((M0 + (A + F(B, C, D)) mod 232) mod 232)) = (3614090360 + 1629513326) = 5243603686

5243603686 mod 4294967296 = 948636390 (DEC)

(K1 + ((M0 + (A + F(B, C, D)) mod 232) mod 232)) mod 232 = 388B0AE6 (HEX) = 948636390 (DEC)

5. Left bit-shit (Si)

Base on the operation is being taken, the previous result from step 4 will be converted to binary then shifted 7
spaces to the left

Result from step 4: 388B0AE6 (HEX) = 111000100010110000101011100110 (BIN)

Shifted 7 spaces: 000101100001010111001101110001 (BIN) = 5857371 (HEX) = 92631921 (DEC)

6. Compute (Result of step 5 + B) mod 232

(92631921 + 2309737967) = 2402369888

2402369888 mod 4294967296 = 2402369888 (DEC)

(Result of step 5 + B) mod 232 = 2402369888 (DEC) = 8F314160 (HEX) = 10001111001100010100000101100000


(BIN)
7. Rearrange A, B, C, D

A = D = 76543210 (HEX)

B = Result of step 6 = 8F314160 (HEX)

C = B = 89abcdef (HEX)

D = C = fedcba98 (HEX)

Then A, B, C, D will be used again in operation 2.

After 4 rounds, we then have different A, B, C, D than at the start.

We then compute the hash by

A = (Init-A + 4-round A) mod 232

B = (Init-B + 4-round B) mod 232

C = (Init-C + 4-round C) mod 232

D = (Init-D + 4-round D) mod 232

The final hash is ABCD

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy