Live lesson · progress saved to your account

Cryptography Essentials

Symmetric and public-key encryption, Diffie-Hellman, hashing and password storage, signatures, certificates and the TLS 1.3 handshake. Crack a leaked MD5 dump, verify certificate chains, use GPG, then audit a breached start-up.

intermediate100 minwalkthrough

Anyone can read this lesson. To submit answers and earn XP, create a free account.

TASK 01Mission briefing: the TiffinTrail breach

INCIDENT · TT-2026-117 TiffinTrail (a fictional tiffin-delivery start-up in Pune) woke up to a forum post: "TiffinTrail user DB, 1,20,000 rows, passwords included". The developers had stored every password as a plain MD5 hash. Within two days, most of them were cracked and posted next to customers' emails.

TiffinTrail has hired you to find out what went wrong and fix it. The problem isn't that they didn't use cryptography. They used it wrongly: the wrong tool for passwords, old TLS settings, a key hidden in their app, and a card column "encrypted" with Base64.

OWASP lists Cryptographic Failures among the top web risks for exactly this reason. In this room you'll learn the handful of ideas that all of security rests on (HTTPS, VPNs, Wi-Fi, disk encryption, software updates, UPI and banking apps) and, more importantly, which one to use when.

You'll get hands-on with real maths at toy sizes: you'll run RSA and Diffie-Hellman with your own numbers, crack the leaked MD5 hashes, verify certificate chains and use GPG in a terminal.

Answer the questions

+10 XP

+10 XP

TASK 02Why cryptography? From Caesar to AES

Cryptography gives us four guarantees:

GoalQuestion it answersTool
ConfidentialityCan anyone else read it?Encryption
IntegrityWas it changed?Hashes, MACs
AuthenticityWho sent it?Signatures, MACs, certificates
Non-repudiationCan the sender deny it later?Digital signatures

Some vocabulary: the readable message is plaintext, the scrambled version is ciphertext, the method is the cipher (or algorithm), and the secret that controls it is the key.

Julius Caesar shifted every letter by 3. Try it, then switch to the Crack tab and break an intercepted message:

Caesar cipher: the oldest trick Shift the alphabet
ABCDEFGHIJKLMNOPQRSTUVWXYZ
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
DEFGHIJKLMNOPQRSTUVWXYZABC

plaintextMEET AT THE GATE

ciphertextPHHW DW WKH JDWH

Caesar's cipher fails because the key space is tiny (only 25 useful shifts). Modern ciphers like AES have 2¹²⁸ or 2²⁵⁶ possible keys.

Kerckhoffs's principle

A system must stay secure even if the attacker knows everything except the key. The algorithms (AES, RSA, SHA-256) are public and studied by thousands of experts. Never trust "secret" home-made algorithms. Only the key is secret.

Encoding is not encryption. Base64, hex and URL-encoding just change the format and have no key: anyone can reverse them. Never use them to "protect" data.

Answer the questions

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

TASK 03Symmetric encryption

In symmetric encryption the same key encrypts and decrypts. It's fast and used for almost all bulk data: HTTPS traffic after the handshake, Wi-Fi (WPA2/WPA3), disk encryption (BitLocker, FileVault, LUKS), encrypted backups and messaging apps.

Change the receiver's key by even one character and watch what comes out:

One shared key locks and unlocks Change either key

Sender

Ciphertext on the wire

ac234a09abc2869ed4f0d901face2c1901138daaff517d34dd803223586e

Receiver

Pay vendor Rs 48,000 on Friday

Same key: message recovered

Toy stream cipher for the demo. Real systems use AES-256-GCM or ChaCha20-Poly1305: same idea (one secret key), much stronger maths, plus a tag that detects tampering.

The standard is AES (Advanced Encryption Standard), chosen in 2001. AES is a block cipher: it works on 128-bit blocks with a 128, 192 or 256-bit key. ChaCha20 is a fast alternative used on phones.

Modes: how blocks are chained

A block cipher on its own only handles 16 bytes. The mode decides how a whole file is processed, and the wrong mode leaks information:

Why the mode matters: ECB leaks patterns Watch it encrypt

Plain image

each pixel = one block

AES-ECB

same block → same ciphertext

AES-GCM

each block mixed with a counter/nonce

Both were encrypted with the same strong key. ECB encrypts each block on its own, so identical blocks stay identical and the logo shows through. Use an authenticated mode like GCM, and never reuse its nonce with the same key.

  • ECB: each block alone. Identical blocks → identical ciphertext. Never use it.
  • CBC: chains blocks together; still common, but easy to get wrong.
  • GCM: counter mode plus an authentication tag that detects tampering (an AEAD mode). The modern default, along with ChaCha20-Poly1305. Never reuse a nonce with the same key.

The big problem: sharing the key

