Crack the Code! Make a Caesar Cipher
If you need to send a secret message to a friend, how could you prevent other people from reading it? One way is to encrypt the message, or use a secret code that only you and your friend know. Try this activity to learn how to create your own "Caesar cipher," a popular type of code that is easy to learn.
This activity is not appropriate for use as a science fair project. Good science fair projects have a stronger focus on controlling variables, taking accurate measurements, and analyzing data. To find a science fair project that is just right for you, browse our library of over 1,200 Science Fair Project Ideas or use the Topic Selection Wizard to get a personalized project recommendation.
Cryptography is the study of writing or solving secret codes that are used for secure communication. Historically, codes have been used by politicians, spies, and countries at war to prevent their enemies from knowing what they're up to. Many of the earliest codes, or "ciphers," like the one you will create in this project, were easy to create by hand. However, modern cryptography is essential in computer science for keeping everything from emails to bank account information secure.
One of the earliest and most widely known ciphers is the Caesar Cipher, named after Julius Caesar. It is a simple form of a "substitution cipher" where you replace each letter of the alphabet with another letter by shifting the whole alphabet a certain number of letters (wrapping around to the beginning once you reach the end). For example, if you shift each letter by 3 spaces, then the alphabet looks like this:
So, when you write your message, the letter "A" gets replaced with "X", "B" gets replaced with "Y", and so on. For example, the word "hello" becomes:
In order to decode your message, you need to share the "key" (the number 3) with your friend first. After that, you can send messages that are written in cipher, so other people can't read them!
Extra: try finding a third person who does not know what a Caesar cipher is. Can they crack your code if they "intercept" your message?
Extra: what if the person who intercepts your message knows about Caesar ciphers? Does that make it easier to crack the code? Since there are only 25 possible keys, Caesar ciphers are very vulnerable to a "brute force" attack, where you simply try each possible combination of letters. This might take some patience for a human to do, but modern computers can do that in a fraction of a second, so Caesar ciphers are not considered a secure method to encrypt electronic communications.
Extra: another way to crack the Caesar cipher is "frequency analysis." Frequency analysis is based on the fact that, in natural English speech and writing, certain letters appear much more frequently than others. For example, the letter "e" appears more often than any other letter, and "z" appears the least often (if you have ever played the board game Scrabble®, you may notice that this determines how many points letters are worth!). So, for example, if you read an entire paragraph and notice that the letter "d" appears more often than any other letter, odds are that it used a Caesar cipher with a shift of 1. This technique will be more accurate for longer blocks of text and very inaccurate for short words or phrases, since there are plenty of words that do not contain the letter "e" at all. Can you have a friend write an entire paragraph with a Caesar cipher and then try to crack it using frequency analysis?
Extra: if you plan to use the Caesar cipher for regular communication, one risk is that eventually someone will discover your key. You can help prevent this by changing the key, for example using a new one every week. This is a similar concept to periodically changing your computer passwords.
Extra: the Caesar cipher is just one type of substitution cipher. Look up some other types of substitution ciphers and try them out. Are they harder or easier to use and crack?
Observations and Results
Once you and your friend both understand how to use a Caesar cipher, it should be relatively easy to send encrypted communications to each other. This can be a fun way to pass secret messages back and forth between friends. However, while the Caesar cipher provides a great introduction to cryptography, as discussed above, in the era of modern computers it is no longer a secure way to send encrypted communications – so please don't try to use it for any personal information online (like your address or bank account information)!
More to Explore
Ben Finio, PhD, Science Buddies
Science Buddies |
Explore Our Science Videos
Flower Dissection - STEM Activity
Solubility Science - STEM Activity
Make a Hygrometer to Measure Humidity - STEM activity