You are on page 1of 66

Cryptography and

Network Security
Chapter 2
Fourth Edition
by William Stallings

Chapter 2 Classical Encryption


Techniques

CRYPTOLOGY
Definition:
Cryptology : from the Greek
Crypto meaning secret or hidden, and
ology meaning theory, or science

Two major divisions:


Cryptography & Cryptanalysis

Symmetric Encryption
or conventional /

private-key / single-key
sender and recipient share a common key
all classical encryption algorithms are
private-key
was only type prior to invention of publickey in 1970s
and by far most widely used

Some Basic Terminology

plaintext - original message


ciphertext or cryptogram - coded message (The
(
transformed message).
cipher - algorithm for transforming plaintext to ciphertext
key or cryptovariable The information used in
conjunction with the algorithm to create ciphertext from
plaintext
encipher (encrypt) - converting plaintext to ciphertext
decipher (decrypt) - recovering ciphertext from plaintext
cryptography - study of encryption principles/methods
cryptanalysis (codebreaking) - study of principles/
methods of deciphering ciphertext without knowing key
cryptology - field of both cryptography and cryptanalysis

Symmetric Cipher Model

Requirements
two requirements for secure use

of
(conventional) symmetric encryption:

a strong encryption algorithm


a secret key known only to sender / receiver

mathematically have:

C = EK(P)
P = DK(C)
assume encryption algorithm

is known
implies a secure channel to distribute key

Cryptography

characterize cryptographic system by:

1- The type of operations used for transforming plaintext to ciphertext:- there


are two general principles ..
- Substitution, in which each element in the plaintext is mapped into
another element.
- Transposition, in which elements in the plaintext are rearranged.
- Product: involve multiple stages of substitutions and transpositions
2- The number of keys used:- Secret -key (symmetric-key or single-key), where both sender and receiver
use the same key.
- Public-key (asymmetric or two-key), where both sender and receiver each
uses different key.
3- The way in which the plaintext is processed:- Block Cipher.
- Stream Cipher

Cryptanalysis
objective to recover key not just message
general approaches:

cryptanalytic attack
brute-force attack

Cryptanalytic Attacks
ciphertext only

only know algorithm & ciphertext, is statistical,


know or can identify plaintext

known plaintext

know/suspect plaintext & ciphertext

chosen plaintext

select plaintext and obtain ciphertext

chosen ciphertext

select ciphertext and obtain plaintext

chosen text

select plaintext or ciphertext to en/decrypt

More Definitions

unconditional security

if the ciphertext generated by the scheme does not contain enough


information to determine uniquely the corresponding plaintext

no matter how much computer power or time is


available, the cipher cannot be broken since the
ciphertext provides insufficient information to uniquely
determine the corresponding plaintext

computational security

given limited computing resources (eg time needed


for calculations is greater than age of universe), the
cipher cannot be broken

Brute Force Search


always possible to simply try every key
most basic attack, proportional to key size
assume either know / recognise plaintext

KeySize(bits)

NumberofAlternative
Keys

Timerequiredat1
decryption/s

Timerequiredat106
decryptions/s

32

232=4.3109

231s

=35.8minutes

2.15milliseconds

56

256=7.21016

255s

=1142years

10.01hours

128

2128=3.41038

2127s

=5.41024years

5.41018years

168

2168=3.71050

2167s

=5.91036years

5.91030years

26!=41026

21026s =6.41012years

6.4106years

26characters
(permutation)

Classical Substitution
Ciphers
where

letters of plaintext are replaced by


other letters or by numbers or symbols
or if plaintext is viewed as a sequence of
bits, then substitution involves replacing
plaintext bit patterns with ciphertext bit
patterns

Types of Ciphers

A Simple Substitution cipher, or Monoalphabetic cipher, is one in which each


character in the plain text is replaced with a corresponding character of cipher-text.

A Homophonic substitution cipher is like a simple substitution crypto-system,


except that a single character of plaintext can map to one of several characters of
ciphertext. For Example, A could correspond to 5, 14 and 147.

A Polygram substitution cipher is one which blocks of characters are encrypted in


groups. For Example, ABA could correspond to RTQ.

The Playfair cipher is an example of this type of cipher and was used by the British in World
War One.

A Polyalphabetic substitution cipher is made up of multiple Monoalphabetic


ciphers. The particular cipher used changes with the position of each character in the
plain text. For Example Vigenere cipher.

Caesar Cipher
earliest known substitution cipher
by Julius Caesar
first attested use in military affairs
replaces each letter by 3rd letter on

example:
meetmeafterthetogaparty
PHHWPHDIWHUWKHWRJDSDUWB

Caesar Cipher
can define transformation as:
abcdefghijklmnopqrstuvwxyz
DEFGHIJKLMNOPQRSTUVWXYZABC

mathematically give each letter a number


abcdefghijklmnopqrstuvwxyz
012345678910111213141516171819202122232425

then have Caesar cipher as:

c = E(p) = (p + k) mod (26)


p = D(c) = (c k) mod (26)

Cryptanalysis of Caesar
Cipher
only have 26 possible ciphers

A maps to A,B,..Z

could simply try each in turn a

brute force

search
given ciphertext, just try all shifts of letters
do need to recognize when have plaintext
eg. break ciphertext "GCUA VQ DTGCM"

Brute-force cryptanalysis is easily


performed with Caesar Cipher :
The encryption and decryption algorithms

are known
There are only 25 keys to try (25 different
k values)
The language of plaintext is known and
easily recognizable

Monoalphabetic Cipher

rather than just shifting the alphabet


could shuffle (jumble) the letters arbitrarily
each plaintext letter maps to a different random
ciphertext letter
hence key is 26 letters long
Plain:abcdefghijklmnopqrstuvwxyz
Cipher:DKVQFIBJWPESCXHTMYAUOLRGZN
Plaintext:ifwewishtoreplaceletters
Ciphertext:WIRFRWAJUHYFTSDVFSFUUFYA

Monoalphabetic Cipher
Security
now have a total of 26! = 4 x 1026 keys
with so many keys, might think is secure
but would be

!!!WRONG!!!
problem is language characteristics

Language Redundancy and


Cryptanalysis

human languages are redundant


eg "th lrd s m shphrd shll nt wnt"
letters are not equally commonly 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


have tables of single, double & triple letter
frequencies for various languages

English Letter Frequencies

Use in Cryptanalysis

key concept - monoalphabetic substitution


ciphers do not change relative letter frequencies
discovered by Arabian scientists in 9th century
calculate letter frequencies for ciphertext
compare counts/plots against known values
if caesar cipher look for common peaks/troughs

peaks at: A-E-I triple, NO pair, RST triple


troughs at: JK, X-Z

for monoalphabetic must identify each letter

tables of common double/triple letters help

Example Cryptanalysis

given ciphertext:
UZQSOVUOHXMOPVGPOZPEVSGZWSZOPFPESXUDBMETSXAIZ
VUEPHZHMDZSHZOWSFPAPPDTSVPQUZWYMXUZUHSX
EPYEPOPDZSZUFPOMBZWPFUPZHMDJUDTMOHMQ

count relative letter frequencies (see text)


guess P & Z are e and t
guess ZW is th and hence ZWP is 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

Playfair Cipher
not even the large number of keys in a

monoalphabetic cipher provides security


one approach to improving security was to
encrypt multiple letters
the Playfair Cipher is an example
invented by Charles Wheatstone in 1854,
but named after his friend Baron Playfair

Playfair Key Matrix


a 5X5 matrix of letters based on a keyword
fill in letters of keyword (sans duplicates)
fill rest of matrix with other letters
eg. using the keyword MONARCHY
M

I/J

Encrypting and Decrypting

plaintext is encrypted two letters at a time


1.
2.

3.

4.

if a pair is a repeated letter, insert filler like 'X


if both letters fall in the same row, replace
each with letter to right (wrapping back to start
from end)
if both letters fall in the same column, replace
each with the letter below it (again wrapping to
top from bottom)
otherwise each letter is replaced by the letter
in the same row and in the column of the other
letter of the pair

Playfair Example
Use the following table:
C
E
G
O
V

H
S
I/J
P
W

A
B
K
Q
X

R
D
M
T
Y

L
F
N
U
Z

Encrypting the message:


THE SCHEME REALLY WORKS

Playfair Example

Break the plaintext in a two character


diagram:

Plaintext is divided into 2-letter diagram


Use X to separate double letter
Use X to pad the last single letter

TH ES CH EM ER EA LX LY WO RK SX

Cont. Playfair Example

TH -> PR
ES -> SB
CH -> HA
EM -> DG
ER -> DC
EA -> BC
LX -> AZ
LY -> RZ
WO -> VP
RK -> AM
SX -> BW

C
E
G
O
V

H
S
I/J
P
W

A
B
K
Q
X

R
D
M
T
Y

L
F
N
U
Z

Cont. Playfair Example

Thus the message:


" THE SCHEME REALLY WORKS
WORKS
Becomes
"PR SB HA DG DC BC AX RZ VP AM BW

Security of Playfair Cipher

security much improved over monoalphabetic


since have 26 x 26 = 676 digrams
would need a 676 entry frequency table to
analyse (verses 26 for a monoalphabetic)
and correspondingly more ciphertext
was widely used for many years

eg. by US & British military in WW1

it can be broken, given a few hundred letters


since still has much of plaintext structure

Hill Cipher
The Hill Cipher uses matrix

multiplication to encrypt a message.


First, you need to assign two numbers
to each letter in the alphabet and also
assign numbers to space, . , and ? or !.
The key space is the set of all invertible
matrices over Z26. 26 was chosen
because there are 26 characters, which
solves some problems later on.

Hill Cipher example


Encryption:
Use the table and 00 for spaces:
A B C D E F G H I J K L M N O P Q R S
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
T U VW X Y Z
20 21 22 23 24 25 26
Consider the following message:
Herbert Yardley wrote The American Black Chamber

Hill Cipher example


Break the message into:
he rb er ty ar dl ey wr ot et he am er ic an bl ac kc
ha mb er
Now convert letters into number-pair:
8 5 18 2 5 18 20 25 1 18 4 12 5 25 23 18 15 20
5 20 8 5 1 13 5 18 9 3 1 14 2 12 1 3
11 3 8 1 13 2 5 18
03 07
Now using the matrix (key)

05
12

Hill Cipher example


Make the first pair a column vector (h (8) e (5)),
and multiply that matrix by the key.
3 7 8
59

5 12 5
100

Of course, we need our result to be mod 26


59
100

7
22 mod 26

The ciphertext is G (7) V (22).

Hill Cipher example


For the next pair r (18) b (2),
3 7 18
5 12 2

16

mod 26
10

and 16 corresponds to P and 10 corresponds to J.

Do this for every pair and obtain


GVPJKGAJYMRHHMMSCCYEGVPEKGVCWQLXXOBMEZAKKG

Hill Cipher Decryption:

Polyalphabetic Ciphers

polyalphabetic substitution ciphers


improve security using multiple cipher alphabets
make cryptanalysis harder with more alphabets
to guess and flatter frequency distribution
use a key to select which alphabet is used for
each letter of the message
use each alphabet in turn
repeat from start after end of key is reached

Vigenre Cipher
simplest polyalphabetic substitution cipher
effectively multiple caesar ciphers
key is multiple letters long K = k 1

k2 ... kd
ith letter specifies ith alphabet to use
use each alphabet in turn
repeat from start after d letters in message
decryption simply works in reverse

Example of Vigenre Cipher


write the plaintext out
write the keyword repeated above it
use each key letter as a caesar cipher key
encrypt the corresponding plaintext letter
Plaintext
Keyword
Ciphertext

THISPROCESSCANALSOBEEXPRESSED
CIPHERCIPHERCIPHERCIPHERCIPHE
VPXZTIQKTZWTCVPSWFDMTETIGAHLH

based on a Vigenre Table shown next

Vigenre Cipher
ABCDEFGHIJKLMNOPQRSTUVWXYZ
A ABCDEFGHIJKLMNOPQRSTUVWXYZ
B BCDEFGHIJKLMNOPQRSTUVWXYZA
C CDEFGHIJKLMNOPQRSTUVWXYZAB
D DEFGHIJKLMNOPQRSTUVWXYZABC
E EFGHIJKLMNOPQRSTUVWXYZABCD
F FGHIJKLMNOPQRSTUVWXYZABCDE
G GHIJKLMNOPQRSTUVWXYZABCDEF
H HIJKLMNOPQRSTUVWXYZABCDEFG
I IJKLMNOPQRSTUVWXYZABCDEFGH
J JKLMNOPQRSTUVWXYZABCDEFGHI
K KLMNOPQRSTUVWXYZABCDEFGHIJ
L LMNOPQRSTUVWXYZABCDEFGHIJK
M MNOPQRSTUVWXYZABCDEFGHIJKL
N NOPQRSTUVWXYZABCDEFGHIJKLM
O OPQRSTUVWXYZABCDEFGHIJKLMN
P PQRSTUVWXYZABCDEFGHIJKLMNO
Q QRSTUVWXYZABCDEFGHIJKLMNOP
R RSTUVWXYZABCDEFGHIJKLMNOPQ
S STUVWXYZABCDEFGHIJKLMNOPQR
T TUVWXYZABCDEFGHIJKLMNOPQRS
U UVWXYZABCDEFGHIJKLMNOPQRST
V VWXYZABCDEFGHIJKLMNOPQRSTU
W WXYZABCDEFGHIJKLMNOPQRSTUV
X XYZABCDEFGHIJKLMNOPQRSTUVW
Y YZABCDEFGHIJKLMNOPQRSTUVWX
Z ZABCDEFGHIJKLMNOPQRSTUVWXY

Vigenre Cipher
By using math. Equation:

C= E(p) = (p+ki) mod (26)


Plaintext
Keyword
Ciphertext

THISPROCESSCANALSOBEEXPRESSED
CIPHERCIPHERCIPHERCIPHERCIPHE
VPXZTIQKTZWTCVPSWFDMTETIGAHLH

Security of Vigenre Ciphers


have multiple ciphertext letters for each

plaintext letter
hence letter frequencies are obscured
but not totally lost
start with letter frequencies

see if look monoalphabetic or not

if not, then need to determine number of

alphabets, since then can attach each

Kasiski Method

method developed by Babbage / Kasiski


repetitions in ciphertext give clues to period
so find same plaintext an exact period apart
which results in the same ciphertext
of course, could also be random fluke
eg repeated VTW in previous example
suggests size of 3 or 9
then attack each monoalphabetic cipher
individually using same techniques as before

Autokey Cipher

ideally want a key as long as the message


Vigenre proposed the autokey cipher
with keyword is prefixed to message as key
knowing keyword can recover the first few letters
use these in turn on the rest of the message
but still have frequency characteristics to attack
eg. given key deceptive
key:deceptivewearediscoveredsav
plaintext:wearediscoveredsaveyourself
ciphertext:ZICVTWQNGKZEIIGASXSTSLVVWLA

Another Classical Substitution Ciphers


Keyword mixed
Example:

keyword= AHMAD becomes AHMD


K= 3
AB C D E F G H I J K LM N O PQ R ST UVWXYZ
XYZA HMDBCE FG I J K LNOPQRST UVW
M= BE OR NOT TO BE
C= YH KO J KQ QKYH

Another Classical Substitution Ciphers


Transposed keyword mixed
Example:
1- keyword= AHMAD becomes
2- A H M D
B C E F
G I J K
L N O P
Q R S T
U V W X
Y Z

AHMD

3- 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
ABGLQUYHCINR VZMEJ OSWDF KPTX
4- M= BE OR NOT TO BE
C= BQ JO ZMW WM BQ

One-Time Pad

This technique was introduced by army signal


officer Joseph Mauborgne. Which is also called
Vernam.
He suggested using a random key that is as long
as the message.
A message encrypted using a one-time pad
cannot be broken because the encryption key is
a random number and because the key is used
only once
problems in generation & safe distribution of key

One-Time Pad (OTP)

Step 1: Create the key...


You need to create a random key.
HLMSEZRBHPSJOTDW
You need a method for converting alphabet
characters into numbers.

A B C D E F G H I J K L M N O P Q R S
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
T U VW X Y Z
20 21 22 23 24 25 26

One-Time Pad (OTP)

Step 1:

HLMSEZRBHPSJOTDW
To make the key easier to work with, break it into blocks of two
characters each, thus
HL MS EZ RB HP SJ OT DW
Now use the conversion table shown above to convert the
alphabet characters into numbers. For example H=08 and L=12,
so the first block HL becomes 0812.
The result is 0812 1319 0526 1802 0816 1910 1520 0423.
(The key)

One-Time Pad (OTP)


Step 2:

Format your message...

Message MY SECRET. 1325 1905


0318 0520
Key HL MS EZ RB HP SJ OT DW 0812
1319 0526 1802 0816 1910 1520 0423

One-Time Pad (OTP)

Guidelines...
Rule 1 Numbers. Spell out all numbers in full in your
plaintext. For example, 365 becomes THREE SIX FIVE.
Rule 2 Negatives. Always add emphasis to the word NOT
in your plaintext. For example, you would write AGENT ALPHA
NOT RPT NOT AVAILABLE FOR MEETING TUESDAY, where
RPT stands for REPEAT.
Rule 3 Punctuation. Use an X for each period in your
plaintext. For example, MESSAGE RECEIVEDX SEND MORE
INFOX. All other punctuation must be written out in full. For
example, COMMA.
Rule 4 Termination. End your plaintext with XX. If
necessary, add dummy characters after XX in order to pad out
the message to frustrate cryptanalysis and to conclude on a
doublet (ensuring the numeric string ends with four digits).

One-Time Pad (OTP)

Step 3: Encrypt your message...

We need some way to indicate to our recipient where the key


begins, otherwise he/she won't be able to decrypt. Remember in
our earlier example, we created a key and stroked off (in gray)
the blocks we'd already used. Here's what our key looked like.
0812 1319 0526 1802 0816 1910 1520 0423
The starting position in the key is at block 1319. So we'll place
the string 1319 at the beginning of our message so the recipient
will know how to decrypt. The plaintext message of 1325 1905
0318 0520 becomes 1319 1325 1905 0318 0520 because we
place the pointer 1319 at the beginning of the string.

One-Time Pad (OTP)

Step 3: Encrypt your message...

First we write out the plaintext. Then directly below it we write


out the key. Then we add the key to the plaintext using
Fibonicci addition. This means we do no carrying. For
example, 9 + 2 would yield 1 not 11. And 7 plus 6 would yield 3
not 13. Here's how the spy's working sheet would look.
Plaintext 1319 1325 1905 0318 0520
Key
----- 0526 1802 0816 1910
Ciphertext 1319 1841 2707 0124 1430
Encrypted message 1319 1841 2707 0124 1430

One-Time Pad (OTP)

Step 3: Decrypting the message...

We subtract the key from the ciphertext using


Fibonicci subtraction .
We allow no negative numbers.
For example, 2 - 9 would yield 3 (because we add
10 so that we're able to subtract 9 from 12).
Ciphertext 1319 1841 2707 0124 1430
Key
1319 0526 1802 0816 1910
Plaintext
---- 1325 1905 0318 0520

Transposition Ciphers
now consider classical

transposition or

permutation ciphers
these hide the message by rearranging
the letter order
without altering the actual letters used
can recognise these since have the same
frequency distribution as the original text

Rail Fence cipher

write message letters out diagonally over a


number of rows
then read off cipher row by row
eg. write message out as:
m e m a t r h t g p r y
e t e f e t e o a a t

giving ciphertext
MEMATRHTGPRYETEFETEOAAT

Columnar Transposition Ciphers


a more complex transposition
columnar transposition: is rearrangement of characters of plain text
into coulmns.

Write plaintext in a rectangle row by row.


Permute the order of the columns
Read the message off, column by column

Key:4312567
Plaintext:attackp
ostpone
duntilt
woamxyz
Ciphertext:TTNAAPTMTSUOAODWCOIXKNLYPETZ

Product Ciphers

ciphers using substitutions or transpositions are


not secure because of language characteristics
hence consider using several ciphers in
succession to make harder, but:

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

Rotor Machines

before modern ciphers, rotor machines were


most common complex ciphers in use
widely used in WW2(World War II)

German Enigma, Allied Hagelin, Japanese Purple

implemented a very complex, varying


substitution cipher
used a series of cylinders, each giving one
substitution, which rotated and changed after
each letter was encrypted
with 3 cylinders have 263=17576 alphabets

Hagelin Rotor Machine

Confusion and Diffusion

A substitution is said to add confusion to the


encryption process whereas a transposition is
said to add diffusion.
Confusion is intended to make the relationship
between the key and ciphertext as complex as
possible. Diffusion refers to rearranging or
spreading out the characters in the message
Most modern block cipher systems apply a
number of rounds in succession to encrypt
plaintext.
A round then can be said to add both confusion
and diffusion to the encryption

Steganography
an alternative to encryption
hides existence of message

using only a subset of letters/words in a


longer message marked in some way
using invisible ink
hiding in LSB in graphic image or sound file

has drawbacks

high overhead to hide relatively few info bits

Popular sites for Popular sites for Steganography


information

http://
www.ise.gmu.edu/~njohnson/Steganography
http://
www.rhetoric.umn.edu/Rhetoric/misc/dfrank/s
tegsoft.html
http://www.topology.org/crypto.html

Summary
have considered:

classical cipher techniques and terminology


monoalphabetic substitution ciphers
cryptanalysis using letter frequencies
Playfair cipher
polyalphabetic ciphers
transposition ciphers
product ciphers and rotor machines
stenography

You might also like