Please enable JavaScript to use CodeHS

Caesar and Vigenere Ciphers

By Jennifer Campbell
In this tutorial, you will learn about two very early encryption systems known as the Caesar and the Vigenère ciphers.

Would you have been able to crack one of the earliest ciphers used in history? The Caesar Cipher is an encryption system that predates computers. There were no algorithms or supercomputers that could quickly decode an encrypted message.

Encryption is a technique used to send an encoded message. The only way to decode, or decrypt, the message is by knowing the “key”, or how the message was changed. To anyone without the key, the message looks like a random series of characters.

The oldest and simplest form of encrypting a message is known as the Caesar Cipher or the shift cipher. The Caesar Cipher is a type of substitution encryption where each letter in the original message is replaced with a different letter depending on a key value. The key is a number from 0-26 which indicates how many times the letters were shifted up or down in the alphabet. 

For each letter of the alphabet, you would take its position in the alphabet and shift it by the key. For example, let’s say our original message was “B” and our shift was 3. The encrypted message, as shown below, would be “E”. A message of "CAB" would become "FDE".

You Try!

In the activity below, create a message and choose an encryption shift (key) to encrypt your message using the Caesar Cipher.

Puzzle 1: Brute Force

The Caesar Cipher is not a secure encryption, because there are only 26 possible keys to try before cracking the cipher. This is a pretty simple task to complete and wouldn't take that much time, even without using a computer. Cracking the Caesar Cipher with a computer algorithm is a trivial matter that can be completed within seconds. The following puzzle displays a message that has been encrypted using the Caesar Cipher. Can you try all of the keys until you unveil the hidden message?

Was there anything in the last puzzle that you were able to use to help figure out the key? Did the punctuation help? Or maybe the length of the letters? There are characteristics of the English language that can help to decrypt messages. One that is commonly used is letter frequency analysis.

If you've ever heard of the game show, Wheel of Fortune, at the end of the game, they try to help out the contestant by unveiling the letters RSTLNE. Why do you think they chose these specific letters? These letters are some of the most commonly used letters in the English alphabet.

The top three letters in the English alphabet are E, A, and R respectively. Counting the number of times a letter is used in an encrypted message could lead to clues as to which letters they represent!

If you are curious, the solution to the puzzle in the Wheel of Fortune image is "Giant Squid." That's a hard one!

Puzzle 2: Letter Frequency Analysis

To solve this puzzle, take a look at the letter frequency analysis in the item below (scroll down to the chart). Using the information shown and the decrypt tool above, can you break the code by trying less than three keys?

To Vigenère Cipher was another early encryption system that used aspects of the Caesar Cipher but with some improvements. The goal was to avoid being susceptible to brute force and letter frequency analysis. To do this, the Vigenère Cipher consists of several Caesar Ciphers in sequence with different shift values based on a keyword, instead of just one key.

Let's say our keyword is KAREL. We would use 5 different shifts depending on the location of the letters in the word to encrypt our message.

We would use 10 as the shift for the first letter in our message, 0 for the second, 17 for the third, and so forth.

Brute force won’t work on the Vigenère Cipher. Since the keyword can be any length, there are infinite possibilities! The Vigenère Cipher is also resistant to letter frequency analysis because there are multiple shift values which means that “E” is encrypted as different letters at different points, so finding the most common letter won't work!

Puzzle 3: Stumped by Vigenère

Use the encrypted message below (or create your own!) and place it in the letter frequency analysis tool above. Are there any patterns? Or are we stumped by Vigenère?