Substitution cipher

## Background

While the umbrella term 'substitution cipher' is extremely broad, the type of cipher used in the book series is a monoalphabetic cipher. This means that each letter of plaintext is replaced with only one other ciphertext. This is the opposite of a polyalphabetic cipher, which uses multiple different ciphers to encode a single piece of plaintext. For example, theVigenère cipher uses multiple Caesar shifts in order to code a message.

The substitution cipher used in the books is very similar to the letter-to-number cipher, as they both replace a letter in the alphabet with a number. However, they differ in the sense that the letter-to-number cipher has a fixed substitution of a=1, b=2, z=26, etc; meanwhile, the book's substitution cipher can be coded in 26 different ways (for each letter of the alphabet).

A substitution cipher looks like a string of numbers, headed by a key.

## Theory

In theory, the substitution cipher is quite simple. The cipher requires the user to choose a substitution key to show how the cipher is enciphered and deciphered. The key consists of a letter, followed by the number by which it stands for in the code. For example, in the books Christopher and Master Benedict use the key M8, to show that M=8. Using the key M=8, by the order of numbers and the alphabet the cipher can continue as N=9, O=10, P=11, etc.

The recipient of the message will see a string of numbers, with each number standing for a letter.

## How to encipher it

First, we must choose a key. For the sake of simplicity, we'll have A=03, but A can equal anything from 1-26. Note that A=01 is the letter-to-number cipher and is easy to break. Also, A=03 can be written as B=04, C=05, as the letter increases at the same rate as the number.

We should write out the cipher alphabet, using A=03 also known as A03.

To create a cipher alphabet, write the alphabet out. Then, put the number on our key and write it directly below the key's letter. Continue the number until we reach '26', at which point we loop back to '01' until we finish the key. Note that you should write all numbers as two-digits, adding a '0' in front if necessary.

Then, we choose our message. 'John Parrett is a plague doctor.'

To encipher the message, we must use the key.

The first letter is 'j', and we can see it corresponds to the '12' on the key. Therefore, the first two-digit of the code is a '12'.

The second letter is 'o', and that corresponds to the '17' on the key. The second two-digit is a '17'. So, the code so far is '1217'.

The third letter is a 'h' which corresponds to '10'. Continue in this way until you get your full code.

'12171016180317170722112103181403092307061722221720'

To write the full message, add the key in front so anyone can decipher it.

```
A03 12171016180317170722112103181403092307061722221720

```

## How to decipher it

Here's an example of a message you want to decipher:

```
M08 2403130414151011032613220925151008221326011304260925140304110210220714

```

Since it's a pretty long message, you may want to add '/' between each two-digit (each two-digit represents a letter).

```
M08 24/03/13/04/14/15/10/11/03/26/13/22/09/25/15/10/08/22/13/26/01/13/04/26/09/25/14/

```

```
03/04/11/02/10/22/07/14

```

First, we can see the key- 'M08'. Unless we know the M08 cipher alphabet by heart, we should create one. (Keep in mind the M08 alphabet is the same as the N09, O10, P11 etc.)

The first two-digit we want to decipher is '24'. If we look at the alphabet cipher, we can see that it corresponds to the letter 'c'. The first letter of the plaintext is 'c'.

The second two-digit is a '03', which corresponds to the 'h' on the cipher. The second letter of plaintext is 'h'.

The next two-digit is a '13', which is a 'r' on the alphabet.

The code so far is 'chr'.

Finish turning all the numbers into letters. The final message is:

```
christopherandtomarefriendshipgoals

```

Since there are no spaces, use common sense to figure out what the coder is trying to say.

```
Christopher and Tom are friendship goals

```