If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

### 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:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
GHIJKLMNOPQRSTUVWXYZABCDEF
S shifts 6 letters over to Y, E shifts 6 letters over to K, etc. Here's the first word and its shifts:
SECRET
YKIXKZ
Now imagine Caesar wants to send the following message, with the same shift of 6:
`ALEXANDRIA SOON`
What would be the encrypted message?

## 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:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
DEFGHIJKLMNOPQRSTUVWXYZABC
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`
Here's another message Caesar might send:
`FURVV WKH UXELFRQ`
Assuming Caesar's usual shift of 3, what does that decrypt to?

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

## Want to join the conversation?

• Can you post the source codes for Frequency analysis and Brute force?
• Hey, Davos. You could use Google in the following manor: "frequency analysis" or "ciphertext brute force", followed by your preferred language, like Python.
• 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
• 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.
• 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?
• 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).
• That is so cool
• This work is really great for me and I did go work.
• im not shure if im reddey but ill try!<:
(1 vote)
• Is this an actual real thing?!
(1 vote)
• yes, it is
(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?