## One Time Pad Cipher

The One Time Pad (OTP) cipher is a substitution cipher that is impossible to crack (if used correctly).

To encrypt a message using OTP you combine each letter of your plaintext with a letter from your "pad". The pad is simply a large amount of text, some people use books as their pad, some people generate random letters.

To combine the letters you have to:

- Find the position of letter from the plaintext is in the alphabet (counting from 0, i.e. A=0)
- Similarly find where the letter from the pad is in the alphabet
- Add the two numbers together
- If the result is greater than the length of your alphabet then wrap around to 0 and keep counting (i.e. use modulo arithmetic)
- Find which letter is at the position you've just calculated

For example, let's use an alphabet of:

ABCDEFGHIJKLMNOPQRSTUVWXYZ

And let's encrypt this message, using this pad:

HELLO

IGBQU

- The letter
`H`

(from the plaintext) is at position 7 in the alphabet - The letter
`I`

(from the pad) is at position 8 - Adding these positions together gives us
`7 + 8 = 15`

- Make sure our new position isn't bigger than the length of the alphabet:
`15 mod 27 == 15`

- The letter
`P`

is at position 15, this is the first letter of the ciphertext

Going through every letter of the plaintext and pad gives us:

PKMAH

### Calculator

Complicated right? The calculator below can help. If you type a message into the plaintext box and a random pad into the pad box it will encrypt your message. If you instead provide a pad and a ciphertext it will decrypt for you.