Both sides need the same secret key before they can talk securely. How do you get it to someone in another city over an internet full of eavesdroppers? And how many keys do you need?

The key-sharing problem Add people

Symmetric: one secret key per pair

n(n−1)/2 = 15 keys

Public-key: one key pair per person

2n = 12 keys (6 public, 6 private)

And every symmetric key must reach the other person secretly first. With 1,000 employees that is 4,99,500 secret keys.

That's the problem public-key cryptography solves.

Answer the questions

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

TASK 04Public-key (asymmetric) encryption

In asymmetric cryptography each person has a key pair:

  • a public key, shared with the world (like an open padlock you hand out), and
  • a private key, never shared (the only key that opens those padlocks).

To send Bob a secret, you encrypt with Bob's public key. Only Bob's private key can decrypt it. No secret ever had to be exchanged in advance.

RSA (1977) is the classic algorithm. Build a key pair yourself with tiny primes. The default p = 61, q = 53 is the textbook example:

RSA with tiny numbers Pick two primes
p =q =
  1. 1. n = p × q = 3233 (public)
  2. 2. φ(n) = (p−1)(q−1) = 3120 (secret)
  3. 3. public exponent e = 17
  4. 4. private d = e⁻¹ mod φ(n) = 2753
  5. public key (e, n) = (17, 3233)
  6. private key (d, n) = (2753, 3233)
c = me mod n = 6517 mod 3233 = 2790
m = cd mod n = 27902753 mod 3233 = 65

Anyone can encrypt with the public key; only the private key decrypts. An attacker who could factor n back into p and q could compute d. For n = 3233 that takes a millisecond. Real RSA uses a 2048-bit n (617 digits), which nobody can factor.

RSA's security rests on one fact: multiplying two huge primes is easy, but factoring the result back into them is practically impossible. Real RSA keys are 2048 bits or more.

Elliptic-curve cryptography (ECC) gives the same security with much smaller keys: a 256-bit ECC key (like Ed25519 or P-256) is about as strong as 3072-bit RSA, which is why phones and TLS prefer it.

The catch

Public-key operations are slow, roughly 1,000× slower than AES. So real systems are hybrid: public-key crypto is used to agree or send a random symmetric session key, and AES encrypts the actual data. HTTPS, GPG, SSH and Signal all work this way.

Quantum note: a large quantum computer could break RSA and ECC. New post-quantum algorithms (ML-KEM, ML-DSA) are already being rolled into browsers and TLS.

Answer the questions

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

TASK 05Diffie-Hellman: agreeing a key in public

In 1976 Diffie and Hellman found a way for two people to create a shared secret over a public channel, even if someone records every message. The classic way to picture it is mixing paint. Step through it, then switch to the real numbers:

Diffie-Hellman: agree a key in public Step 1/5

Alice

Public / Eve

public yellow

Bob

Alice and Bob openly agree on a starting colour. Eve hears it too.

The maths uses a public prime p and base g. Each side picks a secret number, sends g^secret mod p, and raises what they receive to their own secret. Both land on the same value. An eavesdropper sees p, g, A and B but would have to solve the discrete logarithm problem to get a secret.

Modern TLS uses the elliptic-curve version, ECDHE (usually X25519). The E at the end means ephemeral: a fresh key pair for every connection, thrown away afterwards. That gives forward secrecy: even if the server's long-term private key is stolen next year, recorded traffic from today stays unreadable.

Diffie-Hellman agrees a key but doesn't prove who you agreed it with. A man-in-the-middle could run DH separately with each side. That's why TLS adds certificates and signatures, which come later in this room.

Answer the questions

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

TASK 06Hashing

A hash function turns any input (a password, a file, a whole disk image) into a short, fixed-length digest. Unlike encryption, there's no key and no way back. Type in the boxes and watch:

Hash avalanche Change one character

4cf52c6d1cb9c8c8a1136181f559b7662b17bd110335de6cdbe5b553354cfc18

4e33b594b092c093ab2f17b300ef5c4081b008ca206c05b48fe4fee45578fcb7

Bits that flipped125/256 (49%)

  • • Fixed length: 256 bits = 64 hex chars, whatever the input size
  • • Deterministic: same input, same hash, every time
  • • One-way: no key, no "decrypt", only guess-and-compare
  • • Avalanche: a tiny change flips about half the bits

A good cryptographic hash is:

  1. Deterministic: same input → same output.
  2. One-way (pre-image resistant): you can't work backwards from the hash.
  3. Collision-resistant: you can't find two inputs with the same hash.
  4. Avalanche: change one bit and about half the output bits flip.
AlgorithmOutputStatus
MD5128 bitsBroken: collisions in seconds (Flame malware forged a Microsoft certificate with one in 2012)
SHA-1160 bitsBroken: Google's SHAttered made two different PDFs with the same hash (2017)
SHA-256 / SHA-3256 bitsSecure, widely used

