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.

Ciphers

# 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.
Review how this works using the interactive tool below:
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?

• I have heard of people in the military doing code braking but do people actually get pay to that for a living? And what are they called ?
• There are a lot of people who get paid to break codes. Just think about all the possible reasons people and organisations may have to try to keep their messages secret. The military and terrorists are given. Governments. Think about who would be interested in what they are trying to hide. Companies trying to keep business secrets, other companies trying to steal business secrets. Spies. Criminals. Paranoid people.

Tens of thousands of highly skilled mathematicians and computer scientists spend their entire careers on stuff like that.

It's a HUGE field, and without a doubt a colossal waste of human talent. A lot of it has to be done, though. It's a fact of life.
• I totally don't get can any one help me understand please
• A code involves simple translation. "ABC" is code for "Hello There!"
A cipher is like a mathematical function, you input something and get an output. I input "ABC" into the cipher and it outputs "Hello There!".
Code is more direct, you just look up what something means. A cipher is a way of translating the code without having everything listed out.
• how come when you type in your name, and then type in the output, the 2nd output is not your name

e.g if i type in 'clare' and get 'lujan'
if i type in 'lujan' i don't get 'clare' ?

please let me know if you have the answer to this question. if you don't get what i mean, or you don't know, please don't answer, just comment.
Thanks!
- a KA user.
• So basically a cipher has a specific rule, and that rule would work for whatever things you put into that message,
and a code would be a symbol/word/number that represents a meaning, right?
• Basically a cipher changes the literal characters typed in based on some algorithm while a code shortens linguistic constructs based on their meaning.
• So any time you write code for a computer program it is automatically considered an algorithm?
• An algorithm is a set of steps required to complete a task. So an algorithm for you going to work in the morning would include stuff like, waking up, eating breakfast, brushing your teeth, getting in your car, etc., etc.

When computer code is written, every step has to be laid out for the computer because (without the use of 1000s of IF statements or advanced AI) it can't make any real decisions on its own. For instance, if the algorithm for you driving to work described a step to turn right on a given street, the computer will make that turn, even if the street is blocked for construction or an accident, because it won't deviate from the algorithm unless being programmed to. I hope this general example and simplified explanation helps.
• Who has read 'The Davinci code' or 'Angels and Demons'?( Both books by Dan Brown.) I love how both books are full of codes that show the past, give clues to the present, and show the future. Vote if you agree and if you think these books and the author who wrote them are A M A Z I N G :D :D
• I think I watched the videos. They're pretty interesting, like you say. I wasn't interested in the New Testament but I was using it to learn Greek and got a very strong impression about Christ from the Gospels. The church we have now is only one version of many that have disappeared. All that history is interesting and important. Elaine Pagels is a very good historian and writer on this topic and I recommend her many books.
• People say cracking a code when it is actually craking a cipher.
• And the signal fire! Is it a binary code?