CS Unplugged activity
Caesar Cipher: hiding a message in plain sight
Why hide a message?
More than two thousand years ago, Julius Caesar needed to send orders to his generals without an enemy who intercepted the letter being able to read it. His trick was simple: shift every letter in the message the same number of places through the alphabet. Anyone who did not know the shift just saw nonsense.
That is a cipher: a rule for turning a readable message into an unreadable one and back again. The rule here is called a shift cipher, or a Caesar cipher after the man who is said to have used it. It still shows up today, just as one small piece of much bigger, much harder ciphers, and as a classic first puzzle for learning how codebreaking works at all.
How a shift works
Pick a number from 1 to 25. That number is the key. To encode a message, slide every letter that many places later in the alphabet, wrapping back around to A after Z.
Here is key 3, worked out one letter at a time:
| Plain | H | E | L | L | O |
|---|---|---|---|---|---|
| +3 | K | H | O | O | R |
HELLO becomes KHOOR. H is the 8th letter, and 3 letters after H is K. E is the 5th letter, 3 letters after is H, and so on. Spaces do not shift; they just stay spaces.
To decode, run the same slide backward: shift every letter of KHOOR back 3 places and you land on HELLO again.
Your shift table
You do not need anything special to use a key, just the alphabet written out twice: once in order, and once shifted. Fill in the second row for whatever key you are using right now by counting forward that many letters for every blank, wrapping from Z back to A.
| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | |
| Key __ |
Once that row is filled in, encoding and decoding are the same move: find a letter in one row and read off whatever is below or above it in the other row. You will fill this row in again every time you use a new key, so do it in pencil. (If you would rather turn a dial than rewrite the alphabet, there is a cut-out wheel that does the same job near the end of this page. It is entirely optional.)
Decode these
Here are five messages, all encoded with the same key.
Key: 7
Encode one of your own
On a separate scrap of paper, pick your own key from 1 to 25 and write a short message in capital letters, no punctuation. Use your shift table (or the wheel) to encode it letter by letter, checking each one as you go.
Copy just the finished, encoded message onto the line below, then swap papers with a partner.
Message to swap:
If you also tell your partner the key, they can decode it the same way you encoded it, just backward. For an extra challenge, do not tell them the key, and see the next part.
Crack it: no key given
This time, nobody tells you the key. All you get is the message below.
XFFU TFDDVEKJ VOGCRZE NYP EFK ALJK NYRK
That sounds harder, but think about what a key actually is: just a whole number from 1 to 25. There is no key 26, because shifting every letter by 26 places is the same as not shifting at all, and a key of 0 would not hide anything. That is only 25 possibilities in total. You can simply try every one of them until a real message falls out.
Use the grid below to keep track. For each key, shift the message back that many places and jot down just enough of the result to tell whether it is real words or nonsense. You can stop as soon as one works.
| 1 | 2 | 3 | 4 | 5 |
| 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 |
Learn more about the Caesar cipher.
Next step: try a Vigenère cipher, which uses a whole keyword instead of one shift.
OPTIONAL: the cipher wheel
Everything on this page also works with the shift table, so only build this if you would rather turn a dial than write out an alphabet. This is the one page in this whole activity where you need scissors.
- Cut out the big wheel (the solid outline) and the small wheel (the dashed outline).
- Stack the small wheel on top of the big wheel, both letter side up, with their center marks lined up.
- Push a brad through both center marks, or hold a pencil point steady there while you turn the small wheel. Either way, the small wheel needs to spin freely around that one point.
To encode with a key, turn the small wheel until its arrow (next to its “A”) points at that key’s number on the big wheel. Then for every letter of your message, find it on the big wheel and write down whatever letter lines up with it on the small wheel.
To decode, do the opposite: find each letter of the secret message on the small wheel, and write down whichever letter lines up with it on the big wheel.
For example, lining the arrow up with key 3 puts the small wheel’s “A” next to the big wheel’s “D”. That is the same key 3 shift from the shift table earlier in this activity, just turned into a dial instead of a row of letters.
Check your answers
Decode these (key 7).
Crack it. The key is 17. Shifting the message back that many places gives:
Good comments explain why not just what
If you found it with a different key than 17, check your alphabet count. Only one key turns that message into real words.
Version history
- Loading commit history…