Uses: checking downloads (compare the published SHA-256), Git commit IDs, digital signatures (you sign the hash), blockchains, and file fingerprints in forensics and malware lookups (VirusTotal).

A HMAC combines a hash with a secret key, proving both integrity and that the sender knows the key. APIs and JWTs use it.

Answer the questions

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

TASK 07Storing passwords (and the lab: crack the dump)

A site should never be able to see your password: it stores a hash and compares hashes at login. But how it hashes makes all the difference. Click through the five options:

How should a database store passwords? Pick a scheme
userpassword column
priyacd84d683cc5612c69efe115c80d0b7dc
rahulcd84d683cc5612c69efe115c80d0b7dc
meera4cf97e7b194676b7d108259d93338065
samfb848b422a8e85482df7383a653b95d8

GPU guesses

~160 billion/s

Rainbow table

yes, instant

Same pw visible

yes

Fast and unsalted: a GPU tries billions per second and rainbow tables reverse common passwords instantly. This is what TiffinTrail used.

Three ideas make password storage safe:

  • Salt: a random value, unique per user, stored next to the hash and mixed into it. Two users with the same password get different hashes, and precomputed rainbow tables (giant lookup tables of hash → password) become useless.
  • Slow on purpose: SHA-256 is designed to be fast, which helps attackers. Argon2id, bcrypt and scrypt take a tunable amount of time (and for Argon2/scrypt, memory) per guess.
  • Pepper (optional): a secret added to every password, kept outside the database (e.g. in a key vault).

OWASP's recommendation: Argon2id first, bcrypt (cost 10+) if Argon2 isn't available.

Lab · Crack the leaked hashes

Here's a slice of the TiffinTrail dump. First try the rainbow-table lookup, then the wordlist with rules:

Lab · Crack the leaked TiffinTrail hashes 0/7 MD5 cracked

The forum dump: 7 accounts still stored as unsalted MD5, 2 already migrated to Argon2id. MD5 can't be reversed, so attackers look hashes up or hash guesses and compare.

userstored hashcracked
priya.s76d788a2600b609bb0a08443e03df95b…
ananya.ke10adc3949ba59abbe56e057f20f883e…
arjun.pd8578edf8458ce06fbc5bb76a58c5ca4…
dev.ops54c56b27ae98ff739935c14eb127ee4e…
rahul.m0e9fa1bc22da67c20ccf6e510afe8f93…
supportd3ab3d5e39ba3874885e2d94f9cb9141…
ceo.neha183d9a624d332e5afbb885d25c9b01c9…
kavya.r$argon2id$v=19$m=65536,t=3,p=4$……
sam.t$argon2id$v=19$m=65536,t=3,p=4$……

Answer the questions

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

TASK 08Digital signatures and certificates (PKI)

Run public-key crypto backwards and you get a digital signature:

  1. Hash the document.
  2. Sign the hash with your private key.
  3. Anyone with your public key can verify it.

Sign a software release, then tamper with it:

Sign with private, verify with public Tamper with the file

Developer (has the private key)

Release v2.4.1 of the TiffinTrail app. Refund limit: Rs 5,000.

sha256 → 6e73d3ebe3513b4fefb8…

sign: hd mod n → signature 1246

User downloads (has the public key)

sha256(file) mod n = 177

signaturee mod n = 177

Good signature

