Main content

### Course: Internet safety > Unit 1

Lesson 10: Data encryption techniques# Encryption, decryption, and cracking

One of the earliest encryption techniques is the

**Caesar Cipher**, invented by Julius Caesar more than two thousand years ago to communicate messages to his allies.The Caesar Cipher is a great introduction to encryption, decryption, and code cracking, thanks to its simplicity.

## Encrypting a message

Imagine Caesar wants to send this message:

`SECRET MEETING AT THE PALACE`

Here's what that might look like encrypted:

`YKIXKZ SKKZOTM GZ ZNK VGRGIK`

That looks an awfully lot like gobbledygook at first, but this encrypted message is actually

*very*related to the original text.The Caesar Cipher is a simple substitution cipher which replaces each original letter with a different letter in the alphabet by shifting the alphabet by a certain amount.

To make the encrypted message above, I shifted the alphabet by 6 and used this substitution table:

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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|

G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F |

S shifts 6 letters over to Y, E shifts 6 letters over to K, etc. Here's the first word and its shifts:

S | E | C | R | E | T |
---|---|---|---|---|---|

Y | K | I | X | K | Z |

## Decrypting a message

According to historical records, Caesar always used a shift of 3. As long as his message recipient knew the shift amount, it was trivial for them to decode the message.

Imagine Caesar sends this message to a comrade:

`EHZDUH EUXWXV`

The comrade uses this substitution table, where the alphabet is shifted by 3:

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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|

D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C |

They can then decode the message with certainty. The first letter "E" was shifted by 3 from "B", the second letter "H" was shifted by 3 from "E", etc. The result is this ominous message:

`BEWARE BRUTUS`

## Cracking the cipher

Imagine that a very literate and savvy enemy intercepts one of Caesar's messages.

`RZ VMZ WMDIBDIB VGG AJMXZN OJ EJDI RDOC XGZJKVOMV OJ YZAZVO OCZ ZIZHT LPZZI VO OCZ IDGZ YZGOV`

That enemy does not know that Caesar always uses a shift of 3, so he must attempt to "crack" the cipher without knowing the shift.

There are three main techniques he could use: frequency analysis, known plaintext, and brute force.

### Frequency analysis

Human languages tend to use some letters more than others. For example, "E" is the most popular letter in the English language. We can analyze the frequency of the characters in the message and identify the most likely "E" and narrow down the possible shift amounts based on that.

Try it out yourself! Paste the message in the text area below and analyze the frequency graph to identify a possible "E":

### Known plaintext

Another term for the original unencrypted message is

**plaintext**. If the enemy already knew some part of the plaintext, it will be easier for them to crack the rest of the encrypted version.For example, messages tend to start with similar beginnings. In WWII, encrypted German messages always started with a weather forecast, which ultimately made them easier for British mathematician Alan Turing to crack.

Do you think Julius started this message in a common way?

### Brute force

There are only 25 possible shifts (not 26 — why not?). The enemy could take some time to try out each of them and find one that yielded a sensible message. They wouldn't even need to try the shifts on the entire message, just the first word or two.

Try it yourself below:

Caesar's enemy wouldn't have a computer to help them, but it likely would take them less than an hour if they understood the idea of the Caesar Cipher.

Have you managed to crack the code and decrypt the message?
Click below for the big reveal!

## Encryption, decryption, and cracking

Thanks to this exploration of the Caesar Cipher, we now understand the three key aspects of data encryption:

- Encryption: scrambling the data according to a secret key (in this case, the alphabet shift).
- Decryption: recovering the original data from scrambled data by using the secret key.
- Code cracking: uncovering the original data without knowing the secret, by using a variety of clever techniques.

Whenever we consider a possible encryption technique, we need to think about all those aspects: how easy is it to encrypt? how easy is it to decrypt? And most importantly, how easy is it for a nefarious individual to crack the code?

We can no longer use the Caesar Cipher to secure our data, as it is far too easy to crack, but understanding the Cipher prepares us for understanding modern encryption techniques.

If you'd like, you can dive deeper into the Caesar Cipher in our Khan Academy tutorial on Ancient Cryptography.

🙋🏽🙋🏻♀️🙋🏿♂️Do you have any questions about this topic? We'd love to answer—just ask in the questions area below!

## Want to join the conversation?

- Can you post the source codes for Frequency analysis and Brute force?(5 votes)
- Hey, Davos. You could use Google in the following manor: "frequency analysis" or "ciphertext brute force", followed by your preferred language, like Python.(2 votes)

- What if you encrypt a message and then encrypt the result of the first encryption. How will you ever know if you have cracked the second encryption(2 votes)
- heres the thing: with caesar's cipher, if you double encyrpt, you really only encrypt it once with a different shift code. For example, if i try to encrypt "hello" using a factor of 2 and then 3, i will get "jgnnq", and then 'mjqqt". This is the exact same result I would get with a factor of 5, since 2+3=5.(6 votes)

- Did they ever double cypher by using it twice?

qxf fxdum hxd onnu ro cx dwuxlt j zdnbcrxw hxd wnnmnm cx mxdkun mx j lryqna?(3 votes)- Yes, ciphers can be applied multiple times to attempt to increase the security of the encryption. In fact, when one of the encryption standards (DES) was shown to be too weak, it became common practice to apply the encryption 3 times (which became known as 3DES).(3 votes)

- That is so cool(2 votes)
- This work is really great for me and I did go work.(2 votes)
- im not shure if im reddey but ill try!<:(1 vote)
- Is this an actual real thing?!(1 vote)
- why does encryption matter to internet safety?(1 vote)
- Is plaintext the words or language that people understand prior to encryption? Is it true to say that if a language remains unwritten, then it would be more difficult to decrypt? Are there any encryptions that are near impossible to crack? Does this mean that more complex encryptions are constantly being created by machines?(0 votes)
- 1. Yes, that is correct.

2. If a language is never written down, what are you writing the encrypted message in?

3. Yes, the One-Time Pad is an encryption that is impossible to crack. However, it has other limitations which is why it is not used in practice. Generally, right now, we rely on AES and RSA which have not yet been broken.

4. Not really. Creating effective encryptions requires a very good understanding of mathematics. So, it is up to humans to create encryptions.(2 votes)

- What is a frequency(0 votes)
- Frequency is the number of times that something occurs.

In the sentence "the quick brown fox jumped over the lazy dog", the frequency of the letter "q" is 1.

I hope this helps! =](4 votes)