Blog Post
An Animated Tutorial of the MD5 Hash Function
We've created an animated explainer that shows how the MD5 hash function works step-by-step. You can see visually what happens at each step - no need to visualize source code in your head.
If you are familiar with bitwise operations, skip to 5:52.
As a summary:
- The MD5 pads the input until the length is a multiple of 512 bits
- For each 512 bit segment, it divides the input into 32-bit words (16 segments)
- The MD5 begins with a hardcoded 128-bit state which is mutated based on the input values. The state is divided into 4 32-bit words.
- The MD5 iterates through the 16 segments 4 times each for a total of 64 iterations. On each iteration, it shuffles 3 out of four of state words, but one of the words
B'is the result ofcombine(A, B, C, D, input[currentSegment]). - The combine function computes
B + rotate(F(B, C, A) + A + input[currentSegment] + K[i], r[i]).Kandrare hardcoded constants. - The function
Fis shown below:
