Lecture 3.3
Lecture 3.3
(Module-3.B)
Course Code: 20B12CS332
• Substitution:
– A substitution cipher replaces one symbol with
another. Substitution ciphers can be categorized
as either monoalphabetic ciphers or
polyalphabetic ciphers.
• Transposition:
– A transposition cipher does not substitute one
symbol for another, instead it changes the
location of the symbols.
Substitution Cipher
The following shows a plaintext and its corresponding
ciphertext. The cipher is probably monoalphabetic because both
l’s (els) are encrypted as O’s.
7
Caesar Cipher
• Mathematically, map letters to numbers:
a, b, c, ..., x, y, z
0, 1, 2, ..., 23, 24, 25
• The general Caesar cipher is:
c = EK(p) = (p + k) mod 26
p = DK(c) = (c – k) mod 26
• Can be generalized with any alphabet.
8
Cryptanalysis of Caesar Cipher
• Key space is very small: {0, 1, ..., 25}
• Vulnerable to brute-force attacks.
• Exhaustive search
– If the key space is small enough, try all possible keys until you
find the right one
– Caesar cipher has 26 possible keys
– Statistical frequencies not concealed well
• They look too much like regular English letters
• Statistical Attack
– Compute frequency of each letter in cipher text
– Apply 1-gram model of English, which presents the frequency of
letters in the English
– Using statistical analysis, the correlation between the two is
calculated to find the probable key. 9
Monoalphabetic Substitution Cipher
• Shuffle the letters and map each plaintext letter to a
different random ciphertext letter:
Plain letters: abcdefghijklmnopqrstuvwxyz
Cipher letters: DKVQFIBJWPESCXHTMYAUOLRGZN
Plaintext: ifwewishtoreplaceletters
Ciphertext: WIRFRWAJUHYFTSDVFSFUUFYA
10
Monoalphabetic Cipher Security
• Now we have a total of 26! = 4 x 1026 keys.
• With so many keys, it is secure against
brute-force attacks.
• But not secure against some cryptanalytic
attacks.
• Problem is language characteristics.
11
Language Statistics and Cryptanalysis
• Human languages are not random.
• Letters are not equally frequently used.
• In English, E is by far the most common letter, followed
by T, R, N, I, O, A, S.
• Other letters like Z, J, K, Q, X are fairly rare.
• There are tables of single, double & triple letter
frequencies for various languages
• In decreasing order of frequency
Double letters:
th he an in er re es on, …
Triple letters:
the and ent ion tio for nde, …
12
English Letter Frequencies
13
Use in Cryptanalysis
• Key concept: monoalphabetic substitution does not
change relative letter frequencies
• To attack,
• calculate letter frequencies for ciphertext
compare this distribution against the known one
14
Example Cryptanalysis
• Given ciphertext:
UZQSOVUOHXMOPVGPOZPEVSGZWSZOPFPESXUDBMETSXAIZ
VUEPHZHMDZSHZOWSFPAPPDTSVPQUZWYMXUZUHSX
EPYEPOPDZSZUFPOMBZWPFUPZHMDJUDTMOHMQ
• Count relative letter frequencies ( next slide)
• Guess {P, Z} = {e, t}
• Of double letters, ZW has highest frequency, so
guess ZW = th and hence ZWP = the
• Proceeding with trial and error finally get:
it was disclosed yesterday that several informal but
direct contacts have been made with political
representatives of the viet cong in moscow
15
Letter frequencies in ciphertext
P 13.33 H 5.83 F 3.33 B 1.67 C 0.00
Z 11.67 D 5.00 W 3.33 G 1.67 K 0.00
S 8.33 E 5.00 Q 2.50 Y 1.67 L 0.00
U 8.33 V 4.17 T 2.50 I 0.83 N 0.00
O 7.50 X 4.17 A 1.67 J 0.83 R 0.00
M 6.67
16
Playfair Cipher
• Not even the large number of keys in a
•
monoalphabetic cipher provides security.
• One approach to improving security is to
encrypt multiple letters at a time.
• The Playfair Cipher is the best known such
cipher.
• Invented by Charles Wheatstone in 1854, but
named after his friend Baron Playfair.
17
Playfair Key Matrix
• Use a 5 x 5 matrix.
• Fill in letters of the key (w/o duplicates).
• Fill the rest of matrix with other letters.
• E.g., key = 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
18
Encrypting and Decrypting
19
Security of Playfair Cipher
• Equivalent to a monoalphabetic cipher with an
alphabet of 26 x 26 = 676 characters.
• Security is much improved over the simple
monoalphabetic cipher.
20
Polyalphabetic Substitution Ciphers
• A sequence of monoalphabetic ciphers (M1, M2, M3,
..., Mk) is used in turn to encrypt letters.
• A key determines which sequence of ciphers to use.
• Each plaintext letter has multiple corresponding
ciphertext letters.
• This makes cryptanalysis harder since the letter
frequency distribution will be flatter.
21
Vigenère Cipher
• Simplest polyalphabetic substitution cipher
• Consider the set of all Caesar ciphers:
{ Ca, Cb, Cc, ..., Cz }
• Key: e.g. security
• Encrypt each letter using Cs, Ce, Cc, Cu, Cr, Ci, Ct,
Cy in turn.
• Repeat from start after Cy.
• Decryption simply works in reverse.
22
Vigènere Cipher
• Example
– Message THE BOY HAS THE BALL
– Key VIG
– Encipher using Caesar cipher for each letter:
key VIGVIGVIGVIGVIGV
plain THEBOYHASTHEBALL
cipher OPKWWECIYOPKWIRG
23
Tableau
Key phrase characters select
column
• | 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
•-------------------------------------------------------
•A | 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
•B | 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 a
•C | c d e f g h i j k l m n o p q r s t u v w x y z a b
•D | d e f g h i j k l m n o p q r s t u v w x y z a b c
•E | e f g h i j k l m n o p q r s t u v w x y z a b c d
•…
•Q | q r s t u v w x y z a b c d e f g h i j k l m n o p
Plaintex •R | r s t u v w x y z a b c d e f g h i j k l m n o p q
•S | s t u v w x y z a b c d e f g h i j k l m n o p q r
characters •T | t u v w x y z a b c d e f g h i j k l m n o p q r s
select row •U | u v w x y z a b c d e f g h i j k l m n o p q r s t
•V | v w x y z a b c d e f g h i j k l m n o p q r s t u
•W | w 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
•X | 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
•Y | 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 x
•Z | z 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
24
Relevant Parts of Tableau for example
• Only need columns for V, I, G
• Only characters in “THE BOY HAS THE
• V I G BALL” : A,B,
– E,H,L,O,S,T,Y
• A V I G
• B W J H • Example encipherments :
• E Z M L – Encode first plaintext letter T with key
character K : follow V column down to T
• H C P N row (giving “O”)
• L G T R – Encode second plaintext letter H using key
character I: follow I column down to H row
• O J W U (giving “P”)
• S N A Y
• T O B Z
• Y T H E
25
Example of Vigenère Cipher
• Keyword: deceptive
key: deceptivedeceptivedeceptive
plaintext: wearediscoveredsaveyourself
ciphertext: ZICVTWQNGRZGVTWAVZHCQYGLMGJ
26
Useful Terms
• period: length of key
– In earlier example, period is 3
• tableau: table used to encipher and
decipher
– Vigènere cipher has key letters on top,
plaintext letters on the left
• polyalphabetic: the key has several
different letters
– Cæsar cipher is monoalphabetic
27
Security of Vigenère Ciphers
• There are multiple (how many?) ciphertext letters
corresponding to each plaintext letter.
• So, letter frequencies are obscured but not totally lost.
• To break Vigenere cipher:
1. Try to guess the key length. How?
2. If key length is N, the cipher consists of N Caesar ciphers.
Plaintext letters at positions k, N+k, 2N+k, 3N+k, etc., are
encoded by the same cipher.
3. Attack each individual cipher as before.
28
One Time Pad(OTP)
Extends Vigenère cipher so that the key is as
long as the plaintext
– No repeat, cannot be broken by finding key
length
+ frequency analysis
• Key is a random string that is at least as long
as the plaintext
• Encryption is similar to Vigenère
29
Let Zm ={0,1,…,m-1} be
the alphabet.
Plaintext space = Ciphtertext space = Key space
= (Zm)n
The key is chosen uniformly randomly
Plaintext X = (x1 x2 … xn)
Key K = (k1 k2 … kn)
Ciphertext Y = (y1 y2 … yn)
ek(X) = (x1+k1 x2+k2 … xn+kn) mod m
dk(Y) = (y1-k1 y2-k2 … yn-kn) mod m
30
Key Randomness in One-Time Pad
• One-Time Pad uses a very long key, what if the
key is not chosen randomly, instead, texts from,
e.g., a book is used
. – this is not One-Time Pad anymore
– this does not have perfect secrecy
– this can be broken •
• The key in One-Time Pad should never be
reused.
– If it is reused, it is Two-Time Pad, and is
insecure! 31
The Binary Version of One-Time Pad
Plaintext space = Ciphtertext space =
Keyspace = {0,1}n
Key is chosen randomly
For example:
• Plaintext is 11011011
• Key is 01101001
• Then ciphertext is 10110010
32
Bit Operators
• Bit AND
0∧0=0 0∧1=0 1∧0=0 1∧1=1
• Bit OR
0∨0=0 0∨1=1 1∨0=1 1∨1=1
• Can we use operators other than Bit XOR for binary version of
One-Time Pad?
33
How Good is One-Time Pad?
• Intuitively, it is secure …
– The key is random, so the ciphertext is completely
random
– Perfect secrecy ⇒ key-length ≥ msg-length
– Difficult to use in practice
34
Transposition Ciphers
• Also called permutation ciphers.
• Shuffle the plaintext, without altering the
actual letters used.
• Easy to crack as the frequency of letters in the
cipher is same as in plain text
Row Transposition Ciphers
Column Transposition Ciphers
35
Transposition Ciphers
• Also called permutation ciphers.
• Shuffle the plaintext, without altering the
actual letters used.
• Easy to crack as the frequency of letters in the
cipher is same as in plain text
Row Transposition Ciphers
Column Transposition Ciphers
36
Transposition Cipher
Alice and Bob can agree on the number of columns and use the
second method. Alice writes the same plaintext, row by row, in a
table of four columns.
Plain Text: meet me at the park
38
Row Transposition Ciphers
Rail Fence Cipher
Plain text is written downwards on “rails of fence “ , starting a new
column when bottom is reached.
To create cipher
• First write down plain text message as a sequence of diagonals.
• Read the plain text written in first step as a sequence of row
Example:
Plain text: come home tomorrow
Cipher text: cmhmtmrooeoeoorw
39
To decipher a rail fence cipher:
1. Divide the ciphertext in half
2. Reverse the order of the steps of
encipherment, that is, write the ciphertext
in two rows
1. Read off the plaintext in a zig-zag order
40
Product Ciphers
• Ciphers using substitutions or transpositions are not
secure because of language characteristics
• Product Cipher use a sequence of substitutions and
transpositions
– Harder to break than just substitutions or transpositions
– two substitutions make a more complex substitution
– two transpositions make more complex transposition
– but a substitution followed by a transposition makes a new
much harder cipher
• This is bridge from classical to modern ciphers
41
Cryptanalysis Attack
Stream Cipher
BlockBlock
Cipher
Cipher
Pros and Cons
Cryptography Types
Symmetric Key Cryptography
Asymmetric Key Cryptography
Symmetric Vs Asymmetric Cryptography
Symmetric vs Asymmetric cryptosystems
• Symmetric system provides authenticity, proof that a message received was not
fabricated by someone other than the declared sender provided the key the is not
disclosed.
Issues :
• How do two users A and B obtain their shared secret key and that only A and B can
use that key for their encrypted communications.
• Managing keys: If n users who want to communicate in pairs need
n * (n – 1)/2 keys.
• The number of keys needed increases at a rate proportional to the square of the
number of users.
• Require a means of key distribution system.
• Asymmetric systems, have precisely matched pairs of keys.
• The keys are produced together or one is derived mathematically from the other.
Both the keys are computed as a set.
• Asymmetric systems public key can be sent in an email message or post it in a
public directory. Only the corresponding private key, which presumably is not
disclosed, can decrypt what has been encrypted with the public key.
Confusion and Diffusion
• Terms courtesy of Claude Shannon, father of
Information Theory
• Confusion obscures the relationship between the
plaintext and ciphertext,
• Diffusion spreads the plaintext statistics through the
ciphertext.
• A one-time pad relies entirely on confusion while a
simple substitution cipher is another (weak) example of
a confusion-only cryptosystem.
• A double transposition is the classic example of a
diffusion-only cryptosystem.
Confusion Vs Diffusion
Steganograpghy
• Steganography comes from the Greek steganos , meaning
covered or secret, and graphy , meaning writing or drawing.
• Steganography literally means covered writing.
• Steganography simply takes one piece of information and
hides it within another
• Computer files (images, sounds recordings, even disks)
contain unused or insignificant areas of data
• Steganography takes advantage of these areas, replacing
them with information (encrypted mail, for instance).
• The files can then be exchanged without anyone knowing
what really lies inside of them
• For example, An image of the space shuttle landing might
contain a private letter to a friend.
Steganography Principles