Cryptography for builders lesson plan
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.
Objectives and materials
By the end, students can
- Fingerprints for data, and tags only a key holder can make.
- How ciphers work, and the many ways homemade ones fail.
- Keys that cannot be guessed, and commands that cannot be replayed.
- A door that only opens for a signed, fresh command.
Materials for the whole unit
- Hobby servo
- Pushbutton
- Raspberry Pi 4 Model B
- Traffic light module
Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.
Trust
Fingerprints for data, and tags only a key holder can make.
| Lesson | Time | What students do |
|---|---|---|
| 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. | 50 min |
|
| 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. | 50 min |
|
Materials
- Pushbutton
- Raspberry Pi 4 Model B
- Traffic light module
Check for understanding
Each student finishes "HMAC signatures" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "What HMAC does and does not do".
Secrecy
How ciphers work, and the many ways homemade ones fail.
| Lesson | Time | What students do |
|---|---|---|
| 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. | 50 min |
|
| 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. | 50 min |
|
Materials
- Pushbutton
- Raspberry Pi 4 Model B
- Traffic light module
Check for understanding
Each student finishes "Why not roll your own" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Do it properly: encrypt, then MAC".
In practice
Keys that cannot be guessed, and commands that cannot be replayed.
| Lesson | Time | What students do |
|---|---|---|
| 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. | 50 min |
|
| 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. | 50 min |
|
Materials
- Pushbutton
- Raspberry Pi 4 Model B
- Traffic light module
Check for understanding
Each student finishes "Signed messages" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "MACs and real signatures".
Project
A door that only opens for a signed, fresh command.
| Lesson | Time | What students do |
|---|---|---|
| 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. | 50 min |
|
Materials
- Hobby servo
- Raspberry Pi 4 Model B
Check for understanding
Each student finishes "Project: a signed door command" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Review your threat model".
Teach this unit as a class
Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.
The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.