Can two messages share a hash? Collisions and the birthday puzzle

A collision needs two different inputs with the same digest. When any pair will do, each new input adds several chances to match.

The examples below compare matching a fixed date with finding any shared birthday.

A pair can share a date without hitting the target

With January 1 as the target, two people born on July 1 are a pair match and leave the target unhit. One person born on January 1 hits the target even if no two people share a birthday.

In Lesson 4.2, the target digest was fixed. A collision is two different inputs with the same digest. In the birthday model, the people are the inputs and the dates are the outputs. Looking for a collision means any pair of people can match.

More people make more pairs

When the fourth person arrives, they make one new pair with each of the three people already there. Adding the new pairs from each person gives 1 + 2 + … + 22 = 253 pairs for 23 people. By contrast, each person has just one chance to hit the fixed date. A round can contain more than one matching pair, so multiplying the pair count by the chance of one match would count some rounds more than once.

With independent, equally likely draws over 365 days, about half of 23-person rounds have a shared birthday, while about 6% hit a chosen date. Results vary from round to round. The model leaves out leap days and assumes all dates are equally likely.

Why a collision must exist

Imagine five distinct messages whose toy hash can land in just four bins. Once all five go into bins, some bin must hold at least two messages. The same counting idea applies to any fixed-size hash with more allowed inputs than outputs. A strong hash makes collisions impractical to find even though they exist. See NIST’s overview of collision resistance and the Secure Hash Standard.

Check your understanding

Five people are already in a room. How many new pairs does a sixth person create, and why?

Show the answer

Five. The new person forms one pair with each person already there. None of the old pairs needs to be counted again.