Coding and Decoding

beginner coding decoding cipher substitution logical reasoning

Coding-decoding is about cracking a secret pattern. We’re given some words and their coded forms, and we need to figure out the rule — then apply it to encode or decode new words. Think of it like being a codebreaker. Once we spot how the cipher works, the problem is solved instantly.

The Alphabet Position Reference

This is our best friend for coding-decoding. Every question in this topic needs us to think of letters as numbers.

A B C D E F G H I J K L M
1 2 3 4 5 6 7 8 9 10 11 12 13
N O P Q R S T U V W X Y Z
14 15 16 17 18 19 20 21 22 23 24 25 26
Reverse pairs: A↔Z(1↔26), B↔Y(2↔25), C↔X(3↔24)... each pair sums to 27

Types of Coding-Decoding

Coding Types to Check
1. Letter shift: Each letter shifts by a fixed amount (+1, +2, -3, etc.)
2. Reverse alphabet: A↔Z, B↔Y, C↔X (each letter maps to 27 minus its position)
3. Position-based shift: 1st letter +1, 2nd letter +2, 3rd letter +3...
4. Number coding: Each letter → its position number (A=1, B=2...)
5. Word reversal: Letters in the word are reversed
6. Symbol substitution: Letters replaced by symbols or other words
7. Word-to-word mapping: Figure out the mapping from example pairs
8. Condition-based (TCS NQT style): Different rules for vowels, consonants, position, etc.

Type 1: Constant Letter Shift

Every letter shifts by the same amount. This is the simplest and most common type.

Example 1: If CAT is coded as DBU, how is DOG coded?

Let’s find the shift:

  • C(3) → D(4): shift = +1
  • A(1) → B(2): shift = +1
  • T(20) → U(21): shift = +1

Every letter shifts by +1. So for DOG:

  • D(4) → E(5)
  • O(15) → P(16)
  • G(7) → H(8)

Answer: EPH

Example 2: If APPLE is coded as YNNJC, how is MANGO coded?

Let’s check the shift:

  • A(1) → Y(25): difference = 25-1 = +24 (or equivalently, -2 since 26-2=24)
  • P(16) → N(14): difference = -2
  • P(16) → N(14): difference = -2
  • L(12) → J(10): difference = -2
  • E(5) → C(3): difference = -2

Each letter shifts by -2 (two positions back). For MANGO:

  • M(13) → K(11)
  • A(1) → Y(25) [wraps around: 1-2 = -1, add 26 = 25]
  • N(14) → L(12)
  • G(7) → E(5)
  • O(15) → M(13)

Answer: KYLEM

Type 2: Reverse Alphabet Coding

Each letter is replaced by its “mirror” in the alphabet. A↔Z, B↔Y, C↔X, and so on. The rule is: coded letter position = 27 - original position.

Example 3: If SMART is coded as HNZIG, how is LUCKY coded?

Let’s verify it’s reverse alphabet:

  • S(19) → H(8): 19 + 8 = 27 ✓
  • M(13) → N(14): 13 + 14 = 27 ✓
  • A(1) → Z(26): 1 + 26 = 27 ✓
  • R(18) → I(9): 18 + 9 = 27 ✓
  • T(20) → G(7): 20 + 7 = 27 ✓

Confirmed: reverse alphabet. For LUCKY:

  • L(12) → O(15) [27-12=15]
  • U(21) → F(6) [27-21=6]
  • C(3) → X(24) [27-3=24]
  • K(11) → P(16) [27-11=16]
  • Y(25) → B(2) [27-25=2]

Answer: OFXPB

Quick trick: In reverse alphabet coding, the same operation decodes. If SMART → HNZIG, then HNZIG → SMART. It’s its own inverse.

Type 3: Position-Based Shift (Variable Shift)

Each letter shifts by a different amount based on its position in the word.

Example 4: If COME is coded as DPOG, find the pattern and decode HVLQ.

Let’s figure out the shifts:

  • C(3) → D(4): +1 (1st position)
  • O(15) → P(16): +1? Wait, let me check: +1?
  • M(13) → O(15): +2 (3rd position)
  • E(5) → G(7): +2 (4th position)

Hmm, let me re-examine: +1, +1, +2, +2. That doesn’t look right. Let’s try: 1st letter +1, 2nd letter +1, 3rd letter +2, 4th letter +2. Or maybe: +1, +1, +2, +2 per pair.

Actually: C→D(+1), O→P(+1), M→O(+2), E→G(+2). The pattern could be: each pair of letters shares the same shift, and the shift increases by 1 per pair. But a cleaner guess: the shift for the nth letter = n. Let me recheck: C(3)+1=D(4), O(15)+2=Q(17)? No, O→P is +1.

