Coding & Decoding
Spies, soldiers and computers all hide messages in codes. In this lesson you become a code-breaker: find the secret rule from one example, then use it to write or read any word.
1What is coding? The 4-step method
Coding means changing a word into a secret form using a fixed rule. Decoding means turning the secret form back into the real word. In every question you get one example (the key), like CAT โ DBU, and must use its rule on a new word.
The 4-step method
- Line up the word and its code, letter under letter. Check if they have the same number of letters.
- Write the move for each letter: +1, โ2, opposite, or โjumped to another placeโ. Use positions (EJOTY!).
- Name the rule: same move for all? moves growing? letters reversed? Check it on every letter.
- Apply the rule to the new word โ and for decoding, do the moves backwards.
A letter that repeats in the word usually repeats in the code too. BOOK has โOOโ in the middle, so its code should have a double letter in the same places. Use this to cross out options in seconds.
2Letter-shift codes (+n and โn)
The most common code moves every letter forward or backward by the same number of places. Julius Caesar is said to have used a +3 shift for his secret army messages, so this is often called the Caesar cipher.
If COW is coded as EQY, how is GOAT coded?
- C โ E (+2), O โ Q (+2), W โ Y (+2). Rule: +2.
- G + 2 = I, O + 2 = Q, A + 2 = C, T + 2 = V.
- Answer: IQCV.
If MILK is coded as LHKJ, how is TEA coded?
- M โ L, I โ H, L โ K, K โ J: each letter goes one back (โ1).
- T โ 1 = S, E โ 1 = D, A โ 1 = Z (before A comes Z).
- Answer: SDZ.
Decoding: run the rule backwards
In a code, every letter is written as the letter 3 places after it. What real word does the code FDW stand for?
- Coding added 3, so decoding must subtract 3.
- F โ 3 = C, D โ 3 = A, W โ 3 = T.
- The real word is CAT. Check: C + 3 = F, A + 3 = D, T + 3 = W โ.
When the question gives the code and asks for the real word, you must move the opposite way. Setters always put the โwrong-directionโ answer in the options (for FDW that would be IGZ). Tip: a real word must be a real word โ IGZ isn't one!
If COW is coded as DPX, how is HEN coded?
In a code, each letter is replaced by the letter 2 places before it. Which real word is written as ZYJJ?
3Codes where the shift changes
If the moves are not all the same, write them in a row. They usually make a simple pattern.
If CAT is coded as DCW, how is PIG coded?
- C โ D is +1, A โ C is +2, T โ W is +3.
- P + 1 = Q, I + 2 = K, G + 3 = J.
- Answer: QKJ.
If SEAT is coded as TDBS, how is LAMP coded?
- S โ T (+1), E โ D (โ1), A โ B (+1), T โ S (โ1). The moves take turns: +1, โ1.
- L + 1 = M, A โ 1 = Z, M + 1 = N, P โ 1 = O.
- Answer: MZNO.
If RAIN is coded as OJBS, how is SNOW coded?
- Line up: R โ O, A โ J, I โ B, N โ S. These moves (โ3, +9, โ7, +5) make no pattern. When that happens, try reversing the word.
- RAIN reversed is NIAR. Now N โ O, I โ J, A โ B, R โ S: every letter +1. โ Rule: reverse, then +1.
- SNOW reversed is WONS. +1 โ XPOT.
If the moves look random, check two things: is the code the reverse of the word (with or without a shift)? Or has each letter become its opposite? One of these almost always explains it.
If RAIN is coded as OJBS, how is SNOW coded?
4Reverse, opposite and jumbled-position codes
Reverse codes
The word is written backwards: PLAY โ YALP, STOP โ POTS.
Opposite-letter codes
Each letter becomes its opposite (A โ Z, B โ Y โฆ M โ N). Use 27 โ position.
In a code, A is written as Z, B as Y, C as X, and so on. How is HELP written?
- H = 8 โ 27 โ 8 = 19 โ S.
- E = 5 โ 22 โ V; L = 12 โ 15 โ O; P = 16 โ 11 โ K.
- Answer: SVOK.
The opposite-letter code is very old. It is called Atbash and was first used with the Hebrew alphabet. A neat property: coding twice gives back the original word, because the opposite of the opposite is the letter itself!
Jumbled-position codes
Sometimes no letter changes โ the letters just move to new places. Number the positions and watch where each one goes.
| Rule | Example | Apply to |
|---|---|---|
| Swap each pair | TABLE โ ATLBE | PLANT โ LPNAT |
| First letter moves to the end | CHAIR โ HAIRC | WATER โ ATERW |
| Reverse each half | PENCIL โ NEPLIC | GARDEN โ RAGNED |
| First two letters move to the end | TIGER โ GERTI | SPOON โ OONSP |
If BOMBAY is written as MYMYMY, how is TAMILNADU written?
- Number BOMBAY: B1 O2 M3 B4 A5 Y6. The code uses the 3rd and 6th letters (every 3rd letter), โMYโ, repeated 3 times.
- Number TAMILNADU: T1 A2 M3 I4 L5 N6 A7 D8 U9. Every 3rd letter: M, N, U.
- Repeat โMNUโ 3 times: MNUMNUMNU.
In a code, A is written as Z, B as Y, C as X, and so on. How is FISH written?
5Number and symbol codes
Letters as numbers
| Type | Rule | Example |
|---|---|---|
| Position code | A = 1, B = 2 โฆ Z = 26 | FACE โ 6-1-3-5 ยท 8-1-20 โ HAT |
| Reverse position code | Z = 1, Y = 2 โฆ A = 26 (use 27 โ n) | CAT โ 24-26-7 |
| Sum code | Add all the letter positions | BED โ 2 + 5 + 4 = 11 |
| Given table | Each letter gets the digit you are told | T = 4, R = 7, A = 1, P = 9 โ PART = 9174 |
In a code, BED is written as 11 and BAG as 10. How is FACE written?
- Test the sum idea: BED = 2 + 5 + 4 = 11 โ; BAG = 2 + 1 + 7 = 10 โ.
- FACE = F (6) + A (1) + C (3) + E (5).
- Answer: 15.
If T = 4, R = 7, A = 1 and P = 9, how is TRAP written?
- Replace one letter at a time, keeping the order: T โ 4, R โ 7, A โ 1, P โ 9.
- Answer: 4719.
In a sum code, words with the same letters in a different order get the same number: DOG = 4 + 15 + 7 = 26 and GOD = 26 too. Don't expect the number to change just because the order did.
Symbol codes
Digits or letters can be swapped for symbols. Replace carefully, one by one, and keep the order.
| Digit | 1 | 2 | 5 | 8 |
|---|---|---|---|---|
| Symbol | โ | โ | โ | โฒ |
Using the table, how is 2851 written? And what number is โ โ โ?
- 2 โ โ, 8 โ โฒ, 5 โ โ , 1 โ โ . So 2851 = โโฒโ โ .
- Decode: โ โ 5, โ โ 1, โ โ 2. So โ โ โ = 512.
Using A = 1, B = 2, โฆ, Z = 26, a word's code is the sum of its letters. If DOG = 26, what is GOD?
6Word-substitution codes (โis calledโ)
In these puzzles, real things get new names. The question asks about the real world, but you must answer with the new name.
If water is called food, food is called tree, tree is called sky and sky is called wall, then (a) what do we drink? (b) where do birds fly?
- (a) In real life we drink water. Find water on the left of an arrow: water โ food. Answer: food.
- (b) In real life birds fly in the sky. Sky โ wall. Answer: wall.
Two traps hide here. (1) Answering with the real word (โwaterโ) โ the question wants the code name. (2) Following the chain too far (water โ food โ tree). Take only one step: the word that the real thing โis calledโ.
If pen is called pencil, pencil is called eraser, eraser is called sharpener and sharpener is called box, what do we use to rub out a pencil mistake?
7Code languages: sentences in code
Here each word of a sentence has a code word, but the code words may be jumbled. Use the common-word method: if two sentences share one word, they share one code, and that code belongs to that word.
'la pa ta' means 'red big ball'; 'ta sim ro' means 'ball is round'; 'pa ro ne' means 'big round tree'. What is the code for red?
- Sentences 1 and 2 share โballโ and share โtaโ โ ball = ta.
- Sentences 1 and 3 share โbigโ and share โpaโ โ big = pa.
- Sentence 1 is 'red big ball' = 'la pa ta'. Take away pa and ta โ red = la.
- Bonus: round = ro (2 and 3), so is = sim and tree = ne.
The position of a code word does not tell you its meaning โ in 'la pa ta' the code for 'ball' is last, but in 'ta sim ro' it is first. Always compare sentences.
'jo ne ra' means 'come here now' and 'ra pi lo' means 'now go away'. What is the code for now?
8Code-breaker's checklist and traps
- Count letters. Same length? Letters changed or moved. Different length? Letters were picked or repeated (BOMBAY type).
- Try the easy moves first: +1, โ1, +2, โ2, then opposite (27 โ n), then reverse.
- Write every move. Growing (+1, +2, +3)? Alternating (+1, โ1)? Nothing? Reverse the word and try again.
- Apply to the new word letter by letter. Remember wrap-around: after Z comes A.
- Decoding? Do the moves backwards, then check your answer by coding it forward again.
- Check all letters of your chosen option โ the wrong options usually get only the first one or two letters right.
For โDOG โ ?โ with a +1 code, options might be EPH, EPG, EOH and FPH. All start with E except one, so looking only at the first letter doesn't help. Check every letter: D + 1 = E, O + 1 = P, G + 1 = H โ EPH.
Explore more
- ๐ฎCaesar cipher explorationkhanacademy.org ยท slide the wheel and code your own messages
- ๐Caesar ciphersimple.wikipedia.org ยท the shift code used by Julius Caesar
- ๐Atbashwikipedia.org ยท the ancient opposite-letter code (A โ Z)
- ๐Cryptographysimple.wikipedia.org ยท how codes keep messages secret
- ๐Morse codesimple.wikipedia.org ยท letters as dots and dashes โ a symbol code
9Quick recap
- Coding = real word โ secret form. Decoding = secret form โ real word.
- Line up word and code; write the move under every letter.
- Shift codes: same move for all letters (+1, โ2, +3โฆ). After Z comes A; before A comes Z.
- Decoding runs the rule backwards; check by coding forward again.
- Moves can grow (+1, +2, +3) or take turns (+1, โ1).
- No pattern? Try reversing the word, then look for a shift.
- Opposite code: letter โ 27 โ position (A โ Z, M โ N).
- Jumbled codes: number the positions and see where each letter moves.
- BOMBAY โ MYMYMY picks every 3rd letter and repeats it.
- Number codes: A = 1 โฆ Z = 26, reverse Z = 1, sum of positions, or a given table.
- Sum codes give the same number for the same letters in any order.
- โIs calledโ puzzles: find the real answer, then give its code name (one step only).
- Code languages: common word โ common code.