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.

Main content

Ciphers vs. codes

Ciphers vs. codes
To begin, let’s make sure we understand the difference between a cipher and a code. Actually, I dare you to get up and go ask someone the same question right now. While you do that I’ll wait here and admire this Lorenz cipher machine...
Did they stumble around for an answer? For most people, it’s as if you asked them what the difference is between mix and blend. Tough question. Luckily, we have a video on Morse Code which introduces the idea of a codebook—check it out! In the video we see how telegraph operators could save time by mapping entire sentences to shorter words.
Here, the word accountant is code for "Come at once. Do not delay." A code is a mapping from some meaningful unit—such as a word, sentence, or phrase— into something else—usually a shorter group of symbols. For example, we could make up a code where the word apple is written as 67. Generally codes are ways of saving time, and when sending messages around the world, time is money.
A codebook is simply a list of these mappings. Codebooks have been around ever since we began writing. Just remember,a code requires a codebook.
Okay, so what about ciphers?
Most importantly, ciphers do not involve meaning. Instead they are mechanical operations, known as algorithms, that are performed on individual or small chunks of letters. For example, in the Caesar Cipher we saw how each letter in the alphabet was mapped to a different letter. For example, A→D,  B→E, and C→F, when we're using a shift of four. This kind of cipher is known as a shift cipher.
In this case, we don’t need a codebook. Instead, we follow a series of instructions—also known as an algorithm—where we shift each letter by a certain number. The algorithm requires one piece of shared information known as a key. In the example above where A→D, the key is four. This shared key is required for two parties to encrypt messages: HELLO → KHOOR, and decrypt messages: KHOOR→HELLO.
So back to our question: What is the difference between codes and ciphers? Codes generally operate on semantics, meaning, while ciphers operate on syntax, symbols. A code is stored as a mapping in a codebook, while ciphers transform individual symbols according to an algorithm.
Now, let’s review the mechanics involved in the Caesar Cipher in the next exercise.

Want to join the conversation?

No posts yet.