Let me try another angle: shifts are +1, +1, +2, +2. To decode HVLQ with the same pattern (-1, -1, -2, -2):

  • H(8)-1 = G(7)
  • V(22)-1 = U(21)
  • L(12)-2 = J(10)
  • Q(17)-2 = O(15)

Answer: GUJO

The pattern was: +1, +1, +2, +2 (the shift increases every two letters). This kind of variable shift pattern is common.

Type 4: Number-Based Coding

Letters are converted to their position numbers, sometimes with an operation applied.

Example 5: If BAD is coded as 214, how is HEN coded?

  • B=2, A=1, D=4 → 214

It’s just a direct position-to-number mapping (without separators). So:

  • H=8, E=5, N=14

Answer: 8514

Watch out: Sometimes they use two-digit numbers which can create ambiguity. In this case, they usually add separators or the question makes it clear.

Type 5: Word-to-Word Coding (Substitution)

Here, entire words are substituted with other words. We’re given example sentences to figure out the mapping.

Example: In a certain code language:

  • “sky is blue” is written as “ra ma pa”
  • “blue is nice” is written as “pa ta ra”
  • “sky is nice” is written as “ra ma ta”

What is the code for “blue”?

Let’s compare sentences to isolate each word:

From sentences 1 and 2: Common words are “is” and “blue” → common codes are “ra” and “pa” From sentences 1 and 3: Common words are “sky” and “is” → common codes are “ra” and “ma”

So “is” is in all three sentences. Codes common to all three: “ra” appears in all three. So is = ra.

From sentence 1 and 3: Both have “sky” and “is” → common codes: “ra” and “ma”. Since is = ra, sky = ma.

From sentence 1: sky(ma) is(ra) blue(?) = ra ma pa. The remaining code is “pa”. So blue = pa.

Answer: pa

Type 6: Condition-Based Coding (Modern Pattern)

This is a newer format popular in TCS NQT and similar exams. Different rules apply based on conditions like vowels vs consonants, position in the word, etc.

Example: Code a word using these rules:

  1. If a letter is a vowel, replace it with the next vowel (A→E, E→I, I→O, O→U, U→A)
  2. If a letter is a consonant, replace it with the previous letter in the alphabet
  3. If the word starts with a vowel, reverse the result

Code the word OPEN:

Step 1: Apply letter rules:

  • O (vowel) → U
  • P (consonant) → O
  • E (vowel) → I
  • N (consonant) → M

Result after letter replacement: UOIM

Step 2: Check condition — OPEN starts with a vowel (O), so we reverse: MIOU

Answer: MIOU

These problems test attention to detail. The trick is to apply each rule carefully and not rush.

Shortcut Tips

  1. First check for constant shift — it’s the most common pattern. Take the first letter pair and find the shift, then verify with the second pair.
  2. If shifts vary, check if they match positions — +1 for 1st letter, +2 for 2nd letter, etc.
  3. If the shift is exactly 13 — that’s a special case called ROT13, where encoding and decoding are the same operation.
  4. For reverse alphabet — quickly check: do the positions of original + coded letters add up to 27?
  5. For word substitution — always compare two sentences that share words. The common words map to common codes.
  6. Remember: A↔Z pair sums to 27. This instantly identifies reverse alphabet coding.

Common Exam Variations

  • Code a single word given the coding rule
  • Decode a coded word given the rule
  • Find the rule from example pairs, then apply it
  • Word substitution in sentence form (match words to codes)
  • Condition-based with multiple rules (vowel/consonant, position, etc.)
  • Mixed coding — part of the word uses one rule, part uses another
  • Number-letter combination — some letters are replaced by numbers and vice versa

Practice Problems

Problem 1: If COMPUTER is coded as DPNQVUFS, how is MACHINE coded?

Problem 2: In a code language:

  • “good morning friend” = “abc def ghi”
  • “good evening friend” = “abc jkl ghi”
  • “morning time” = “def mno”

What is the code for “evening”?

Problem 3: Using the reverse alphabet code (A↔Z, B↔Y…), what is the code for PYTHON?


Answers

Problem 1: Check the shift: C(3)→D(4) = +1, O(15)→P(16) = +1. It’s a constant +1 shift. For MACHINE: M→N, A→B, C→D, H→I, I→J, N→O, E→F. Answer: NBDIJOF

Problem 2: Comparing sentences 1 and 2: common words “good” and “friend” → common codes “abc” and “ghi”. Unique in sentence 1: “morning” = “def”. Unique in sentence 2: “evening” = “jkl”

Problem 3: P(16)→K(11), Y(25)→B(2), T(20)→G(7), H(8)→S(19), O(15)→L(12), N(14)→M(13). Answer: KBGSLM. Verify: 16+11=27 ✓, 25+2=27 ✓, 20+7=27 ✓, 8+19=27 ✓, 15+12=27 ✓, 14+13=27 ✓