Information Security
Unit 2: Encryption Techniques Basics
Dr. Asmita Manna
Contents:
• Introduction
• Symmetric & Asymmetric Cipher Model;
• Cryptography; Cryptanalysis and BruteForce Attack
• Classical Encryption Techniques
• Substitution Techniques: Caesar Cipher, Monoalphabetic Ciphers,
Poly-alphabetic Ciphers, Playfair Cipher;
• Transposition Techniques: Rail Fence Technique
Basic Terminologies
• Cryptography
• The art or science encompassing the principles and methods of transforming an
intelligible message into one that is unintelligible, and then retransforming that
message back to its original form
• Plaintext
• The original intelligible message
• Ciphertext
• The transformed message
• Cipher
• An algorithm for transforming an intelligible message into one that is
unintelligible by transposition and/or substitution methods
• Key
• Some critical information used by the cipher, known only to the sender &
receiver
Basic Terminologies (Contd..)
• Encipher (encode)
• Process of converting plaintext to a key
• Decipher (decode)
• The process of converting ciphertext using a cipher and a key
• Cryptanalysis (code breaking)
• The study of principles and methods of transforming an unintelligible
message back into an intelligible message without the knowledge of the key
• Cryptology
• The field encompassing both cryptography and cryptanalysis
Basic Terminologies (Contd..)
• Encryption
• The mathematical function mapping plaintext to ciphertext using the
specified key:
• Y = E K (X) or E(K, X)
• Decryption
• The mathematical function mapping ciphertext to plaintext using the
specified key:
• X = DK (Y) or D(K, X) = E K1 (Y)
Symmetric Encryption
• 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 public-key in 1970’s
• and by far most widely used
Symmetric Cipher Model
-plaintext - original message
-encryption algorithm – performs substitutions/transformations on plaintext
-secret key – control exact substitutions/transformations used in encryption algorithm
-ciphertext - scrambled message
Symmetric Cipher Model
• Same key for encryption and decryption
• Conventional encryption technique
• Problems
• How to distribute the key securely?
• What will happen once the key loses its secrecy?
Asymmetric Cipher Model
Asymmetric Cipher Model
• Two different keys
• One for encryption another for decryption
• Keys are mathematically related
• Public key
• Publicly available; anyone can access it
• Private key
• Available to the owner / originator of the key
• No issue of key distribution
Classical Encryption Techniques
Classical Encryption Techniques
• Two basic types
• Substitution Cipher
• One element of plaintext is substituted by another element
• Monoalphabetic cipher – Caesar Cipher
• Group of bits of plaintext is substituted by another group
• Polygraphic Substitution Cipher – Hill Cipher , Playfair Cipher
• One element of plaintext is substituted by another element, but depending on the relative
position in the plaintext, one letter may be replaced with different letters at different places
• Polyalphabetic Cipher - Vigenere Cipher
• Transposition Cipher
• The letters are written in a row under the key and then arrange the column as per
alphabetical order
• Single Columnar
• Double Columnar
• Rail Fence
Mono Alphabetic Cipher
• One to One
• Additive Cipher / Caesar Cipher
• Multiplicative Cipher / Affine Cipher
• Monoaplhabetic Substitution Cipher
Caesar Cipher
• earliest known substitution cipher
• by Julius Caesar
• first attested use in military affairs
• replaces each letter by 3rd letter from that
• example:
• meet me after the toga party
• PHHW PH DIWHU WKH WRJD SDUWB
Caesar Cipher (…)
• can define transformation as:
• 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 = IN
• 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 = OUT
• mathematically give each letter a number
• 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
• 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
• then have Caesar (rotation) cipher as:
• c = E(k, p) = (p + k) mod (26)
• p = D(k, 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 you have plaintext
• eg. break ciphertext "GCUA VQ DTGCM"
Affine Cipher
• broaden to include multiplication
• can define affine transformation as:
• c = E(k, p) = (ap + b) mod (26)
• p = D(k, c) = a-1 (c – b) mod (26) D(x)=a-1(x-b)mod m
• key k = (a,b)
• a must be relatively prime to 26
• so there exists unique inverse a-1
Affine Cipher - Example
example k=(17,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 = IN (a-0, z-25)
D U L C T K B S J A R I Z Q H Y P G X O F W N E V M = OUT
example:
meet me after the toga party
ZTTO ZT DKOTG OST OHBD YDGOV
Now how many keys are there?
● 12 x 26 = 312
Still can be brute force attacked!
Note: Example of product cipher
https://www.dcode.fr/affine-cipher - Let’s check
Monoalphabetic Cipher or Cryptogram
rather than just shifting the alphabet could shuffle (permute) the letters arbitrarily
each plaintext letter maps to a different random ciphertext letter
hence key is 26 letters long
Plain: 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
Cipher: D K V Q F I BJ WPES C X H T M Y A UO L R G Z N
Plaintext: ifwewishtoreplaceletters
Ciphertext: WIRFRWAJUHYFTSDVFSFUUFYA
Language Redundancy and Cryptanalysis
human languages are redundant
e.g., "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,A,O,I, N ,S
other letters like Z,J,K,Q,X are fairly
rare
have tables of single, double & triple
letter frequencies for various
languages
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 looks for common peaks/troughs
● peaks at: A-E-I triple, N-O pair, R-S-T triple
● troughs at: J-K, U-V-W-X-Y-Z
for monoalphabetic must identify each letter
● tables of common double/triple letters help (digrams and trigrams)
amount of ciphertext is important – statistics!
An Example to solve…
• GFS WMY OG LGDVS MF SFNKYHOSU ESLLMRS, PC WS BFGW
POL DMFRQMRS, PL OG CPFU M UPCCSKSFO HDMPFOSXO GC
OIS LMES DMFRQMRS DGFR SFGQRI OG CPDD GFS LISSO GK
LG, MFU OISF WS NGQFO OIS GNNQKKSFNSL GC SMNI DSOOSK.
WS NMDD OIS EGLO CKSJQSFODY GNNQKKPFR DSOOSK OIS
'CPKLO', OIS FSXO EGLO GNNQKKPFR DSOOSK OIS 'LSNGFU'
OIS CGDDGWPFR EGLO GNNQKKPFR DSOOSK OIS 'OIPKU', MFU
LG GF, QFOPD WS MNNGQFO CGK MDD OIS UPCCSKSFO
DSOOSKL PF OIS HDMPFOSXO LMEHDS. OISF WS DGGB MO OIS
NPHISK OSXO WS WMFO OG LGDVS MFU WS MDLG NDMLLPCY
POL LYEAGDL. WS CPFU OIS EGLO GNNQKKPFR LYEAGD MFU
NIMFRS PO OG OIS CGKE GC OIS 'CPKLO' DSOOSK GC OIS
HDMPFOSXO LMEHDS, OIS FSXO EGLO NGEEGF LYEAGD PL
NIMFRSU OG OIS CGKE GC OIS 'LSNGFU' DSOOSK, MFU OIS
CGDDGWPFR EGLO NGEEGF LYEAGD PL NIMFRSU OG OIS
CGKE GC OIS 'OIPKU' DSOOSK, MFU LG GF, QFOPD WS
MNNGQFO CGK MDD LYEAGDL GC OIS NKYHOGRKME WS
WMFO OG LGDVS.
Step by Step Solution
• The first step is to find the frequency of
all the letters appearing in the intercept.
For this intercept we get the values
given in the table below.
• Let us rearrange as in decreasing order
• Let us compare the frequency
distribution with the standard English
distribution
• S and O to e and t??
• GFe WMY tG LGDVe MF eFNKYHteU EeLLMRe, PC We BFGW PtL
DMFRQMRe, PL tG CPFU M UPCCeKeFt HDMPFteXt GC tIe LMEe
DMFRQMRe DGFR eFGQRI tG CPDD GFe LIeet GK LG, MFU tIeF
We NGQFt tIe GNNQKKeFNeL GC eMNI DetteK. We NMDD tIe EGLt
CKeJQeFtDY GNNQKKPFR DetteK tIe 'CPKLt', tIe FeXt EGLt
GNNQKKPFR DetteK tIe 'LeNGFU' tIe CGDDGWPFR EGLt
GNNQKKPFR DetteK tIe 'tIPKU', MFU LG GF, QFtPD We MNNGQFt
CGK MDD tIe UPCCeKeFt DetteKL PF tIe HDMPFteXt LMEHDe. tIeF
We DGGB Mt tIe NPHIeK teXt We WMFt tG LGDVe MFU We MDLG
NDMLLPCY PtL LYEAGDL. We CPFU tIe EGLt GNNQKKPFR
LYEAGD MFU NIMFRe Pt tG tIe CGKE GC tIe 'CPKLt' DetteK GC tIe
HDMPFteXt LMEHDe, tIe FeXt EGLt NGEEGF LYEAGD PL
NIMFReU tG tIe CGKE GC tIe 'LeNGFU' DetteK, MFU tIe
CGDDGWPFR EGLt NGEEGF LYEAGD PL NIMFReU tG tIe CGKE
GC tIe 'tIPKU' DetteK, MFU LG GF, QFtPD We MNNGQFt CGK MDD
LYEAGDL GC tIe NKYHtGRKME We WMFt tG LGDVe.
• Most common Trigram is : tIe >
• I should correspond to?? H
• Next highest frequency from the graph? G, right?
• G must correspond to ‘a’, ‘i’ or ‘o’
• tG is quite common –
• Which diagram do you think this tG is? ta, ti or to?
• G -> o
• GF and GC –on, or, of
• F – n, makes sense in oFe and theF!
• Matches frequency too!
• oFe WMY to LoDVe MF eFNKYHteU EeLLMRe, PC We BFoW PtL
DMFRQMRe, PL to CPFU M UPCCeKeFt HDMPFteXt oC the LMEe
DMFRQMRe DoFR eFoQRh to CPDD oFe Lheet oK Lo, MFU theF We NoQFt
the oNNQKKeFNeL oC eMNh DetteK. We NMDD the EoLt CKeJQeFtDY
oNNQKKPFR DetteK the 'CPKLt', the FeXt EoLt oNNQKKPFR DetteK the
'LeNoFU' the CoDDoWPFR EoLt oNNQKKPFR DetteK the 'thPKU', MFU Lo
oF, QFtPD We MNNoQFt CoK MDD the UPCCeKeFt DetteKL PF the
HDMPFteXt LMEHDe. theF We DooB Mt the NPHheK teXt We WMFt to
LoDVe MFU We MDLo NDMLLPCY PtL LYEAoDL. We CPFU the EoLt
oNNQKKPFR LYEAoD MFU NhMFRe Pt to the CoKE oC the 'CPKLt' DetteK
oC the HDMPFteXt LMEHDe, the FeXt EoLt NoEEoF LYEAoD PL NhMFReU
to the CoKE oC the 'LeNoFU' DetteK, MFU the CoDDoWPFR EoLt NoEEoF
LYEAoD PL NhMFReU to the CoKE oC the 'thPKU' DetteK, MFU Lo oF,
QFtPD We MNNoQFt CoK MDD LYEAoDL oC the NKYHtoRKME We WMFt
to LoDVe.
• Lheet - > sheet may be?
• L->s
one WMY to soDVe Mn enNKYHteU EessMRe, PC We BnoW Pts DMnRQMRe, Ps
to CPnU M UPCCeKent HDMPnteXt oC the sMEe DMnRQMRe DonR enoQRh to
CPDD one sheet oK so, MnU then We NoQnt the oNNQKKenNes oC eMNh DetteK.
We NMDD the Eost CKeJQentDY oNNQKKPnR DetteK the 'CPKst', the neXt Eost
oNNQKKPnR DetteK the 'seNonU' the CoDDoWPnR Eost oNNQKKPnR DetteK the
'thPKU', MnU so on, QntPD We MNNoQnt CoK MDD the UPCCeKent DetteKs Pn
the HDMPnteXt sMEHDe. then We DooB Mt the NPHheK teXt We WMnt to soDVe
MnU We MDso NDMssPCY Pts sYEAoDs. We CPnU the Eost oNNQKKPnR
sYEAoD MnU NhMnRe Pt to the CoKE oC the 'CPKst' DetteK oC the HDMPnteXt
sMEHDe, the neXt Eost NoEEon sYEAoD Ps NhMnReU to the CoKE oC the
'seNonU' DetteK, MnU the CoDDoWPnR Eost NoEEon sYEAoD Ps NhMnReU to
the CoKE oC the 'thPKU' DetteK, MnU so on, QntPD We MNNoQnt CoK MDD
sYEAoDs oC the NKYHtoRKME We WMnt to soDVe.
• K -> r
• D -> l
• Q- > g
• R- >h
• one WMY to solve Mn enNrYHteU EessMge, PC We BnoW Pts lMnguMge, Ps to
CPnU M UPCCerent HlMPnteXt oC the sMEe lMnguMge long enough to CPll one
sheet or so, MnU then We Nount the oNNurrenNes oC eMNh letter. We NMll the Eost
CreJuentlY oNNurrPng letter the 'CPrst', the neXt Eost oNNurrPng letter the
'seNonU' the ColloWPng Eost oNNurrPng letter the 'thPrU', MnU so on, untPl We
MNNount Cor Mll the UPCCerent letters Pn the HlMPnteXt sMEHle. then We looB
Mt the NPHher teXt We WMnt to solve MnU We Mlso NlMssPCY Pts sYEAols. We
CPnU the Eost oNNurrPng sYEAol MnU NhMnge Pt to the CorE oC the 'CPrst' letter
oC the HlMPnteXt sMEHle, the neXt Eost NoEEon sYEAol Ps NhMngeU to the CorE
oC the 'seNonU' letter, MnU the ColloWPng Eost NoEEon sYEAol Ps NhMngeU to the
CorE oC the 'thPrU' letter, MnU so on, untPl We MNNount Cor Mll sYEAols oC the
NrYHtogrME We WMnt to solve.
• N -> c H-> p U-> d E-> m M->a W-> w Y-> y Z->z P - >i
• one way to solve an encrypted message, if we know its language, is to find
a different plaintext of the same language long enough to fill one sheet or
so, and then we count the occurrences of each letter. we call the most
frequently occurring letter the 'first', the next most occurring letter the
'second' the following most occurring letter the 'third', and so on, until we
account for all the different letters in the plaintext sample. then we look at
the cipher text we want to solve and we also classify its symbols. we find
the most occurring symbol and change it to the form of the 'first' letter of
the plaintext sample, the next most common symbol is changed to the form
of the 'second' letter, and the following most common symbol is changed
to the form of the 'third' letter, and so on, until we account for all symbols
of the cryptogram we want to solve.
Poly-Alphabetic Substitution Cipher
• Autokey Cipher
• Playfair Cipher
• Vigenere Cipher
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 Cipher
• Encryption is divided into three parts:
• Preparing the plaintext
• Preparing the key
• Encryption
Playfair …
• The message is converted into lowercase;
• All punctuations are removed
• The message is split into group of two letters.
• If any group contains same letter twice, ‘x’ is inserted in between those two
same letters and the message is re-grouped after insertion
• If j is present in the message, j is replaced with ‘i’ generally!
• Finally the groups are arranged in five columns in multiple rows
Example of plaintext
• We live in a world full of beauty.
• we live in a world full of beauty
• we li ve in aw or ld fu ll of be au ty
• we li ve in aw or ld fu lx lo fb ea ut y
• we li ve in aw or ld fu lx lo fb ea ut yz
we li ve in aw
or ld fu lx lo
fb ea ut yz
A N O T H
Example of key E R
• You can have a key having any number of letters
• But the key can’t have any duplicate letter
• If duplicate letter is there, one occurrence should be
removed
• Convert the letters in uppercase
A N O T H
• Construct a 5 x 5 matrix
• Suppose our key is another E R
• Step 1: ANOTHER (no duplicates!)
• Step 2: Enter the letters in a 5 x 5 matrix starting from
m[0][0] – first 5 letters in first row.
• Step 3: Remaining letters of alphabet, which are not
present in key, should be inserted into the table in
alphabetical order.
Playfair Cipher - Encryption
• Read the first group of letters from the plain-text.
• Depending upon whether the two letters in a group belong to same row,
same column, different substitutions are used
• If both the letters are on the same row
• Each letter is replaced by the letter to the right of that letter. (If plaintext letter is the last letter
in the row, wrap it up and substitute it with the first letter of the row
• If both the letters are on the same column
• Each letter is replaced by the letter below of that letter. (If plaintext letter is the last letter in the
column, wrap it up and substitute it with the first letter of the column
• If both the letters are neither on the same row nor on the same column
• Substitution is done based on their intersection
• Take the first letter - move through the row and reach the column of the second letter.
Substitute with that letter
• Take the second letter – same procedure
A N O T H
E R B C D
F G I/J K L
M P Q S U
V W X Y Z
we li ve in aw
or ld fu lx lo
fb ea ut yz
Transposition Cipher
Transposition Cipher
• A transposition cipher reorders (permutes) symbols in a block of
symbols
• Keyless Transposition Cipher
• Keyed Transposition Cipher
• Combination of two
Keyless Transposition Ciphers
• The keyless ciphers permute the characters by using writing plaintext
in one way and reading it in another way
• Simple transposition ciphers, which were used in the past,are keyless.
• Example –Rail Fence Cipher
Rail Fence Cipher
• the plaintext is written downwards diagonally on successive "rails" of an
imaginary fence
• moving up when the bottom rail is reached
• down again when the top rail is reached
• Continue till the whole plaintext is written
• Read each rail at a time starting from the top rail
• Example:
• Plaintext: we are discovered run at once
• W...E...C... R... U...O...
• .E.R.D.S.O.E.E.R.N.T.N. E
• ..A... I... V... D... A... C.
• WECRUO ERDSOEERNTNE AIVDAC
Keyless Transposition Ciphers
• Columnar Transposition
Simple Keyless Columnar
Transposition
• Write row-wise under
pre-defined number of columns!
C O M E H O • Read One column at a time
• Easiest
M E T O M O
• CMROERMTOEOWHM-OO-
R R O W - -
1 2 3 4 5 6
Keyed Transposition Cipher – Single
Columnar
• The permutation is done on the H E A V E N
whole plaintext to create the 4 2 1 6 3 5
whole cipher text. W E A R E T
H E B E S T
• In Keyed Transposition, key
determines the order of reading
different columns.
• AB EE ES WH TT RE
Keyed Transposition Cipher – Double Columnar
• To provide stronger encryption H E A V E N
than single columnar, Double 4 2 1 6 3 5
columnar is proposed W E A R E T
H E B E S T
• Same procedure needs to be
applied twice!
A N O T H E R
• AB EE ES WH TT RE 1 4 5 7 3 2 6
• Second time, a different key will A B E E E S W
be applied on this cipher text H T T R E Z Z
• AHSZ EE BT ET WZ ER
Cryptanalysis of Columnar transposition
• The order of the letters in the plaintext is shuffled
• However, if the key length is short, it is possible to break the cipher
easily.
• Assume the number in the keys – 5/6/7
• Then arrange the cipher text in 5/6/7 columns.
• Concentrate on a single Row. Try to unscramble to find out dictionary
word!
• Arrange the columns accordingly
Example
• GSMOEVMTEFMTPYPEIRSPIOEVIEEOMP
• Count the number of letters – 30
• Assumption: The array may look like 6*5 or 5*6 or 3*10 or 10*3
• Let us try with 6 by 5 array
• GSMOE VMTEF MTPYP EIRSP IOEVI EEOMP
G
S
M
O
E
Thank you