# Can the sender use 12 again?

Welcome to the weather station workshop. A weather station measures conditions outside. Today it needs new software. The computer sending it uses a secret shared with the station, called a **key**, to hide the update and let the station check for changes.

For each update the sender also needs a number it has never used with that key. Repeating the pair can expose information about the hidden contents. You will repair the sender's record so it remembers used pairs after a restart.

The sender already used number 12 with the key it calls `north`. That name always identifies the same secret. The sender restarts. Two requests ask for 12 again, one with `north` and one with a new key, `south`, that has never sent an update. Should both wait? Write down which you would let through.

The method that seals the update is called **AES-GCM**. The public number that must be fresh for that key is its **nonce**. The file that records used pairs is the sender's **journal**.

```sh
python3 workshop.py queue
```

Run this from the course directory. The sender prints each number in base 16, where the last digit `c` means twelve. Mark all four requests “allow” or “hold” before you run the starter.

```sh
python3 workshop.py nonce
```

The unfinished sender holds all four. Find one request it got right by accident and one it should have allowed. Save your predictions beside that output.

## Read the pair in the update

A **byte** is a small unit of data. Open the course folder’s [index.html page](../index.html) to see each byte in your browser. Below the 3D demonstration, open the **Update case** menu and choose **Queued delivery B**. Its keys are named `fleet-a` and `fleet-b`. Start counting at byte zero. Byte 2 says which key to use. Bytes 10 through 21 hold the nonce.

![The twelve nonce bytes stay the same. Byte 2 changes from 01 for fleet-a to 02 for fleet-b.](../figures/envelope-fields.svg)

```python
key_slot = frame[2]
nonce = frame[10:22]
```

In each green box, two digits stand for one byte. Start with `77` at byte 10. The final `01` on the second line is byte 21.

Here `frame` holds all the bytes of one update. The slice stops one byte before 22. Select byte 21 on that page, then move right once. Which of those bytes belongs in the journal?

## Make a restart keep its history

In `boundaries.py`, the supplied `insert_new` saves a row in a database file. The first row pairs the key ID `north` with the twelve bytes for 12. The sender must keep that ID with the same secret even if its display name changes. If that pair is already on disk, the database skips it. If the pair is new, the database saves it before returning.

Finish `reserve` so its caller learns whether a new row was saved. Try before opening the [optional repair hint](../hints/nonce.md). Run the nonce check again. It closes the database after each row and opens the same file for the next.

The operator changes the display name from Weather Station to Harbor Station. The secret bytes and the saved ID `north` stay the same. Can Harbor Station use 12 with that key? Give the operator the journal entry that should settle that question. Record any help next to your repair.
