HomeCryptographyHash Functions — Avalanche & Collisions

#️⃣ Hash Functions — Avalanche & Collisions

Explore what makes a cryptographic hash strong: flip one input bit and watch ~half the output bits change (the avalanche effect), and see the birthday bound make collisions likelier than intuition.

Cryptography3DModerate60 FPS
sha-hashing ↗ Open standalone

About this simulation

This simulation demonstrates two core properties of a cryptographic hash using a small, fast FNV-1a hash (a non-cryptographic mixing algorithm named after Fowler, Noll and Vo) finished with an xorshift step, producing a 32-bit digest (a fixed-length fingerprint of the input). In Avalanche mode, your text is hashed live and drawn as a bit grid; flipping one input bit recomputes the hash and highlights every output bit that changed — the avalanche effect. In Birthday mode, random samples are hashed into a b-bit space of B = 2b buckets and checked for collisions, plotting the observed collision rate against the theoretical birthday bound 1 − e−n²/2B.

🔬 What it shows

A 32-bit hash rendered as a 4×8 grid of 0/1 cells for Avalanche mode, with any bit that flipped between input A and input B picked out in red; and, for Birthday mode, a live plot of collision probability versus number of samples drawn, comparing an amber theoretical curve to a green observed data point.

🎮 How to use it

Switch between the Avalanche and Birthday views with the two mode buttons. In Avalanche, type any text into the input box and press "Flip one bit" to mutate one random character by a single bit, or "Reset" to return to "hello world". In Birthday, drag the "Hash bits b" slider (4–16) to resize the bucket space and "Samples drawn" (1–120) to change how many values are hashed per trial, then press "Run 1 trial" or "Run 200 trials" to accumulate an observed collision rate.

💡 Did you know?

The birthday bound is why real hash functions need roughly double the bit-length of their intended security level: SHA-256 produces a 256-bit digest, but because collisions become likely after only about √B attempts, its actual collision resistance is closer to 128 bits — the same square-root effect this simulation's slider lets you see directly.

Frequently asked questions

What algorithm computes the hash in this simulation?

It uses FNV-1a, a fast non-cryptographic hash: it starts from a fixed offset basis, then for each input character XORs the running value with the character code and multiplies by a fixed prime (0x01000193). The result is then passed through an xorshift finishing step (three XOR-shift operations) to spread bits more thoroughly, producing a 32-bit output. It is not SHA-256, but it still exhibits the same avalanche and collision behaviour that real cryptographic hashes are designed around.

Why does flipping one bit change so many output bits?

Because of how FNV-1a's multiply-and-XOR chain mixes each input byte through every later step, and because the xorshift finisher spreads any single-bit difference across the whole 32-bit word, changing one input bit cascades into roughly half of the 32 output bits flipping, on average. That property is the avalanche effect, and it is exactly what the red highlighted cells in Avalanche mode are showing you bit by bit.

What do the "Hash bits" and "Samples drawn" sliders control in Birthday mode?

"Hash bits b" sets the width of the hash space: with b bits there are B = 2b possible output buckets (from 16 buckets at b=4 up to 65,536 at b=16). "Samples drawn" sets how many random values are hashed into that space in a single trial before the simulation checks whether any two landed in the same bucket. Both sliders reset the running trial statistics so the observed rate always reflects the current settings.

Why doesn't the observed collision rate exactly match the predicted curve?

The amber curve plots the closed-form birthday bound 1 − e−n²/2B, an approximation that is exact only in the limit of many trials. The green point is a real empirical average over however many trials you have actually run (shown as "Trials run" in the stats panel); with only a handful of trials, random chance means the observed fraction can sit noticeably above or below the theoretical line. Press "Run 200 trials" repeatedly to shrink that gap.

Is this simulation's hash function secure enough for real cryptography?

No — FNV-1a plus an xorshift finisher is fast and shows the right statistical behaviour for teaching, but it lacks the cryptographic design (fixed-point rounds, key schedules, proven diffusion bounds) that make functions like SHA-256 resistant to deliberate attack. Real systems must use a vetted cryptographic hash; this simulation only borrows the same two properties — avalanche and the birthday bound — to make them visible and interactive.

⚙ Under the hood

Explore what makes a cryptographic hash strong: flip one input bit and watch ~half the output bits change (the avalanche effect), and see the birthday bound make collisions likelier than intuition.

hash functionavalanche effectcollisiondiffusionCanvas 2D

3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)