Classical Ciphers
Two – Substitution and Transposition – types of Historical/Classical/Conventional Cipher.
Substitution Cipher: Type of encryption where each letter or symbol in the plaintext is
replaced by another letter or symbol or number.
– Monoalphabetic Substitution { e.g. → Shift Cipher }
– Polyalphabetic Substitution { e.g. → Vigenère Cipher, Vernam Cipher }
– Playfair Cipher
– Hill Cipher
E.g. → NETWORK→ OFUXPSL
Transposition Cipher: Encrypts by performing some sort of permutations(i.e. – rearranging
the positions of the characters) on plaintext. They can be keyed or keyless.
– Rail Fence Transposition
– Row-Column Transposition
– Double Transposition
E.g. → NETWORK→ KOENTRW
Monoalphabetic Substitution: Same plaintext letter is always replaced by the same
ciphertext letter. Shift cipher is a Monoalphabetic cipher.
E.g.– A T T A C K S = n d d n t q; here, A is always replaced by N, and T is replaced by D.
Polyalphabetic Substitution: More than one substitution for the same plaintext letter,
generated based on a key/ keyword.
E.g. – A T T A C K S = n d f q c y; here A has different substitutions (n , q), so as T (d, f).
Transposition Techniques:
1) Rail Fence Technique: Keyless Transposition, plaintext is written as a sequence of
diagonals and read off as a sequence of rows.
E.g. → “Today is Friday” - encrypt w/ a depth 2 rail fence:
\ 𝑇 \𝑑 \𝑦 \𝑠 \𝑟 \𝑑 \𝑦
\ 𝑜 \𝑎 \𝑖 \𝐹 \𝑖 \𝑎 \
Here, encrypted text is : “T D Y S R D Y O A I F I A”
→ It is used for short messaging and easily breakable by attackers.
2) Row-Column Transposition Technique:
→ Write the message in a rectangle , row by row
→ Read off the message , column by column
→ Permute the order by column (given as key)
→ Key – integer value (0 to 9)
→ Generate KEY For: “C R Y P T O” : 1 4 6 3 5 2, As Sorted Order = C - O - P - R - T - Y
→ key : S T R I P E = 5 6 4 2 3 1, As sorted Order = E - I - P - R - T - S
E.G. – KEY : (4 3 1 2 5 6 7); PLAINTEXT : “attack postponed until two am”
Solution:
4 3 1 2 5 6 7
a t t a c k p
o s t p o n e
d u n t i l t
w o a m x y z
Here, X, Y, Z are extra or dummy bits.
Therefore, ciphertext : TTNA APTM TSUO AODW COIX KNIY PETZ
PROBLEMS: Can easily be understood by attackers.(use for short messaging)
Solution: It can be made more secure by performing more than one stage of transposition.
So, the result will be a more complex permutation.
4 3 1 2 5 6 7
t t n a a p t
m t s u o a o
d w c o i x k
n l y p e t z
Ciphertext: “NSCY AUOP TTWL TMDN AOIE PAXT TOKZ”
3) Double Transposition Techniques: Applied row/columnar transposition twice. And the
key can be either the same or different.
Substitution Techniques:
1)Playfair Cipher
It was invented in 1854 by Charles Wheatstone, was named after Lord Playfair, who
promoted the use of this cipher.
How does it work?
i) Matrix Generation
→ Choose a keyword (e.g., MONARCHY).
→ Remove duplicate letters.
→ Fill a 5×5 matrix with the letters of the keyword.
→ Fill remaining spaces with the rest of the alphabet (I and J are treated as the same
letter).
E.g. → MONARCHY
M O N A R
C H Y B D
E F G I/J K
L P Q S T
U V W X Z
ii) Preprocess Plaintext
→ Divide plaintext into pairs of 2 letters.
→ Insert X between repeated letters in a pair (e.g., BALLOON → BA LX LO ON).
→ If the last letter is single, add an Z (padding).(e.g., WATCH - WA TC HZ)
iii) Encryption Rules (per pair)
For each pair, let’s say (A,B):
→ Same Row : Replace each letter with the letter to its right (wrap around if needed).
E.g.- MA → OR, IK → KE, VW → WX, LT → PL
→ Same Column : Replace each letter with the letter below (wrap around).
E.g. - MU → CM, OP → HV, YG → GQ, JX → SA
→ Rectangle (Box) : Replace each letter with the letter in the same row but in the
column of the other.
E.g. - MZ → RU, OS → AP, BK → DI, QI → SG
How To Decrypt
→ Use same matrix
→ Reverse the direction for the same row and column.
Q: Key = BANGLADESH, Encrypt = “ATTACK AT TWELVE AM”
2) Vernam Cipher(For Letters)
→ Converts letters to numbers (A = 0, B = 1, ..., Z = 25)
→ Uses a key of the same length as the plaintext
→ Apply (P+K) mod 26 , i.e, modular addition: 𝐶𝑖 = (𝑃𝑖 + 𝐾𝑖 ) 𝑚𝑜𝑑 26
[ Remark : For bit transmission, it will be mod 2, same as XOR operation ]
→ Converts result back to a letter
For Decryption, 𝑃𝑖 = (𝐶𝑖 − 𝐾𝑖) 𝑚𝑜𝑑 26
Letter Indexing:
A B C D E F G H I J K L M
0 1 2 3 4 5 6 7 8 9 10 11 12
N O P Q R S T U V W X Y Z
13 14 15 16 17 18 19 20 21 22 23 24 25
Plaintext : “ATTACK NOW” AND KEY : “ATTEMPTED”
𝑃𝑖 0 19 19 0 2 10 12 13 22
𝐾𝑖 0 19 19 4 12 14 19 4 3
𝑃𝑖 + 𝐾𝑖 0 38 38 4 14 24 31 17 25
(𝑃𝑖 + 𝐶𝑖) 𝑚𝑜𝑑 26 0 12 12 4 14 24 5 17 25
Therefore, the encrypted text is : AMMEPYFRZ
Vernam Cipher is actually used for bit transmission, A special version of vernam cipher is
called one-time pad, where modulo 2 addition(i.e., XOR operation) is performed for encryption
and decryption. And keys are completely random, in fact a single key used only once.
3) Vigenere Cipher
The Vigenère Cipher was designed by Blaise de Vigenère in the 16th century, who was a
French diplomat and cryptographer. It’s a Polyalphabetic cipher, a stronger version of shift
cipher. It’s also considered as a very secure cipher.
How does it work?
→ Choose a keyword, let’s say, Key = LOCK
→ Repeat the keyword as long as the plaintext
E.g. → plaintext = G I V E M O N E Y
Key =LOCKLOCKL
→ Now, do the modulo 26 addition(i.e. Same as shift cipher)
𝑌𝑖 = 𝐸𝑘(𝑋𝑖) = (𝑋𝑖 + 𝐾𝑖 ) 𝑚𝑜𝑑 26
𝑋𝑖 = 𝐷𝑘(𝑌𝑖) = (𝑌𝑖 − 𝐾𝑖 ) 𝑚𝑜𝑑 26
Q: P = “ATTACK NOW”, K = “KEY”, encrypt this message, and then decrypt it to the original text
by using Vigenere cipher.
Solution:
Plaintext = A T T A C K N O W
KEY =KEYKEYKEY
ENCRYPTION AND DECRYPTION:
𝑃𝑖 0 19 19 0 2 10 12 13 22
𝐾𝑖 10 4 24 10 4 24 10 4 24
𝑃𝑖 + 𝐾 𝑖 10 23 43 10 6 34 22 17 46
𝐶𝑖 = (𝑃𝑖 + 𝐾𝑖) 𝑚𝑜𝑑 26 10 23 17 10 6 8 22 17 20
CIPHERTEXT K X R K G I W R U
𝑃𝑖 = (𝐶𝑖 − 𝐾𝑖) 𝑚𝑜𝑑 26 0 19 19 0 2 10 12 13 22
(10-10) (23-4) (17-24)+26 (10-10) (6-4) (8-24)+26 (22-10) (17-4) (20-24)+26
PLAINTEXT A T T A C K N O W