When we think of codes, we usually think of spies, espionage and intrigue. Although codes have been used extensively by various governments, codes are used in many other ways as well, not just in spy rings.

Codes are all around us. One of the most famous codes is the Morse Code, used for many years in telegraphy. Invented by Samuel Morse, his code allowed letters of the alphabet to be sent long distances. Short electrical signals were the "dots," and long electrical signals were the "dashes."

Another code that you see almost every day is a bar code which can be found on almost everything you buy at the store. These black bars and the spaces between them can be read by optical scanners, which then read the code, feed the information into the computer, match that code to the code on file, then register the correct price on the cash register.

In written messages, a code normally substitutes words with other words. For instance, a military leader might use a code where "enemy" would be written as "flour barrels." He would use a codebook to look up each word he needed to use in his message. When his soldiers received the message, they would use a matching codebook to look up the real meanings. Codes like this have the weakness of falling apart completely – and permanently – if the enemy can get hold of just one of your codebooks.

On the other hand, a cipher normally relies on a key, which is the method used to decipher, or figure out, the message. Ciphers usually have two advantages: they are generally harder to crack than a code, and they are typically less cumbersome to use. For instance, look at the following (very simple) cipher and see if you can decipher it before you read any further:

3-15-4-5-19  1-14-4  3-9-16-8-5-18-19  8-1-22-5  16-21-26-26-12-5-4  16-5-15-16-12-5  5-15-18  20-8-15-21-19-1-14-4-19  15-6  25-5-1-18-19.  2-21-20  20-8-5-25  1-12-12  8-1-22-5  20-8-5  19-1-13-5  16-21-18-16-15-19-5:  20-15  16-18-15-20-5-3-20  9-13-16-15-18-20-1-14-20  9-14-6-15-18-13-1-20-9-15-14.

As you've probably noticed, this cipher works by substituting numbers for letters. 1 represents A, 2 represents B, and so on, with a dash between each letter so the numbers can be read properly. The key to this cipher is the numbering sequence. You could change the cipher by using 1 for Z and 26 for A. Either way, someone would need to know the key to read the message.

Julius Caesar used a cipher in which each letter was represented by the letter three places to its right in the alphabet, "wrapping around" to the beginning for the letters X, Y and Z. With this cipher, "time for lunch" would be written as "wlph iru oxqfk." The key to this cipher is the "letter shift." You could easily use the same principle with a letter shift of five or six positions, or by changing the direction of the shift.

Ciphers can be cracked (figured out without the key) in several different ways. Frequency analysis is one way. By knowing how often certain letters are normally used, a cryptographer (someone who studies codes and ciphers) can sometimes figure out which symbols in a message represent which letters. For example, E is the most common letter in the English language. So, if you wrote a cipher where each letter was represented by a different letter, and if you chose P to represent the letter E, a cryptographer could probably figure out that P meant E just by realizing there were more P's than any other letter in your message. Frequency analysis works best on longer messages since correct guesses are easier to identify.

Now that you know a little about codes and ciphers, let's try to make our own. Say we'd like to send the following message:

I want pizza for supper.

We'll start with a simple substitution cipher, where A stands for Z and vice-versa, B stands for Y, C for X, and so on. Therefore, our message will now read like this: