Source: https://mokxi.com/teachers/plans/cryptography-basics
Updated: 2026-11-19

Lesson plan

# 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.

4 chapters, 7 lessons, about 6 hours, on the Raspberry Pi 4 Model B. Every lesson runs in the browser, with nothing to install.

Start a class from this course

The unit

## 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.

Chapter 1. About 1 h 40 min

## Trust

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

Lesson | Time | What students do

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. | 50 min

- Run it: a fingerprint
- The avalanche
- Any size in, same size out
- Check a download
- Why not a homemade hash?

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. | 50 min

- Run it: a tag with a key
- Build HMAC from SHA-256
- Now use the library
- Green for genuine, red for forged
- What HMAC does and does not do

### 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".

Chapter 2. About 1 h 40 min

## Secrecy

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

Lesson | Time | What students do

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. | 50 min

- Run it: Caesar
- Break it
- The one-time pad
- A stream cipher from a short key
- Reuse a nonce, lose everything

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. | 50 min

- Run it: a homemade door code
- Known plaintext
- Encryption is not integrity
- A timing attack
- Do it properly: encrypt, then MAC

### 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".

Chapter 3. About 1 h 40 min

## In practice

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

Lesson | Time | What students do

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. | 50 min

- Run it: a predictable key
- A real random source
- A key from a passphrase
- Slow on purpose
- Keep keys out of the code

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. | 50 min

- Run it: a signed command
- Verify, and refuse tampering
- The replay attack
- A counter beats replay
- MACs and real signatures

### 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".

Chapter 4. About 50 min

## Project

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

Lesson | Time | What students do

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. | 50 min

- Run it: an open door
- Only signed commands
- Stop the replay
- Survive a power cut
- Review your threat model

### 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".

Your class

## 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.

Start a class from this course See the demo class

More units

## Other lesson plans

Electronics basics 20 lessons, about 10 h. Embedded on the Arduino Uno 16 lessons, about 12 h. Embedded on the ESP32-C3 13 lessons, about 11 h. Embedded on the Raspberry Pi Pico 7 lessons, about 6 h. Build your own fight stick 5 lessons, about 4 h. Embedded on the STM32F411 6 lessons, about 6 h. C++ on a board 13 lessons, about 10 h. Digital logic and memory 4 lessons, about 4 h. Interactive devices on the Uno 9 lessons, about 8 h. From gates to a computer 23 lessons, about 16 h. Build a claw machine 8 lessons, about 6 h. Every unit All the courses as ready-made units, on the teachers page.
