Lecture 2 - Classical Ciphers
Lecture 2 - Classical Ciphers
Alshaimaa Abo-alian
Classical Encryption Techniques [email protected]
Lecture Outline
➢ Symmetric Encryption Model
➢ Substitution Techniques
1. Caesar Cipher
2. Monoalphabetic (Homophonic) Ciphers
3. The Hill Algorithm
4. Polyalphabetic Ciphers
a) Vigenère Cipher
b) Vernam cipher/one-time pad
➢ Transposition Techniques
1. Rail Fence Cipher
2. Row Transposition Cipher
➢ Product Cipher
2
Encryption Algorithms
Encryption algorithms are characterized along 3 dimensions:
• The type of operations used for transforming plaintext to ciphertext
– Substitution – Transposition
– Product systems (multiple stages of substitutions and
transpositions)
• The number of keys used
– Single-key (Symmetric, secret-key, or conventional encryption)
– Two-key (Asymmetric, or public-key encryption)
• The way in which the plaintext is processed
– Block cipher – Stream cipher
3
Symmetric Encryption Model
4
Symmetric Encryption
Terminologies
▪ Plaintext (m): An original message
▪ Ciphertext (c): The coded message
▪ Enciphering/encryption (E): The process of converting
from plaintext to ciphertext.
▪ Deciphering/decryption (D): Restoring the plaintext from
the ciphertext
▪ Secret key (k): is also input to the encryption/decryption
algorithm. The key is a value independent of the
plaintext and of the algorithm.
5
Symmetric Encryption
Scheme
• A symmetric encryption scheme is defined by a
message space M and algorithms (Gen, E, D):
– Gen (key-generation algorithm): outputs kK
– E (encryption algorithm): takes key k and
message mM as input; outputs ciphertext c
c E (k, m)
– Dec (decryption algorithm): takes key k and
ciphertext c as input; outputs m
m D (k, c)
11
Brute-force Attack
of Shift Cipher
This observation is known as the
sufficient key-space principle:
12
Substitution Techniques
Monoalphabetic (Homophonic)
Ciphers
▪ In the shift cipher, the key defines a fixed shift.
▪ In the mono-alphabetic substitution cipher, the key also defines
a map on the alphabet, but the map is now arbitrary.
▪ The key space consists of all bijections of the alphabet.
▪ Example:
13
Substitution Techniques
Monoalphabetic (Homophonic)
Ciphers
If the cipher can be any permutation of the 26 alphabetic
characters, then there are 26! or approximately 288 possible
keys
▪ A brute-force attack is infeasible.
▪ However, this does not mean the cipher is secure!
15
Cryptanalysis Example
Letter Frequency Analysis
Given ciphertext
uzqsovuohxmopvgpozpevsgzwszopfpesxudbmetsxaizv
uephzhzshzowsfpappdtsvpquzwymxuzuhsxepyepopdzs
zufpombzwpfupzhmdjudtmohmq
Frequency Analysis
Ciphertext length= 120 P 13.33 H 5.83 F 3.33 B 1.67 C 0.00
M 6.67
16
Cryptanalysis Example
Letter Frequency Analysis
– Determine the frequency of every ciphertext letter and compare
it to the standard table of letter frequencies of English language.
– The frequency distribution will be close to that of the given
language in general
– We can also look at digrams (pairs) or trigram (triples ) of letters
– For example, the letter Q is almost always followed by a U. we
detect frequent short words such as THE, AND, etc.
– Continuing with trial and error, we finally get the following
plaintext
It was disclosed yesterday that several informal
but direct contacts have been made with
political representatives of the Viet Cong in
Moscow 17
Frequency of Common Digrams in
English
18
Playfair Cipher
– Best-known multiple-letter encryption cipher
– Invented by British scientist Sir Charles Wheatstone in 1854
– it encrypts pairs of letters (digrams) instead of single letters.
– It uses a 5×5 matrix of letters based on a keyword.
– Initialization:
o Create 5x5 matrix and write keyword (row by row; ignoring duplicates)
o Fill out remainder with alphabet, not repeating any letters
o Treat I and J as same letter
19
Playfair Cipher
– Preparing Plaintext:
o Split the text into letter pairs (digrams).
o If a pair contains duplicate letters (e.g., "LL"), insert an X between
them (e.g., "LXL").
o If there's an odd number of letters, add X at the end.
– Encryption
o Plaintext in same row: Replace each letter with the next letter to the
right (wrap around if needed)
o Plaintext in same column: Replace each letter with the letter below it
(wrap around if needed)
o Else, replace by letter in same row as it and same column as other
plaintext letter 20
Playfair Cipher - Example
T H A I/J L
– Plaintext: hello
N D B C E
– Keyword: thailand F G K M O
– Initialization ➔ P Q R S U
– Preparing Plaintext: V W X Y Z
HE LX LO
– Encryption:
HE ➔ LD
LX ➔ AZ
LO ➔ EU
✓Ciphertext: LDAZEU 21
Substitution Techniques
The Hill Algorithm
▪ Developed by the mathematician Lester Hill in 1929
▪ Its strength is that it completely hides single-letter frequencies
✓ The use of a larger matrix hides more frequency information
✓ A 3 x 3 Hill cipher hides not only single-letter but also two-
letter frequency information
▪ It takes successive m plaintext letters and substitutes for them m
ciphertext letters.
▪ The substitution is determined by linear equations in which each
character is assigned a numerical value (a=0, b=1, …, z=25)
22
Substitution Techniques
The Hill Algorithm
For m= 3, this can be expressed in terms of row vectors and
matrices
𝑘11 𝑘12 𝑘13 𝑝1
(𝑐1 𝑐2 𝑐3 ) = 𝑘21 𝑘22 𝑘23 × 𝑝2 𝑚𝑜𝑑 26
𝑘31 𝑘32 𝑘33 𝑝3
23
Hill Cipher Example
24
Hill Cipher Example
Continue with other di-grams
12 14 16 13 18 24 2 1 18 6
M O Q N S Y C B S G
For the plaintext “ Good Course”
The encrypted message is “MOQN SYCBSG”
25
Substitution Techniques
Polyalphabetic Ciphers
▪ The mono-alphabetic substitution cipher can be
statistically attacked because the key defines a fixed
mapping that is applied letter-by-letter to the plaintext.
▪ A Polyalphabetic Cipher uses different monoalphabetic
substitutions as one proceeds through the plaintext message
▪ Examples:
o Vigenère cipher
o Vernam cipher
o One time pad
26
Vigenère Cipher
27
Vigenère Cipher
28
Vigenère Cipher- Example
Encrypt the message “we are discovered” using Vigenère Cipher
with the keyword = deceptive
P w e a r e d i s c o v e r e d
PI 22 4 0 17 4 3 8 18 2 14 21 4 17 4 3
K d e c e p t i v e d e c e p t
KI 3 4 2 4 15 19 8 21 4 3 4 2 4 15 19
CI 25 8 2 21 19 22 16 13 6 17 25 6 21 19 22
C Z I C V T W Q N G R Z G V T W
31
Vernam Cipher
32
One-Time Pad
33
One-Time Pad - Difficulties
35
Rail Fence Cipher
36
Rail Fence Cipher
37
Row Transposition Cipher
▪ Write the message in a rectangle, row by row, and read the
message off, column by column, but permute the order of the
columns
–The order of the columns then becomes the key to the algorithm
– Example: To encrypt the message “attack postponed until two
am” with key = 4312567.
38
Transposition Techniques
Are They Secure?
39
Product Cipher
42
PRODUCT CIPHER
Confusion & Diffusion Concept
43
Thank you
45