A signature proves integrity (not changed), authenticity (who signed) and non-repudiation (they can't deny it). It does not hide the file: signing is not encrypting.

Signatures protect app updates, Windows drivers, Git commits, e-mail (S/MIME, PGP), Aadhaar e-Sign and every HTTPS connection.

Certificates: whose key is this?

A public key alone doesn't tell you who owns it. A certificate (X.509) binds a name like tiffintrail.in to a public key, and is signed by a Certificate Authority (CA) that checked you control the domain.

Browsers and operating systems ship a trust store of around 150 root CAs. Roots sign intermediate CAs, which sign the website's leaf certificate. This is the chain of trust, and the whole system is called PKI (public key infrastructure). In India, the CCA (Controller of Certifying Authorities) licenses CAs for digital signature certificates.

A browser accepts a certificate only if all of these hold:

  • the hostname is listed in the certificate's SAN (Subject Alternative Name),
  • today's date is inside the validity period,
  • each signature in the chain verifies, and
  • the chain ends at a root in the trust store.

Revoked certificates are checked with CRLs or OCSP. Free CAs like Let's Encrypt issue 90-day certificates (and shorter soon), automated with the ACME protocol.

Lab · Verify the certificate chains

Six TiffinTrail sites. Inspect each chain and give your verdict:

Lab · Verify the certificate chains 0/6 correct · today: 1 Dec 2026

https://tiffintrail.in/

leaftiffintrail.inSANtiffintrail.in, www.tiffintrail.inissuerR11 (Let's Encrypt)valid2026-10-20 → 2027-01-18

↑ signed by · signature ok

intermediateR11 (Let's Encrypt)issuerISRG Root X1valid2024-03-13 → 2027-03-12

↑ signed by · signature ok

rootISRG Root X1issuerISRG Root X1valid2015-06-04 → 2035-06-04trust storepresent in browser/OS store

The browser checks: hostname in SAN · dates · each signature up the chain · a trusted root at the top.

Answer the questions

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

TASK 09TLS 1.3: how HTTPS puts it all together

TLS (Transport Layer Security) is the "S" in HTTPS. It uses everything from this room in one handshake: ECDHE for the key, a certificate and signature for identity, a hash for integrity and AES-GCM for the data. Watch it, then compare with TLS 1.2:

TLS 1.3: one round trip Click a message
Browsertiffintrail.in

browser → server

ClientHello + key_share

Supported versions and cipher suites, a random value, the site name (SNI) and the client's Diffie-Hellman public value (key_share).

encrypted plaintext

TLS 1.3 (2018) is faster (one round trip, or zero with resumption) and safer: it removed RSA key exchange, CBC ciphers, SHA-1 and other old options, so every connection has forward secrecy.

What the padlock proves, and what it doesn't

✅ The connection is encrypted, and you're talking to whoever controls that domain name. ❌ It does not mean the site is honest. Most phishing sites have valid HTTPS certificates. Check the domain itself.

Common TLS mistakes

  • Still allowing TLS 1.0/1.1 or SSL (deprecated; allow only 1.2 and 1.3).
  • Expired certificates (automate renewal).
  • No HSTS header, so a first visit over plain HTTP can be hijacked (SSL stripping).
  • Apps that turn off certificate validation "just for testing" and ship it.

Test a site with openssl s_client -connect site:443, testssl.sh, or SSL Labs.

Answer the questions

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP

TASK 10Lab: encrypt and sign with GPG

GPG (GNU Privacy Guard, an OpenPGP tool) is used to encrypt files and e-mail, and to sign software releases (Linux packages, Git tags). It's hybrid: it encrypts a random AES key with the recipient's public key.

You're Asha, TiffinTrail's new security engineer. The CTO, Bob, has put his public key in bob.asc. Complete the objectives on the right. Type help for the commands, and use ↑ for history.

Lab · Encrypt and sign with GPG 0/8 objectives
asha@ws: ~
TiffinTrail security workstation · user asha · type 'help'
asha@ws:~$
  1. Generate your key pair
  2. List your keys
  3. Import Bob's public key (bob.asc)
  4. Encrypt report.txt for Bob
  5. Sign report.txt
  6. Verify both release downloads
  7. Export your public key to a file
  8. Decrypt Bob's reply

Tips: you need your own key pair before you can sign or decrypt, and Bob's key before you can encrypt for him or check his signatures. To send your public key, export it to a file with gpg --export -a asha > asha.asc.

Answer the questions

+20 XP

+10 XP

+10 XP

+10 XP

TASK 11Final mission: audit TiffinTrail

Time to report back. Judge each item in TiffinTrail's systems as Fine or Needs fix:

Mission · Audit TiffinTrail's crypto 0/10 judged correctly

User passwords

password_hash = md5(password)

Nginx TLS versions

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

pay.tiffintrail.in certificate

notAfter = 2026-11-28

Mobile app source

const AES_KEY = "tiffin2023secret";

Card numbers in orders table

card = base64(card_number) // "encrypted"

HTTP response headers

(no Strict-Transport-Security header)

Nightly backups

AES-256-GCM, key in cloud KMS, rotated yearly

Password-reset tokens

crypto.randomBytes(32), single use, 15 min expiry

Session cookie

Set-Cookie: sid=…; Secure; HttpOnly; SameSite=Lax

Public API

TLS 1.3 · X25519 · TLS_AES_128_GCM_SHA256

Then prove you can choose the right primitive for any job:

Pick the right tool 0/7 correct

Encrypt every laptop's disk

Store customer passwords

Prove an app update really came from the developer

Check a 4 GB download wasn't corrupted

Agree a session key with a website you've never visited

Encrypt the nightly database backup

Send a confidential file to a journalist using their published key

Your three fixes that would have prevented this breach:

  1. Argon2id with a unique salt for every password (and force a reset for everyone in the dump).
  2. Keys out of code: secrets in a vault/KMS, never in the app bundle or Git.
  3. Modern TLS everywhere: TLS 1.2/1.3 only, HSTS, and automated certificate renewal.

And remember: don't invent your own crypto. Use well-reviewed libraries (libsodium, your language's standard crypto) with their safe defaults.

Complete the mission for the Key Master badge and the room's XP. Welcome to Level 2!

Answer the questions

+10 XP

+10 XP

+10 XP

+10 XP

+10 XP