Classical Cryptosystems
Dr Om Pal, Associate Professor
Dept of Computer Science,
University of Delhi
Classic Ciphers
Ciphers
A cipher is a means of concealing a message, where letters of the message are
substituted or transposed for other letters, letter pairs, and sometimes for many
letters.
Classical Ciphers
In general, classical ciphers operate on an alphabet of letters (such as "A-Z"), and
are implemented by hand or with simple mechanical devices. They are probably
the most basic types of ciphers, which made them not very reliable, especially
after new technology was developed.
The two basic building blocks of encryption techniques are:
• Substitution
• Transposition
Classic Ciphers
Substitution
A substitution technique is one in which the letters of plaintext are replaced by
other letters or by numbers or symbols
Examples are: Caesar Ciphers, Playfairs cipher, Hill cipher, Vigenère cipher etc.
Transposition
A very different kind of mapping is achieved by performing some sort of
permutation on the plaintext letters. This technique is referred to as a
transposition cipher.
The simplest such cipher is the rail fence technique, in which the plaintext is
written down as a sequence of diagonals and then read off as a sequence of
rows. For example, to encipher the message "meet me after the toga party" with a
rail fence of depth 2, we write the following:
Transposition
Rail Fence cipher
• Rail Fence Cipher (also called a zigzag cipher)
generally refers to a form of transposition cipher. Write
message letters out diagonally over a number of rows
then read off cipher row by row.
Eg. giving ciphertext
MEMATRHTGPRYETEFETEOAAT
write message out as:
mematrhtgpry
etefeteoaat
MEET ME AFTER THE TOGA PARTY
Transposition
Transposition cipher – example
• Write a message in a rectangle (square matrix), row by row and read it
off, column by column.
• Plain text message: meet at five pm behind p lab
• Encrypted text (5x5 matrix):
<read column vise>
mtpia efmnb eibdx tvepx aehlx
• xxx is appended to make message 25 character long.
• Block size (matrix size and dimension)
Transposition
Transposition cipher (Cont.)
• Additionally, a key can also be defined to permute the order of the
columns. Write text in a row by row..
Key 41523
• E.g. key (41523) defines -- read it off – 4th column first, 1st column
second, 5th column third, followed by 2nd and 3rd column, and prepare
encrypted text.
• Encrypted text is:
tvepx mtpia aehlx efmnb eibdx
Monoalphabetic and Polyalphabetic Ciphers
Monoalphabetic and Polyalphabetic Ciphers
• Monoalphabetic - Uses the same substitution across the entire message. For
example, if you know that the letter A enciphered as the letter K, this will hold
true for the entire message. Eg. Caesar cipher
• is
• Polyalphabetic - Substitution may change throughout the message. In other
words, the letter A may be encoded as the letter K for part of the message, but
latter on it might be encoded as the letter W. Eg. Vigenère Cipher is probably
the best-known example of a polyalphabetic cipher.
e t a o i n s h r
.127 .091 .082 .075 .070 .067 .063 .061 .060
Frequencies of most common letters in English
Polygraphic Ciphers
Instead of substituting one letter for another letter, a polygraphic cipher performs
substitutions with two or more groups of letters. This has the advantage of
masking the frequency distribution of letters, which makes frequency analysis
attacks much more difficult. Eg. Playfair Cipher
Substitution
Substitution Ciphers
• Symbols of the text are substituted with another symbols of
the same alphabet.
• OMPAL
• QORCN(+2)
• RPSDO (+3)
Substitution
Substitution ciphers (cont.)
Mono-alphabetic substitution
• Letters of the plain text alphabet are mapped on to unique letters
throughout the entire message text.
• Cipher can be trivially broken because
i. The language of the plain text is easily recognizable.
ii. For English alphabet, only 26 keys – 0 to 25) to search exhaustively.
• Exhaustive key search is always possible <make it practically infeasible is
the goal.
Substitution
Shift
Ciphers
Simply put, we 'shift' the letter A some number of spaces to the right, and start the
alphabet from there, wrapping around when we get to Z.
For example, a three shift looks like:
plaintext: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
ciphertext: X Y Z A B C D E F G H I J K L M N O P Q R S T U V W
In this example, the message:
WHAT KIND OF CAKE SHOULD WE HAVE? ALICE.
From Alice to Bob would look like
TEXQ HFKA LC ZXHB PELRIA TB EXSB? XIFZB.
The Caesar cipher is a special case of a Shift Cipher. Caesar simply
replaced each letter in a message with the letter that is three places further
down the alphabet.
Substitution
Polygram substitution
Playfair cipher
• By Sir Charles Wheatstone in 1854 (named for his friend B. Playfair)
• A digram substitution defined by arranging the characters of a 25-letter
alphabet (I and J are equated) in a 5 x 5 matrix as a key
• A mnemonic aid (a meaningful keyphrase) may be used to easily
remember the 5x5 square
• This method was used in World War I by British and Germans.
Substitution
Playfairs
cipher
If the pair of letters are in different rows
and columns
If the pair of letters are in the same row
If the pair of letters are in the same
column
If the pair of letters are identical
Plaintext ME RC HA NT TA YL OR SZ SC HO OL
Cipher SC OF LM BI SB AR PU BX ME OV RH
Text
Substitution
Adjacent plaintext characters are paired (p1,p2).
p1 🡪 c3, p2 🡪 c4; pair (c3,c4) is defining cipher text
– Rule 1: If p1 and p2 are in distinct rows and columns, they define the
corners of a sub-matrix, they get replaced by remaining corners.
[Right and down then to first character]
– Rule 2: If p1 and p2 are in a common row, they get replaced by
character immediately to the right of them.
For decryption, use left direction.
– Rule 3: If p1 and p2 are in the same column, they get replaced by
characters immediately (circularly) below them.
For decryption, use up direction.
– Rule 4: If p1 = p2, then an infrequent plaintext character (such as
X) is inserted between them and the plaintext is re-grouped.
E.g. word Balloon would become ba lx lo on.
Substitution
Playfairs
cipher
If the pair of letters are in different rows
and columns
If the pair of letters are in the same row
If the pair of letters are in the same
column
If the pair of letters are identical
Plaintext ME RC HA NT TA YL OR SZ SC HO OL
ME
Cipher SC OF LM BI SB AR PU BX ME OV RH
Text
Substitution
Playfairs
cipher
If the pair of letters are in different rows
and columns
If the pair of letters are in the same row
If the pair of letters are in the same
column
If the pair of letters are identical
Plaintext ME RC HA NT TA YL OR SZ SC HO OL
ME
Cipher SC OF LM BI SB AR PU BX ME OV RH
Text ME
Substitution
Playfairs
cipher
If the pair of letters are in different rows
and columns
If the pair of letters are in the same row
If the pair of letters are in the same
column
If the pair of letters are identical
Plaintext ME RC HA NT TA YL OR SZ SC HO OL
ME OR
Cipher SC OF LM BI SB AR PU BX ME OV RH
Text ME
Substitution
Playfairs
cipher
If the pair of letters are in different rows
and columns
If the pair of letters are in the same row
If the pair of letters are in the same
column
If the pair of letters are identical
Plaintext ME RC HA NT TA YL OR SZ SC HO OL
ME OR
Cipher SC OF LM BI SB AR PU BX ME OV RH
Text ME PU
Substitution
Playfairs
cipher
If the pair of letters are in different rows
and columns
If the pair of letters are in the same row
If the pair of letters are in the same
column
If the pair of letters are identical
Plaintext ME RC HA NT TA YL OR SZ SC HO OL
ME OR HO
Cipher SC OF LM BI SB AR PU BX ME OV RH
Text ME PU
Substitution
Playfairs
cipher
If the pair of letters are in different rows
and columns
If the pair of letters are in the same row
If the pair of letters are in the same
column
If the pair of letters are identical
Plaintext ME RC HA NT TA YL OR SZ SC HO OL
ME OR HO
Cipher SC OF LM BI SB AR PU BX ME OV RH
Text ME PU OV
Substitution
The Polybius Square
1 2 3 4 5 ▪It is also knows as Polybius Check board.
1 A B C D E ▪Originally was used for Greek letters.
▪ Each letter is represented by
2 F G H IJ K
coordinated.
3 L M N O P ▪Polybius conceived this device as an aid
4 Q R S T U
5 V W X Y Z to Telegraphy.
Plaintext : n o w i s t h e t i m e
3 4 2 4 3 4 3 5 4 4 2 5
Cipher text:
3 3 5 2 4 4 2 1 4 2 6 1
Substitution
Hill cipher
• The encryption takes n successive plaintext letters and
substitutes for them n ciphertext letters determined by n
linear equations. (Mathematician Lester Hill in 1929)
• n-gram substitution may be defined using an invertible n x n
matrix A = aij as the key to map an n-character plaintext
m1m2…. mn to a ciphertext n-gram
• expressed in terms of column vectors and matrices:
• Encryption C = EK(X) = KX mod 26
• Decryption X = DK(C) = K-1C mod 26
Substitution
Hill cipher - Example
• Encrypt “Meet B” using a 2 X 2 Hill Cipher
• with the keys k = and decryption key k-1 =
• c1 = (k11x1 + k12x2) mod 26
• c2 = (k21x1 + k22x2) mod 26
• Plain text : me et bx (x added to complete last (pair) diagram)
• Numerical equivalent = 12 4 4 19 1 23, read as pairs x 1x2,
x3 x4 , x5 x6 .
• c1 = (36 + 4) mod 26 = 14 (O), c2 = (60 + 8) mod 26 = 16 (Q)
• Encrypted as 🡪 oq fg az
Substitution
Hill Cipher Example (Decryption)
• Decryption key K-1 =
• Decryption X = DK(C) = K-1C mod 26
• x1 = (k11c1 + k12c2) mod 26
• x2 = (k21c1 + k22c2) mod 26
• oq fg az <14, 16><5,6><0,25>
• x1 = (28 – 16) mod 26 = 12 = m
• x2 = (-70 + 48) mod 26 = -22 = 4 = e
• me et bx
Substitution
Poly-alphabetic substitutions
• Vigenere Cipher:
• The letters of the plain text alphabet are mapped
into letters of cipher text space depending on their
position in the text
• Under different alphabets, the same plaintext
character is thus encrypted to different ciphertext
characters, precluding simple frequency analysis of
mono-alphabetic substitution
• Key is taken from some known text (with
corresponding character value (0 to 25)) defining
the shifting of underlying m.
• The mapping of plaintext m = m1 m2 m3 … to
ciphertext c = c1 c2 c3 … is defined on individual
characters by ci = (mi + ki) mod 26, where
subscript i in ki is taken modulo t (the key is re-
used). Let length of key is l then repeat same key
Substitution
Vigenere Cipher
Let Key={21,4,2,19,14,17}
Plaint H E R E I S H O w
ext
Key 21 4 2 19 14 17 21 4 2
Cipher C I T X W J C S Y
Finding key length:
Write ciphertext on a long strip and same ciphertext on second
strip.
Put one strip on another by displacement 1 then 2 then 3 etc.
Find out max coincidence of letters (mapping) for a particular
displacement.
Substitution
Affine Ciphers
An encipherment scheme (or algorithm) of the form
E(x) ≡(ax + b) MOD 26
is called an affine cipher. Here x is the numerical equivalent of the given
plaintext letter, and a and b are (appropriately chosen) integers.
Thank You
[email protected]