Birthday probability for hash outputs 2026-10-13
How soon should a hash collision appear? Specify the probability distribution of the outputs first. Evaluate distinct keys and assume their hash values are independent random variables, each with the uniform distribution on a finite set of possible outputs. The randomness may come from an idealized randomly chosen hash function; a fixed hash function and a fixed list of keys have a definite outcome. Sampling the same key twice creates a repeated hash value without creating a hash collision, so distinctness of the queried keys matters.
This is the existing birthday problem, with hash values in place of birthdays. Let be the probability of at least one equal pair. The exact formula isThe empty product is , so . Given previous distinct hash values, the next value avoids them with conditional probability . Multiply these conditional chances and subtract from . Equivalently, for , exactly of the equally likely ordered outcomes have no repeated value. This derivation also explains why independence of all outputs, rather than merely uniform individual values, is required.[ref]
https://cacr.uwaterloo.ca/hac/about/chap2.pdf. Menezes, van Oorschot and Vanstone, Handbook of Applied Cryptography, section 2.1.5, Fact 2.27(i), birthday probability
For , the exact hash collision probabilities are , , and . Thus only distinct queries already exceed a one-half chance of some pair matching. The striking feature is the number of opportunities: queries supply pairs. By linearity of expectation, the expected value of the number of equal pairs is . This expectation counts pairs, not the probability of at least one pair; three equal outputs contribute three pairs in one outcome. The union bound gives .
Using the natural logarithm expansion in the exact product givesFor , the omitted correction in the logarithm of the no-collision probability is . Thus the approximation is controlled when is small; in particular it becomes accurate at the birthday scale proportional to as increases. The inequality also shows that the displayed approximation is a lower bound for when . Setting its exponent to gives the approximate half-probability sample size for large .
For comparison, under the same independent uniform model the probability of hitting one previously fixed digest in queries isEach query supplies one chance to hit , instead of a growing number of possible pairs. For , , and the first integer with is . In a toy model with possible -bit digests, the any-pair transition therefore has scale queries, while the fixed-target transition has scale . This explains the birthday-search distinction between collision resistance and preimage resistance.[ref]
https://cacr.uwaterloo.ca/hac/about/chap9.pdf. Menezes, van Oorschot and Vanstone, Handbook of Applied Cryptography, Fact 9.33 and section 9.7.1, generic collision versus preimage searches
The assumptions are essential. Uniform marginals alone do not give the product formula: if all equal one shared uniform random variable, every distinct pair collides with probability . A universal hash family bounds each pair's hash collision probability, but that condition alone does not supply joint independence of every output. Nor does a fixed output length establish collision resistance or preimage resistance: the toy has , making deliberate hash collisions immediate. The curves describe the specified model and do not establish the security of a concrete cryptographic hash function.
Birthday problem Created 2026-10-13 Updated 2026-10-14
The birthday problem asks for the probability that at least two members of a group share a birthday. Use the explicit model of independent random variables taking labels with a uniform distribution on a finite set. Let and be integers. For calendar examples below, stipulate equally likely labels and omit leap days. For , the probability of at least one matching pair isAt , the empty product is one and . At , a repeat is certain by the pigeonhole principle. Count the complement to obtain the formula: the first label has choices, then a distinct second label has , and so forth, out of equally likely label sequences.[ref]
For the stipulated calendar, and . Only 23 people suffice to put the probability above one half. There are possible pairs, each with matching probability . The many comparison opportunities explain why a small group can contain a repeat.
The distinction also matters for hash collisions. If independently generated outputs of a hash function are uniformly distributed over possible labels, the same counting formula governs repeats. The birthday square-root scale explains why looking for any repeated output requires far fewer labels than trying to match one predetermined output. The uniform-independent model is an assumption about those outputs; the birthday problem does not itself establish that a particular implementation meets it.
For an unknown nonzero period, a collision reveals the period . Birthday problem sampling finds one using queries with bounded error. A matching lower bound follows by choosing the period and output labels randomly: without a collision, queries rule out at most candidate periods. For , almost all periods remain consistent with the transcript. The exponential separation is in query complexity, compared with Simon's algorithm's linear quantum query count.
Past exam of the mathematics course of the University of Cambridge 2004 iii Paper 53 2 5 Solution 2026-10-14
Each independent run uses one oracle call and gives a uniformly sampled equation . Collect linearly independent equations and use Gaussian elimination over . Their solution space has dimension one and consists of , so the promised nonzero solution identifies uniquely.
To quantify the expected query count for Simon sampling, write . If the existing equations have rank , their span contains of the possible samples. A fresh equation raises the rank with probability . The mean waiting time is the corresponding geometric distribution mean, givingThe last sum is less than : its first term is and its remaining terms are bounded by . Hence the expected number of quantum queries is . For a fixed high-confidence budget, use samples. Failure to span means that a nonzero linear functional on the -dimensional sampling space annihilates every sample. Each such functional has probability , so the union bound gives failure probability at most . Thus queries suffice for failure probability at most . For , the nonzero string is known already and no samples are needed.
Classically, a collision between distinct queried arguments immediately yields . Random queries produce this collision after order calls, by the birthday problem. Conversely, choose the nonzero period uniformly and label the fibres randomly. Before a collision, queries can exclude at most periods, their pairwise argument differences; every remaining period has the same no-collision transcript distribution. When , those exclusions occupy a vanishing fraction of the candidate periods, and neither collision discovery nor guessing a remaining period has a constant success probability. More quantitatively, conditioned on no previous collision, the next query tests at most of at least remaining periods; summing these conditional probabilities proves the same square-root lower bound. Therefore the optimal bounded-error classical query count is , exponentially larger in than the quantum count.
Past exam of the mathematics course of the University of Cambridge 2009 ia Paper 2 4F Solution Created 2026-09-24 Updated 2026-10-14
The events are pairwise disjoint and their union is . Finite additivity and the definition of conditional probability therefore give the law of total probability:For the birthday problem, let mean that all birthdays differ. For , sequential conditioning on previous distinct birthdays and independence of random variables giveHere each factor uses the stated bound . For , , soFor a match is certain by the pigeonhole principle. The threshold from the exponential bound is , so suffices.

