Coding and Decoding

intermediate24 min read

The four families of code question — letter shifts, letter-to-number, symbol substitution, and codes you deduce from example pairs — and a fixed routine for cracking each one.

Introduction

Four kinds of code

Almost every coding question is one of four kinds:

  1. Letter shift — each letter moves a fixed number of places along the alphabet.
  2. Letter to number — each letter is replaced by its position (A is 1, Z is 26) or by some arithmetic on that position.
  3. Symbol or number substitution — each letter maps to a fixed symbol or digit, with no pattern to find, only a table to build.
  4. Deduced word codes — you are given two or three words with their codes and must work out the mapping, then apply it.

Decide which kind you are looking at before you try anything else. The method is different for each.

Method

Letter-shift codes

Write the plain word and its code one above the other and find the gap for each letter:

  • If every letter moves the same number of steps forward, that is the shift. CHAIR becoming EJCKT is a shift of plus two.
  • The alphabet wraps: two steps past Y is A, three steps past Z is C.
  • Some codes shift backward, and a few shift the first half of the word one way and the second half the other, so always check two or three letters before trusting the pattern.
  • Once the shift is confirmed on the given word, apply the very same shift to the asked word.
Method

Letters and numbers

Keep the position values in mind: A is 1, E is 5, I is 9, M is 13, Q is 17, U is 21, Z is 26.

  • A plain letter-to-number code just prints those values, sometimes with dashes or spaces between them.
  • A worked code does arithmetic on the value first — double it, add three, or take twenty-seven minus the value, which is the mirror letter (A pairs with Z, B with Y, since one plus twenty-six is twenty-seven).
  • To decode, reverse the arithmetic: if the code adds three, subtract three, then turn the number back into a letter.
Concept

Deduced word codes and coded relationships

Deduced word codes. Line the word up against its code letter by letter. If two given words share a letter and their codes share a symbol in the matching place, that pairing is fixed. Watch for codes whose parts are reordered — the mapping can still be one-to-one even when the positions are shuffled.

Coded relationships and directions. Here a symbol stands for a fixed operation, such as P # Q meaning Q is north of P, or A @ B meaning A is the mother of B. Build the picture one symbol at a time from left to right, drawing as you go, then read the final question off the finished picture.

Worked example

Worked example

1. Letter shift. In a code, CHAIR is EJCKT and TABLE is VCDNG. Write DESK.

Compare CHAIR with EJCKT: C to E is plus two, H to J is plus two, A to C is plus two, I to K is plus two, R to T is plus two. Check on TABLE: T to V, A to C, B to D, L to N, E to G — all plus two. Apply plus two to DESK: D to F, E to G, S to U, K to M. The code is FGUM.

2. Symbol substitution. If LOAN is 4 9 1 7 and NOTE is 7 9 3 5, write TALE.

From the first: L is 4, O is 9, A is 1, N is 7. From the second: N is 7 and O is 9 agree, and T is 3, E is 5. So TALE is T 3, A 1, L 4, E 5, that is 3 1 4 5.

Common mistake

Common mistakes

  • Reading the shift off one letter and not checking a second, so a mixed pattern slips past.
  • Forgetting the wrap, and stopping at Z instead of continuing to A.
  • Mixing up the direction — the code shifts forward but you decode by also going forward instead of back.
  • Assuming the code keeps letter order when the parts have been reordered.
  • Building a fresh table for every word in a substitution set, instead of carrying the one table across all the questions.
  • In a relational code, jumping to the question before the full picture is drawn.
Quick revision

Quick revision

  • Name the code family first: shift, letter-to-number, substitution, or deduced word code.
  • For a shift, find the constant gap, confirm it on two or three letters, mind the wrap past Z, then apply the same gap to the asked word.
  • For number codes, remember A is 1 to Z is 26; undo any arithmetic to decode; twenty-seven minus the value is the mirror letter.
  • For substitution, build one table and reuse it for every question in the set.
  • For coded relationships and directions, draw the picture link by link, then answer from the picture.
Practice

Practice

Give the answer and a one-line reason.

  1. If RAIN is SBJO, write SNOW.
  2. If MANGO is NBOHP, write APPLE.
  3. With A as 1 up to Z as 26, decode 13 1 20 8.
  4. If DELHI is WVOSR (each letter replaced by its mirror), write PATNA.
  5. If CAT is 3-1-20 and DOG is 4-15-7, write BAD.
  6. If pen is qfo and ink is jol, write cap.
  7. If FROG is IURJ, write TOAD.