One pair of bits at a time
In Lesson 3.1, you wrote a byte as eight bits. With XOR, you line up two rows of bits and apply the same rule to every column. A mask bit of 0 keeps the input because 0 XOR 0 is 0 and 1 XOR 0 is 1. A mask bit of 1 flips the input because 0 XOR 1 is 1 and 1 XOR 1 is 0.
| Position | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| Input | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 0 |
| Mask | 0 | 0 | 1 | 1 | 0 | 1 | 0 | 1 |
| Pass 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 1 |
| Pass 2 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 0 |
Why the same mask undoes the change
The first application changes 10110010 into 10000111. The second takes that result as its input. Where the mask is 0, the bit stays the same both times. The mask has a 1 at positions 3, 4, 6, and 8. Those bits flip once and then flip back, restoring 10110010.
The one-time pad will use a secret mask as the key. The next few lessons ask where the bits for that mask can come from.
Check your understanding
In the worked example, change mask position 2 from 0 to 1. Which bit of the first result changes compared with the table? What happens when you apply your new mask again?
Show the answer
Only position 2 changes in the first result. The input bit at position 2 is 0, and the new mask bit flips it to 1. Apply the same new mask again and that 1 flips back, restoring the original byte.