The one time pad is a very secure way of encoding messages – so secure in fact that it is unbreakable as long as the agents using it don’t make any mistakes. It was a very popular method of sending coded messages during the Second World War – and persisted well into the Cold War, when secret agents on the ground in a foreign country could encode their reports without fear that they would be broken by the enemy.

The picture above is from a one time pad code sheet which was used in the Second World War. What would happen is that the secret agent would be issued with a code book with lots of pages such as the page shown above. The person who was to receive the coded message would have an identical copy of this book kept securely in the home country. Now, the secret agent would infiltrate a foreign country and start to gather data. To encode it he would choose a page from the codebook, encode his message using the method will look at in a minute, and then the receiver would once he knew which page of the codebook had been used, would be able to decipher very quickly.

The one time pad is uncrackable as long as the codebook uses truly randomly generated numbers (not easy!) and as long as each page from the codebook is only used once – and is never discovered by the enemy. Sometimes this code was cracked because agents became lazy and reused the same pages, other times because the agent was captured and their codebook discovered. Nevertheless, in the age before digital communications it was a very secure method of encoding data.

How does the one time pad work?

It’s all based on Modulo arithmetic (mod 26). This sounds complicated, but basically we just work out the remainder when we divide by 26. For example 4 is still 4 mod 26, because 4 divided by 26 is 0 remainder 4. 30 is also 4 mod 26 because 30 divided by 26 is 1 remainder 4. For negatives we just keep adding 26 until we get a positive number. eg. -10 = 16 mod 26.

Now, say I want to encode the message ” Attack”. I assign each letter in the alphabet a value between 0 and 25 (A = 0, B = 1 etc).

So Attack = 0 19 0 2 10

Next I use my one time pad. Let’s use the one pictured at the top of the page. The first 5 random numbers are 54048, so I add these in turn working in mod 26 if required.

0 + 5 = 5

19 + 4 = 23

0 + 0 = 0

2 + 4 = 6

10 + 8 = 18

Now I convert these new number back into the alphabet using A = 0, B = 1 etc as before. This gives my code word as:

FXAGS

I can then send this back home using my chosen method (e.g. in a letter perhaps hidden as the first word of every sentence etc). The person receiving the code simply has to work in reverse using the same code pad. He converts FXAGS to numbers:

5 23 0 6 18

and he notes the numbers in his code pad are 54048 so he takes away to reveal the message:

5 – 5 = 0

23 – 4 = 19

0 – 0 = 0

6 – 4 = 2

18 – 8 = 10

This reveals the hidden message, Attack!

The beauty of this code is that it can even be done without a code pad – indeed deep cover secret agents were often too scared of being caught with a code book that they used ordinary books. This works in the same way, as long as both parties have agreed in advance on what copy book to use. Say I choose to use John Le Carre’s spy classic The Honourable Schoolboy, page 1 paragraph 1. This can sit innocuously on my bookshelf and yet I can create an equivalent to a code pad by taking each word in turn to make a number. In this case the first word is Afterwards – which would give me the code pad numbers 0 5 19 4 17 22 0 17 3 18. I could then use this to encode in the same manner as above.