Vol. 01 · Story 11 · Domain 1

GARY'S SECRETRECIPES.

Cryptography

Gary's Coffee Shop · 6 min read

Gary's coffee recipes are his competitive advantage. Five problems. Five tools. Symmetric encryption, asymmetric encryption, hashing, digital signatures, salting, steganography, and forward secrecy.

Reading Progress
00 / 22
Story 11 · Domain 1 · Cryptography

Gary's Secret Recipes.

Gary's coffee recipes are his competitive advantage. He needs to protect them. Five different problems. Five different tools. The most content-dense story in the guide.

Gary has a second shop across town. He needs to send recipes there. He puts each recipe in a lockbox with a padlock and sends it by courier. Both shops have a copy of the same key. One key. Both sides. Fast.

That's symmetric encryption — one key, both sides, fast, bulk data. But there's a problem: how did Gary get the key to the second shop in the first place? If he sent it by courier, the courier could copy it. That's the key distribution problem.

Gary's lockboxes come in models. DES — the old rusty one, 56-bit keyhole. Anyone with a crowbar can pop it. Broken. 3DES — three rusty lockboxes chained together. Better, but slow. Legacy. AES — the titanium lockbox. Three keyhole sizes: 128, 192, or 256-bit. Nobody's ever cracked it. Current standard. AES works in blocks — it chops the recipe into fixed-size chunks. That's a block cipher. The alternative encrypts one character at a time: a stream cipher.

A food blogger wants Gary's recipe. Gary's never met her. He can't hand her a key in person. So Gary does something clever. He makes two keys — a gold key he keeps in his pocket (private key), and a silver key he hangs on the shop door for anyone to grab (public key).

The blogger grabs the silver key, locks her message in a box, and sends it. Only Gary's gold key can open it. That's asymmetric encryption. Public key encrypts, private key decrypts. It's slow — so in practice, Gary uses the asymmetric box to send a brand-new symmetric key to the blogger. Then they switch to fast lockboxes for the actual recipes. That's how TLS works — asymmetric for the handshake, symmetric for the data.

Asymmetric algorithms: RSA — the classic. Big keys (2048/4096-bit). Heavy iron padlock. ECC — smaller keys, same strength. Lightweight titanium. Modern favourite. Diffie-Hellman — not for locking boxes. For agreeing on a key without ever sending it. Gary and the blogger each shout a number, do some maths, and end up with the same secret. Nobody listening can figure it out. That's key exchange.

Gary prints a recipe and runs it through a magic shredder. The shredder spits out a unique fingerprint — a short fixed-length code. Change ONE ingredient and the fingerprint is completely different. You can't reconstruct the recipe from the fingerprint.

That's hashing — one-way fingerprint, no key, fixed output. Shredders: MD5 — 128-bit, has known collisions. Broken, never use. SHA-1 — 160-bit, also has collisions. Deprecated. SHA-256 — 256-bit, no known collisions. Current standard.

Gary wants to send a recipe and prove two things: it hasn't been tampered with, and he definitely wrote it. He hashes the recipe to get a fingerprint, then locks the fingerprint with his gold key (private key). He sends the recipe plus the locked fingerprint. The blogger unlocks it with Gary's silver key (public key), hashes the recipe herself, and compares. Match = untampered AND Gary signed it. That's a digital signature — hash plus encrypt with private key. Proves integrity and non-repudiation.

Gary keeps staff passwords as hashes. Problem: two staff with the same password produce the same hash. A thief with a rainbow table could match them instantly. Fix: Gary adds a salt — a unique random value — to each password before hashing. Now identical passwords produce different hashes. Extra fix: key stretching — run the hash thousands of times. Deliberately slow. Brute force takes thousands of operations per guess. Algorithms: PBKDF2, bcrypt, scrypt.

Gary's paranoid mate hides a recipe inside a photo of a cat. The photo looks perfectly normal. Nobody knows there's data hidden in it. That's steganography — hiding the existence of the message, not just the content. Encryption hides the content. Steganography hides the existence.

Gary uses a new temporary key for every recipe delivery. Even if someone steals Gary's gold key next year, they can't decrypt last year's deliveries — those used different keys that no longer exist. That's forward secrecy — ephemeral (temporary) keys per session. DHE or ECDHE provides forward secrecy.

TLS uses asymmetric for the handshake and symmetric for the data. One is for trust — the other is for speed. Gary never sends 10,000 recipes through the iron padlock. He just uses it to hand over the key to the titanium one. — Story 11 · Cryptography
// THE LOCK-IN

A digital signature is: hash the data, then encrypt that hash with your private key. The recipient decrypts with your public key and compares their own hash of the message. Match = intact. Only you could have produced the signature. That's integrity plus non-repudiation in one operation.

Check Yourself · Question 11

Which hashing algorithm has known collisions and should never be used for security purposes?

Terminology · Story 11

The Crypto Toolkit.

// Term · 01 / 06
Symmetric vs Asymmetric
Tap to reveal
// Definition
Symmetric — one key, fast, bulk data (AES). Key distribution problem. Asymmetric — key pair, slow, used for key exchange + signatures (RSA, ECC).
Domain 01
// Term · 02 / 06
Hashing
Tap to reveal
// Definition
One-way fingerprint. Fixed output, no key. SHA-256 current standard. MD5/SHA-1 broken. Cannot reverse — cannot recover data from the hash.
Domain 01
// Term · 03 / 06
Digital Signature
Tap to reveal
// Definition
Hash the data + encrypt the hash with your private key. Provides integrity (hash) and non-repudiation (only your private key). Verified with your public key.
Domain 01
// Term · 04 / 06
Salting
Tap to reveal
// Definition
Adding a unique random value to each password before hashing. Defeats rainbow tables by ensuring identical passwords produce different hashes.
Domain 01
// Term · 05 / 06
Steganography
Tap to reveal
// Definition
Hiding data inside other data (images, audio, video). Hides the existence of the message. Encryption hides content. Steganography hides the fact there's a message at all.
Domain 01
// Term · 06 / 06
Forward Secrecy
Tap to reveal
// Definition
Ephemeral keys per session — past sessions remain safe even if the long-term private key is later compromised. DHE or ECDHE provides forward secrecy.
Domain 01