CNS-MD5-The MD5 Algorithm (With Examples) - Comparitech
CNS-MD5-The MD5 Algorithm (With Examples) - Comparitech
CNS-MD5-The MD5 Algorithm (With Examples) - Comparitech
Search
yBlog
Use Reviews
» Information Security » The MD5 algorithm
yWe
OS/Device
are funded Byby OS/Device
our readers and may receive a commission when you buy using links on our site.
y CountryGuides
The MD5 algorithm (with examples)
uides Compare providers
eviews
In this article, we discuss the underlying processes of the MD5
algorithm and how the math behind the MD5 hash function works.
WHAT'S IN
THIS ARTICLE?
This time, we’ll be zeroing in on what actually happens The MD5 Algorithm
23db6982caef9e9152f1a5b2589e6ca3
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 2/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 4/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 6/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
The input M
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 7/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
M0 – 54686579
M1 – 20617265
M2 – 20646574
M3 – 65726D69
M4 – 6E697374
M5 – 69638000
M6 – 00000000
M7 – 00000000
M8 – 00000000
M9 – 00000000
M10 – 00000000
M11 – 00000000
M12 – 00000000
M13 – 00000000
M14 – 00000000
M15 – 000000B0
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 8/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
M1, M6, M11, M0, M5, M10, M15, M4, M9, M14,
M3, M8, M13, M2, M7, M12
M5, M8, M11, M14, M1, M4, M7, M10, M13, M0,
M3, M6, M9, M12, M15, M2
M0, M7, M14, M5, M12, M3, M10, M1, M8, M15,
M6, M13, M4, M11, M2, M9
A – 01234567
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 9/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
B – 89abcdef
C – fedcba98
D – 76543210
F(B, C, D) = (B∧C)∨(¬B∧D)
The operations
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 10/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
If you follow the arrow out of it into the next box, this
indicates that the output of F(B, C, D) is added to
the initialization vector A, with a special type of
addition. In the first operation, initialization vector A’s
value is 01234567, but it changes in subsequent
operations.
abs(sin(i+ 1))×232
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 11/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
K1 – D76AA478
K2 – E8C7B756
K3 – 242070DB
K4 – C1BDCEEE
K5 – F57COFA
K6 – 4787C62A
K7 – A8304613
K8 – FD469501
K9 – 698098D8
K10 – 8B44F7AF
K11 – FFFF5BB1
K12 – 895CD7BE
K13 – 6B901122
K14 – FD987193
K15 – A679438E
K16 – 49B40821
K17 – F61E2562
K18 – C040B340
K19 – 265E5A51
K20 – E9B6C7AA
K21 – D62F105D
K22 – 02441453
K23 – D8A1E681
K24 – E7D3FBC8
K25 – 21E1CDE6
K26 – C33707D6
K27 – F4D50D87
K28 – 455A14ED
K29 – A9E3E905
K30 – FCEFA3F8
K31 – 676F02D9
K32 – 8D2A4C8A
K33 – FFFA3942
K34 – 8771F681
K35 – 699D6122
K36 – FDE5380C
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 12/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
K37– A4BEEA44
K38 – 4BDECFA9
K39 – F6BB4B60
K40 – BEBFBC70
K41 – 289B7EC6
K42 – EAA127FA
K43 – D4EF3085
K44 – 04881D05
K45 – D9D4D039
K46 – E6DB99E5
K47 – 1FA27CF8
K48 – C4AC5665
K49 – F4292244
K50 – 432AFF97
K51 – AB9423A7
K52 – FC93A039
K53 – 655B59C3
K54 – 8F0CCC92
K55 – FFEFF47D
K56 – 85845DD1
K57 – 6FA87E4F
K58 – FE2CE6E0
K59 – A3014314
K60 – 4E0811A1
K61 – F7537E82
K62 – BD3AF235
K63 – 2AD7D2BB
K64 – EB86D391
Round one
S1, S5, S9, S13 – 7
S2, S6, S10, S14 – 12
S3, S7, S11, S15 – 17
S4, S8, S12, S16, – 22
Round two
S17, S21, S25, S29 – 5
S18, S22, S26, S30 – 9
S19, S23, S27, S31 – 14
S20, S24, S28, S32 – 20
Round three
S33, S37, S41, S45 – 4
S34, S38, S42, S46 – 11
S35, S39, S43, S47 – 16
S36, S40, S44, S48 – 13
Round four
S49, S53, S57, S61 – 6
S50, S54, S58, S62 – 10
S51, S55, S59, S63 – 15
S52, S56, S60, S64 – 21
After the shift has been made, the result of all of these
calculations is added to the value for initialization
vector B. Initially, it’s 89abcdef, but it changes in
subsequent operations.
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 14/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
Confused?
The F function
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 15/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
F(B, C, D) = (B∧C)∨(¬B∧D)
∧– AND
∨– OR
¬ – NOT
⊕ – XOR, which basically means either, but not
both.
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 16/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
88888888
76543210
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 17/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
fedcba98
Modular addition
(X + Y) mod Z
Where:
Enter:
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 19/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
ffffffff
ffffffff
(X + Y) mod Z
Where:
X – 54686579 (M0)
Therefore:
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 21/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
Enter:
154686578
54686578
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 22/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
d76aa478
(X + Y) mod Z
X – d76aa478
Z – 100000000 (232)
12bd309f0
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 23/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
2bd309f0
Left bit-shift
2bd309f0
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 24/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
e984f815
(X + Y) mod Z
This time:
Z – 100000000 (232)
17330C604
Now it’s time to copy and insert this value into “Number
a value” field. Type 100000000 into “Number b value”
and change the formula to mod (a,b). This should give
you an answer of:
7330C604
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 26/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
This means that the output of the last step will become
the initialization vector B for the next operation. It
replaces the original initialization vector B, which was
89abcdef. If you follow all of the other lines, we end up
with:
A – 01234567
B – 89abcdef
C – fedcba98
D – 76543210
F(B, C, D) = (B∧C)∨(¬B∧D)
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 27/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
F(B, C, D) = fedcba98
(X+Y) mod Z
Where:
X = 01234567
Y = fedcba98
Z = 100000000
ffffffff
54686578
2bd309f0
e984f815
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 28/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
7330c604
A – 76543210
B – 7330c684
C – 89abcdef
D – fedcba98
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 29/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
Subsequent operations
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 30/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
Round two
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 31/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
G (B, C, D) = (B∧D)∨(C∧¬D)
∧– AND
∨– OR
¬ – NOT
A – 799d1352
B – 2c34dfa2
C – de1673be
D – 4b976282
Therefore:
G (B, C, D) =
(2c34dfa2∧4b976282)∨(de1673be∧¬4b976282)
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 33/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
(2c34dfa2∧4b976282)
8144282
(de1673be∧¬4b976282)
1400113c
8144282 ∨ 1400113c
We need to:
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 34/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
1c1453be
Round three
H (B, C, D) = B⊕C⊕D
A – eb160cd0
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 35/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
B – d5071367
C – c058ade2
D – 63c603d7
7699bd52
Round four
I(B, C, D) = C⊕(B∨¬D)
This formula also has the XOR function for one or the
other, but not both. It’s basically saying “C OR, BUT
NOT BOTH (B OR NOT-D). Let’s make up some more
outputs from the end of the 48th round:
A – 60cdceb1
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 36/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
B – 7d502063
C – 8b3d715d
D – 1de3a739
Therefore:
I(B, C, D) = 8b3d715d⊕(7d502063∨¬1de3a739)
7f5c78e7
8b3d715d ⊕ 7f5c78e7
To finish it:
f46109ba
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 37/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
A – 60cdceb1
B – 7d502063
C – 8b3d715d
D – 1de3a739
First, we’ll zoom out again and take a look at the larger
MD5 algorithm:
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 38/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
OIV-A – 01234567
OIV-B – 89abcdef
OIV-C – fedcba98
OIV-D – 76543210
(X + Y) mod Z
In this case:
Therefore:
61f11418
Now it’s time to copy and insert this value into “Number
a value” field. Type 100000000 into “Number b value”
and change the formula to “mod (a,b).” This should
give you an answer of:
61f11418
This is the answer for the final value of A (in the case
of a single 512-bit block of input data).
(A + B) mod C
(B + OIV-B) mod C
(C + OIV-C) mod C
(D + OIV-D) mod C
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 41/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
Hash = ABCD
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 42/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
If the initial input was only two 512-bit blocks long, the
last parts of the MD5 hash algorithm would proceed in
essentially the same way as they did in the The final
step, after 64 operations section, finally outputting
the hash for the two 512-bit blocks of input data.
Comments
Leave a Reply
Comment
Name *
Leave Comment
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 44/45
3/9/24, 11:45 AM The MD5 algorithm (with examples) | Comparitech
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Home Blog Our Authors Privacy policy Cookies Policy Terms of use Disclosure
https://www.comparitech.com/blog/information-security/md5-algorithm-with-examples/ 45/45