These codes are named after the
Ancient Roman Emperor Julius Caesar
who used them to keep his messages secret.

CODES Home Page

Caesar Codes

How to make and break codes using the Caesar Shift method.

The shift method was one of the earliest coding systems. It's a substitution code which means that each letter of your original is turned into a different letter in your coded message.

  • The original uncoded message is called plaintext and is written in small (lowercase) letters.
  • The coded message is called CODETEXT and is written in capital letters.
  • The person you send your message to is your agent

To start with, we're going to make a very simple Caesar code. After that we're going to see how to make it better and harder to crack!

Getting ready...

You and your agent both need to download and print out this sheet.

Carefully cut out the two CODETEXT strips. Stick the ABC of the shorter strip over the grey ABC of the longer strip, to make a very long strip with the alphabet shown twice.

You and your agent need to have agreed on a secret KEY LETTER.

You'll need extra paper and pencils.

How to write code

Start off by putting your long CODETEXT strip underneath the first plain text strip. If you put the letter A under the black letter a then all the other letters will be in line. If you wanted to code a message then a=A and b=B and c=C which isn't a code at all!

But now, here comes the clever bit...

Shift the CODETEXT strip along a few places until your chosen key letter is under the black letter a. Julius Caesar usually used the key letter D, so that's what we'll do here.

Now you can quickly code a message turning the small plain text letters into CAPITAL CODETEXT letters. "happy birthday granny" would become "KDSSB ELUWKGDB JUDQQB".

This sort of code used to be good enough for Julius Caesar until his enemies realised how it worked. There are only 25 possible code letters (not counting letter A), so there are only 25 different code patterns. If anybody wanted to decode a message they could just try each key letter in turn until the message made sense. This is worth doing - especially if it might get you out of danger!

How to make a better code

The secret is to mix up the letters on the plaintext strip. You and your agent can agree a secret key word. Here, we'll use the word "amazing". We'll make up a plaintext strip starting with the word "amazing" but miss out any repeated letters. This means the first letters on the plain text strip are "amzing". You then fill in the rest of the strip with all the letters you haven't used in order. We also need a key letter so we'll use H. We get this:

This makes the message much harder message to decode.

We could even use a key sentence if we wanted! Let's try "we love making codes" with key letter = M

Using a key word or sentence gives us 26! different code patterns.

The ! is a factorial sign and it means we need to work out 26 x 25 x 24 x 23 x ... all the way down to ... x 3 x 2 x 1.

This works out at
403,291,461,126,605,635,584,000,000 different possible code patterns!

Here our message "happy birthday granny" turns into "WMYYE UOABWSME QAPPE" but there's still a problem.

A codebreaker has to work out which plaintext letter each CODETEXT letter represents. A clever codebreaker will see the CODETEXT and spot double letter YYs and the double letter PPs. Some letters in the alphabet are much more likely to be doubles than others, so he could start by guessing what P or Y could be.

Also, in a long message, some letters are far more common than others. Letter "e" is the most common letter used in English. "t" and "a" are also very common. This helps him to guess a few more letters.

Once the codebreaker has guessed a few letters correctly, the rest quickly become obvious. Wouldn't it be good to disguise the most used letters and the double letters somehow? The answer is to use a "doubles" plaintext strip...

Here we've used key letter = Q, and you'll see there are two of a,e and t on the plaintext strip. There is also a number 2 at the end. Some of the letters that don't get used much share a CODETEXT letter, so for example, the letter G can represent p or q. This time "happy birthday granny" becomes "ZRGPO SAHJZUQO YHREPO" You'll see that both Q and R have been used as letter a. What's more, instead of double letters, we just out in the number 2 which is P in CODETEXT. When you decode this message and see EP, you know that E = n and P=2 which means it's a double letter n.

There are just a few ideas to make your secret messages as secure as possible, but of course the very best codes come if you invent your own plaintext strips!

If you'd like to see some other types of code look at our CODES Home Page.


Teacher Resources

The Murderous Maths Home Page