All paths

Cryptography for builders

Secure the things you build, in Python on a Raspberry Pi: hashes, HMAC, how ciphers work and break, why homemade crypto fails, keys and secrets, and signed commands against replay, ending in a door lock that only opens for a signed, fresh command.

Raspberry Pi 4 Model BFree7 lessons6 h4 chapters2,385 XPCoding · Advanced+250 XP

0 of 7 done

What you will build

3 projects, built step by step

7 lessons in 4 chapters, about 6 hours on a simulated Raspberry Pi 4 Model B. Free, in your browser, every step checked by the simulator.

Chapter 1 project

HMAC signatures

A hash anyone can compute proves nothing about who sent a message. HMAC mixes in a secret key: build it from SHA-256 exactly as RFC 2104 says, check it against the RFC 4231 test vector and Python's hmac module, and light green for a genuine command and red for a forgery.

Open it in the simulator
Chapter 2 project

Why not roll your own

Attack homemade security the way real attackers do: recover a repeating XOR key from one known word, flip SHUT to OPEN in a properly encrypted message that has no MAC, read a PIN out of how long a comparison takes, then close every hole with encrypt-then-MAC and a constant-time compare.

Open it in the simulator
Chapter 3 project

Signed messages

Design a command format the way a protocol designer does: command, counter and HMAC tag in one line, a verifier that rejects tampering, a replay attack that a valid tag cannot stop, a counter that does, and where public-key signatures fit.

Open it in the simulator
The map

Chapter by chapter

Each lesson opens when the one before it is done, and each chapter ends in a project.

Chapter 1

Trust

Fingerprints for data, and tags only a key holder can make.

  1. Open250 XP

    Hashes

    A hash is a fingerprint for data: SHA-256 on the Pi, the avalanche effect that flips half the bits for one changed letter, a fixed size for any input, a firmware download checked against its published hash, and why a homemade hash falls over.

    0 of 5 steps

  2. ProjectLocked454 XP

    HMAC signatures

    A hash anyone can compute proves nothing about who sent a message. HMAC mixes in a secret key: build it from SHA-256 exactly as RFC 2104 says, check it against the RFC 4231 test vector and Python's hmac module, and light green for a genuine command and red for a forgery.

    0 of 5 steps

4 questions, graded as you go.
Chapter 2

Secrecy

How ciphers work, and the many ways homemade ones fail.

  1. Locked250 XP

    Symmetric ciphers

    Encryption with a shared key, from the bottom up and for understanding only: a Caesar cipher broken in 26 tries, the one-time pad that cannot be broken, a toy stream cipher built from SHA-256, and the nonce reuse mistake that hands an attacker your plaintext.

    0 of 5 steps

  2. ProjectLocked500 XP

    Why not roll your own

    Attack homemade security the way real attackers do: recover a repeating XOR key from one known word, flip SHUT to OPEN in a properly encrypted message that has no MAC, read a PIN out of how long a comparison takes, then close every hole with encrypt-then-MAC and a constant-time compare.

    0 of 5 steps

4 questions, graded as you go.
Chapter 3

In practice

Keys that cannot be guessed, and commands that cannot be replayed.

  1. Locked250 XP

    Keys and secrets

    The algorithm is public; the key is everything. See a key from a seeded random generator fall to an attacker in seconds, make keys from a secure random source, stretch a passphrase into a key with PBKDF2 and a salt, measure what iterations cost an attacker, and keep keys out of your code.

    0 of 5 steps

  2. ProjectLocked454 XP

    Signed messages

    Design a command format the way a protocol designer does: command, counter and HMAC tag in one line, a verifier that rejects tampering, a replay attack that a valid tag cannot stop, a counter that does, and where public-key signatures fit.

    0 of 5 steps

4 questions, graded as you go.
Chapter 4

Project

A door that only opens for a signed, fresh command.

  1. Locked227 XP

    Project: a signed door command

    A real lock on the Pi: a servo bolt that opens for "unlock" typed on the Serial Monitor, then only for commands signed by the phone, then only for fresh ones, with the replay counter saved to a file so a power cut cannot reopen the hole.

    0 of 5 steps

3 questions, graded as you go.
Syllabus

Every lesson in the course

All 7 lessons, in order, each with what it covers. Any of them opens in the editor right away.

Chapter 1

Trust

  1. HashesA hash is a fingerprint for data: SHA-256 on the Pi, the avalanche effect that flips half the bits for one changed letter, a fixed size for any input, a firmware download checked against its published hash, and why a homemade hash falls over.
  2. HMAC signaturesA hash anyone can compute proves nothing about who sent a message. HMAC mixes in a secret key: build it from SHA-256 exactly as RFC 2104 says, check it against the RFC 4231 test vector and Python's hmac module, and light green for a genuine command and red for a forgery.
Chapter 2

Secrecy

  1. Symmetric ciphersEncryption with a shared key, from the bottom up and for understanding only: a Caesar cipher broken in 26 tries, the one-time pad that cannot be broken, a toy stream cipher built from SHA-256, and the nonce reuse mistake that hands an attacker your plaintext.
  2. Why not roll your ownAttack homemade security the way real attackers do: recover a repeating XOR key from one known word, flip SHUT to OPEN in a properly encrypted message that has no MAC, read a PIN out of how long a comparison takes, then close every hole with encrypt-then-MAC and a constant-time compare.
Chapter 3

In practice

  1. Keys and secretsThe algorithm is public; the key is everything. See a key from a seeded random generator fall to an attacker in seconds, make keys from a secure random source, stretch a passphrase into a key with PBKDF2 and a salt, measure what iterations cost an attacker, and keep keys out of your code.
  2. Signed messagesDesign a command format the way a protocol designer does: command, counter and HMAC tag in one line, a verifier that rejects tampering, a replay attack that a valid tag cannot stop, a counter that does, and where public-key signatures fit.
Chapter 4

Project

  1. Project: a signed door commandA real lock on the Pi: a servo bolt that opens for "unlock" typed on the Serial Monitor, then only for commands signed by the phone, then only for fresh ones, with the replay counter saved to a file so a power cut cannot reopen the hole.
Kits

Build it on your bench too

Every lesson runs in the simulator with nothing to buy. When you want the real thing, these kits have the parts.

Have a kit already?

Find your kit

Pick the starter kit you own and run every lesson in its manual with the same parts on the same pins.

See every kit
Questions

About Cryptography for builders

Is Cryptography for builders free?

Yes. All 7 lessons of Cryptography for builders are free and run in your browser, with nothing to install and no parts to buy before you start.

Do I need a real Raspberry Pi 4 Model B?

No. Every lesson runs on a simulated Raspberry Pi 4 Model B with its parts on the canvas, and the simulator checks each step as you go. When you want to build it for real, the same wiring and code work on a real board.

How long does Cryptography for builders take?

About 6 hours: 7 lessons in 4 chapters, each one a few short steps. Your progress is kept, so you can stop after any lesson and pick up where you left off.

What will I build?

Each chapter ends in a project that puts it together: HMAC signatures, Why not roll your own and Signed messages.

Where do I start?

With "Hashes", and each lesson builds on the one before it. New to circuits? Electronics basics is the course that starts from zero.