One-Time Pad Examples

Learn about the effects of reusing keys in one-time pads and explore the one-time pad using a Latin square example.

Consequences of key reuse in a one-time pad

An important property of a one-time pad is that keys should be used only once. We now demonstrate why this is the case. To keep things really simple, we’ll use the Caesar cipher one-time pad to encrypt single-letter plaintexts.

Suppose two plaintext letters, P1P_1 and P2P_2, have been encrypted using the same one-time pad key KK (in other words, key KK has been used twice) to produce two ciphertext letters, C1C_1 and C2C_2. This means an attacker knows that both C1C_1 and C2C_2 have arisen by shifting P1P_1 and P2P_2 the same number of positions. Thus, the attacker learns that the number of letters between C1C_1 and C2C_2 is the same as the number of letters between P1P_1 and P2P_2. This doesn’t immediately tell the attacker what either P1P_1 or P2P_2 is, but it’s certainly information the attacker did not have before.

We can make this statement more precise by using the mathematical description of the Caesar cipher, which is the following:

C1=P1+Kmod26C_1 = P_1 + K \, mod \, 26

C2=P2+Kmod26C_2 = P_2 + K \, mod \, 26

Since an attacker can see C1 and C2, the attacker can subtract C1 from C2 to get the following:

C2C1=(P2+K)(P1+K)mod26C_2 - C_1 = (P_2 + K) - (P_1 + K) \, mod \, 26

=P2P1mod26= P_2 - P_1 \, mod \, 26

This can be seen in the code given below:

Get hands-on with 1200+ tech skills courses.