Encode Secrets with the Caesar Cipher

Encode Secrets with the Caesar Cipher

History of the Caesar Cipher

The earliest and most famous cipher in history is the Caesar Cipher. It is named after Julius Caesar who supposedly used the cipher to pass messages between his generals.

It is the first known type of substitution cipher – (a substitution cipher is any cipher that involves replacing letters from the original message with a new letter).

Encoding with the Caesar Cipher

To encode a message with the Caesar Cipher, you first need 2 things: a secret message to encode and a key!

Your message can be anything as long as it is made up of the letters A to Z. For example: ‘I have a secret for you’, ‘Girls Code Too’ or simply ‘Hello’.

Your key can be any number between 1 and 25. Why these numbers? This is because we will shifting the alphabet to create our encoded message. For example if we shift our alphabet by 1, A will become B, B = C, C = D etc. If we shift our alphabet by 25, A will become Z, B = A, C = B etc. If we shift our alphabet by 26 spaces… it”ll end up right back at the beginning A = A (this will make a very bad encryption!!!).

I’ll take you through it. For this first example my message is ‘Hello’ and my key will be 3. First I will construct my new alphabet by shift it along by 3 so A becomes D and so on. Then for each letter in my message I will map it to my new alphabet. See below:

Using key 3 my message ‘hello’ becomes ‘khoor’.


Let’s try another one. I will keep the same message ‘hello’ but this time my key will be 13. 13 is a special number to the Caesar cipher (and not just because its considered an unlucky number). I will show you why when it comes to decrypting our new messages.

This time I will shift my alphabet by 13 spaces so A = N, B = O etc.

Using the key 13, ‘hello‘ has become ‘uryyb‘.

Try some yourself with a longer message and a key of your own.

Decoding with the Caesar Cipher

Now we know how to encrypt using the Caesar cipher we need to learn how to decrypt. To decrypt a message we will need to know both the encrypted message and the key in which is was encrypted. Let’s take our earlier example where I encrypted a message with a key of 3 which gave me the encrypted message ‘khoor’. This time instead of shifting our alphabet forward by 3, we need to move it backwards by 3. This time A will become X, B = Y and so forth.

Using our new shift alphabet, we can decrypt ‘khoor’ to our original message ‘hello’. There is another way to shift our alphabet which you may find easier. Shift our alphabet back 3 is exactly the same as shifting our alphabet forward by 23 spaces. This is because there are 26 letters in our alphabet and we have already learned that by shifting the alphabet 26 spaces we end up in the exact same spot (which makes for a useless cipher as ‘hello’ will encrypt to ‘hello’). By combining this fact with our decryption key -3 we get 26 – 3 = 23.

Give this a try with some of the messages you decrypted in the previous step.

Now let’s decrypt our second example, the one with key 13 which became ‘uryyb’. We can do this either by shifting back by 13 or shifting forward by 26 – 13.

Remember when I said that 13 was a special number to the Caeser cipher?

Take a close look at the difference between our 'shifted' alphabets for all our examples so far.

Done?

You may have noticed that the ‘shifted’ alphabet for the example where the key was 3 are different but for the key 13 the decryption alphabets are the exact same! We can explain this by comparing our decryption techniques. We could have either shifted back by 13 or shifted forward by 13 (26 – 13 = 13) landing us in the exact same spot. Cool right?

Because the encryption and decryption for key 13 is exactly the same, it’s has become a cipher all by itself called ROT-13 (which stands for ‘rotation by 13’.

Additional Work

Want to try some more Caeser ciphers? Try one of our additional tasks below:

1. Practice decryption

Decrypt the following using the key 7: Doha kpk aol ihuhuh zhf av aol kvn?
Decrypt the following using ROT-13: Abguvat. Onananf pna’g gnyx!

2. Send messages to friends

Agree a key with a friend and send each other messages. This could be either by letter or text.

3. Try out another cipher

Want to try another type of substitution cipher? Try our tutorial (coming soon) for the more advanced Vigenere Cipher.

ROT-13: unir sha!

Leave a Reply

Your email address will not be published. Required fields are marked *