Cryptology Academy · Lesson

What Makes a Good Hash Function

Explore pre-image resistance, collision resistance, and avalanche effect.

Lesson 1 of 413 steps

What Makes a Good Hash Function is a free Cryptology Academy lesson on CoddyKit. This is lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cryptology Academy learning path, and your progress syncs across the web and the CoddyKit app. The Cryptology Academy course includes 4 lessons in total.

Welcome

A cryptographic hash function transforms any input into a fixed-length digest. In this lesson we study the properties that make a hash function cryptographically secure.

Deterministic Output

Hash(M) always produces the same output for the same input. SHA-256('hello') is always aabb... no matter where or when you compute it.

Fixed Output Length

SHA-256 always outputs 256 bits (32 bytes = 64 hex chars). SHA-512 always outputs 512 bits. The input can be 0 bytes or 10 GB — output size never changes.

Pre-image Resistance

Given hash h, it must be computationally infeasible to find any message M such that Hash(M) = h. One-way property: you cannot reverse a hash.

Second Pre-image Resistance

Given M1, it must be infeasible to find M2 ≠ M1 such that Hash(M1) = Hash(M2). Prevents an attacker from substituting a different message with the same hash.

Collision Resistance

It must be infeasible to find ANY two messages M1 ≠ M2 where Hash(M1) = Hash(M2). This is harder than second pre-image but weaker than it sounds — pigeonhole principle guarantees collisions exist.

Avalanche Effect

Flipping a single bit in the input should change ~50% of output bits. SHA-256('hello') vs SHA-256('hellp') differ in ~128 bits. This sensitivity prevents incremental search attacks.

Merkle-Damgård Construction

MD5, SHA-1, and SHA-2 use Merkle-Damgård: divide input into blocks, chain a compression function. The final chain value is the hash. This design is vulnerable to length-extension attacks.

Sponge Construction

SHA-3 (Keccak) uses a sponge construction: absorb input into a state, then squeeze output. Sponges resist length-extension attacks and are more versatile than Merkle-Damgård.

Birthday Bound

The birthday attack finds collisions in 2^(n/2) operations, not 2^n. SHA-256 has 256-bit output, so collision resistance is ~2^128. SHA-1 (160 bits) has ~2^80 — now broken in practice.

Hash vs MAC vs Signature

Hash: no key, provides integrity only. MAC (HMAC): keyed hash, provides integrity + authenticity. Digital signature: asymmetric key, provides integrity + authenticity + non-repudiation.

Quick Check

What property ensures it is infeasible to find any input that produces a given hash output?

Recap

You now understand the security properties of hash functions. Next we study MD5 — once the standard, now fully broken.
Free to start

Learn Cryptology Academy with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
67
Lessons
261

Frequently Asked Questions

Is the “What Makes a Good Hash Function” lesson free?

Yes — the full text of “What Makes a Good Hash Function” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cryptology Academy course, upgrade to CoddyKit PRO. The Cryptology Academy course includes 4 lessons in total.

What will I learn in “What Makes a Good Hash Function”?

Explore pre-image resistance, collision resistance, and avalanche effect. You practise Cryptology Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Cryptology Academy?

No prior experience is required. Cryptology Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 4.

How long does the “What Makes a Good Hash Function” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Cryptology Academy lesson?

Yes. Every Cryptology Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. What Makes a Good Hash Function
  2. MD5: History, Uses & Why It Is Broken
  3. SHA-1 & SHA-2 Family Explained
  4. Hash Applications: Checksums, HMAC & Git
← Back to Cryptology Academy