Virtual laboratory/Mathematics/Cryptography/Hash function — the avalanche effect

Hash function — the avalanche effect

A hash function turns arbitrary data into a short "fingerprint". Change one input character and watch the avalanche effect — the whole hash changes. This is an illustrative model (not a real SHA).

Hash function — the avalanche effect
Mathematics · Cryptography · Hash function — the avalanche effect
Input A
Which character we change in Bchar #4 “u”
Changing one character in a hash function’s input changes the result…
length A
11 chars
hash length
128 bit
changed bits
—
function
det. ✓
🎯 Challenge: hash properties
streak: 0

Check whether you understand how a hash function behaves — a short quiz on its properties.

What just happened?

We swapped one character in the input, and the hash changed in nearly half of its bits — with no resemblance to the previous one. This is how a good hash function behaves.

What is a hash function?

It is a mapping that transforms arbitrarily long input data into a hash of fixed length (here: 128 bits, i.e. 32 hex characters). Formally:

h:{0,1}∗→{0,1}nh:\{0,1\}^{*} \to \{0,1\}^{n}

Every input — “kot” or a whole sentence — gives a result of the same length nn. The function is deterministic: the same input always returns the same hash.

The avalanche effect

The key property of cryptographic hash functions: changing one bit of the input changes about half of the output bits, unpredictably:

x≠x′ ⇒ Pr⁡ ⁣[ bi(h(x))≠bi(h(x′)) ]≈12x \ne x' \ \Rightarrow\ \Pr\!\big[\,b_i(h(x)) \ne b_i(h(x'))\,\big] \approx \tfrac{1}{2}

That is why from the hash alone you cannot “reverse” it to the input, nor guess how a small change will affect the result.

What is it good for?

A hash is a digital “fingerprint” of data. Since every modification changes it, it is used for:

  • data integrity — you compare the hash of a downloaded file with the original; a difference = the file changed,
  • password storage — the database stores the hash, not the password,
  • digital signatures and blockchain — one signs the hash of a document, not the whole document.

Remember:

A hash function: any input → fixed-length output, deterministically, with an avalanche effect. A small change in the input = a large, unpredictable change in the hash.

Note: this is an illustrative model — we used our own simple mixing function (FNV-1a + finalizer) to show the principle. Real functions (e.g. SHA-256) are much stronger, but obey the same avalanche rule.

Illustrative model · NexTutor Virtual Laboratory

Enjoyed the experiment? Share it.

It's free — send it to friends from school.

Theory & formulas

What a hash function does

It turns data of arbitrary length into a short "fingerprint" (a hash) of fixed length. The same message always produces the same hash.

The avalanche effect

Changing a single input character changes about half of the output bits — the hashes of similar messages are completely different and unpredictable.

Desirable properties

  • hard to invert — the data cannot be recovered from the hash,
  • collision resistance — it is hard to find two different inputs with the same hash.

Hence their use in checking data integrity, storing passwords and digital signatures.

Frequently asked questions

›

How does changing one character affect the hash?

It changes it completely (the avalanche effect) — about half of the output bits change.

›

What are hash functions used for?

For checking data integrity, storing passwords and digital signatures.

Teaching? Embed this experiment on your site.

Free widget — paste it on your school site, blog or notes. It links to the full version.

Teaching a class or tutoring? Guide students in NexTutor →