How to Create (and Crack) Secret Codes and Ciphers

Secret codes, or ciphers, are a great way to teach computational thinking.

While you can use computers to crack secret codes, also called ciphers, they’re not always needed. And computers on their own cannot decode secret codes. Computers need humans to provide directions. And humans have to think through a series of questions, develop rules for possible solutions, and decide when a possible solution should be abandoned in favor of another.

This project will lead you through a high level method to create secret codes and ciphers, as well as find ways to decode them. Obviously, the field of ciphers is vast and complicated. This puzzle is simply fun. I’ve also patterned this project on a more complicated Google lesson plan which is linked below. And I’ve collected a set of online links to help you figure out secret codes of your own, as well as ideas on how to crack them.

If you’re ready, let’s get started.

What is a Secret Code or Cipher?

A secret code, or cipher, is simply a substitution of one letter in an alphabet for another letter or number. I could say, for example, that instead of typing the letter E I will type the letter F instead. So house becomes housf.

Another type of secret code transposes, or changes, the order of letters in a message. So house might become uoesh.

Another way to create secret codes is to place meaningless words, letters, or characters between meaningful letters or characters. For example, you could take a piece of cardboard the size of letter paper, cut out squares or rectangles, place a piece of paper under your cardboard, write your message using the cut out cardboard spaces, then lift the cardboard and fill out the rest of your paper as if it was one letter. Only when you place the cardboard back down on your letter would you see your real message.

The process of encoding then decoding a message is called cryptography. To do cryptography, you will need a plain text message, a set of rules (algorithm) to encode your message, and a key to help decode your message. In some cases, you’ll also specify the time during which the algorithm and keys are in effect.

Ciphers are slightly different from codes. A cipher mixes up or uses different letters or characters. A code substitutes one word for another word or sentence. For example, FWIW or OMG are codes, aren’t they? FWIW replaces for what it’s worth and OMG replaces Oh My God!

For this project, we’ll focus on a simple pattern to substitute letters and characters.

How Do You Create a Secret Code or Cipher?

Remember my example of replacing the letter E with the letter F, so house becomes housf?

What happens if I say the letter E will be replaced by the letters F plus the letters R and K? What happens if I need to use a word with F, R, or K in them? Creating a sentence this way could get confusing very quickly. The solution is to create a pattern, or set of rules (called an algorithm in computer science), used to translate any sentence encoded with your pattern.

To start, let’s say our pattern will simply shift all letters in the alphabet two spaces to the right. So the letter E becomes the letter G, the letter G becomes the letter I, and so on.

With this simple pattern, house becomes iqwug. Could you figure out what iqwug means?

How Do You Crack a Secret Code or Cipher?

Remember our simple pattern where we shifted the letters of the alphabet two spaces to the right, so house becomes iqwug? Let’s talk about ways we might crack or decode this word.

What you might notice first is that iqwug is an extremely small sample, a word of only five characters in length. To crack any code, you need as many examples of encoded words, sentences, and paragraphs as possible. One five character word might be impossible to crack without other examples.

When you have a large sample of words and sentences encoded with the same pattern, it becomes possible to apply other patterns. For example, in the English language, the letter E is very common.

A large sample of encoded words with our pattern which shifts letters two spaces, turning the letter E into the letter G, would likely have more Gs than most or all other letters. We could begin to try and decode our sentence by changing the letter G to E. Then we could look at how E became G: we might realize G is two letters to the left of E in the English alphabet and try shifting the other letters in our encoded message two spaces to the left.

Decoding and deciphering encoded messages requires lots of thought, as well as trial and error. It’s a fun puzzle to solve.

Try Your Own Cipher

If you recall, to encode and decode a message you will need:

  • A plain text message.
  • A pattern or set of rules to encode and decode your message.

You also could use a key, for example, a dictionary, and set a period of time when your pattern or set of rules is active before it is replaced by another pattern used to encode and decode messages. But these are optional steps and not required to have a little fun with codes and computational thinking.

To create a simple substitution cipher, take a piece of paper and write out every letter of the alphabet. Next to each letter, assign another letter, number, or character to represent the original letter. You can assign these randomly or in a set pattern, for example, assigning the second or third character to the right or left of the original letter. So A might become X if you shift three characters to the left.

Once you have a message to encode, refer to your alphabet and rewrite your message with the letter, number, or character assigned to each letter.

To make things more interesting, work with a partner to create your own substitution patterns and trade encoded messages. See if you can figure out the method of substitution required to decode the message.

If you need a long message, or can’t think of a message, copy text from a book or web page to encode and decode. Longer plain text will allow you to see how letter frequency might help decode a message.

Learn More

Ciphering a Sentence (Google)

Cipher (Wikipedia)

Letter Frequency

Some resources with information about how common individual letters are in the English language. The Wikipedia article includes data on Spanish, Turkish, Swedish, and other languages.

The Secret Language

Secret Codes for Cubs and Scouts

Three Secret Codes to Try With Your Kids

Create Secret Codes and Ciphers (Wiki How)

Cryptography (Wikipedia)


  • Tim Slavin

    Tim is an award-winning writer and technologist who enjoys teaching tech to non-technical people. He has many years experience with web sites and applications in business, technical, and creative roles. He and his wife have two kids, now teenagers, who are mad about video games.

Also In The May 2014 Issue

Computer Science Unplugged

The Computer Science Unplugged movement introduces non-technical people to computer hardware and software concepts that drive the technologies we use.

What is Computational Thinking?

While computers think in rigid predictable patterns, learning computational thinking helps us understand how and why computers work.


We've all used Captchas and found some impossible to solve. Here's why they exist, how they work, and less frustrating alternatives.

Data Types

Programming languages use data types to allocate memory and enforce data integrity. They also reveal the nature of a language.

Lauren Ipsum

If the idea of a computer science book without computers upsets you, please close your eyes until you've finished reading.

The Turing Test

The Turing Test, and its creator Alan Turing, have had a profound effect on computer science and artificial intelligence.

If debugging is the process of removing software bugs, then programming must be the process of putting them in.

May 2014 Learn More Links

Links from the bottom of all the May 2014 articles, collected in one place for you to print, share, or bookmark.


One of two key programming languages (Lisp is the other), FORTRAN defined many of the key ideas used in programming languages.

May 2014 News Wire

Interesting stories about computer science, software programming, and technology for the month of April 2014.

How to Create (and Crack) Secret Codes and Ciphers

Secret codes, or ciphers, are a great way to teach computational thinking.

Grace Hopper

One of the first female programmers, Grace Hopper also worked as a mathematician and had an unusual career for women in the 1900s.


Bogons are not an evil race of aliens. But they do shine a light on one part of the internet little known outside of a few security technologists.

Interested but not ready to subscribe? Sign-up for our free monthly email newsletter with curated site content and a new issue email announcement that we send every two months.

No, thanks!