Unit-1 5
Unit-1 5
Sender Recipient
Security -related Info. Security -related
Channel
Message
Message
Message
Message
Transformation Transformation
Secure
Secure
Secret Secret
Information Opponent Information
Encryption and Decryption
The simplest monoalphabetic cipher is the additive cipher. This cipher is sometimes called
a shift cipher and sometimes a Caesar cipher, but the term additive cipher better reveals
its mathematical nature.
When the cipher is additive, the plaintext, ciphertext, and key are integers in Z26.
1) Additive or Caesar Cipher
The Caesar cipher involves replacing each letter of the alphabet with the letter standing
three places further down the alphabet.
In encryption each plaintext letter P, substitute the ciphertext letter C:
C = E(k, P) = (P + k) mod 26
C = E(3, P) = (P + 3) mod 26
For decryption algorithm is:
P = D(k, C) = (C - k) mod 26
Caesar Cipher (Cont…)
Let us assign a numerical equivalent to each letter
a b c d e f g h i j k l m
0 1 2 3 4 5 6 7 8 9 10 11 12
n o p q r s t u v w x y z
13 14 15 16 17 18 19 20 21 22 23 24 25
C = E(3, P) = (P + 3) mod 26
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 e f g h i j k l m n o p q r s t u v w x y z a
Example:
b c
Plaintext: THE QUICK BROWN FOX
Ciphertext: WKH TXLFN EURZQ IRA
Brute force attack on Caesar Cipher
The encryption and decryption algorithms are known.
There are only 25 keys to try.
The language of the plaintext is known and easily recognizable.
Brute force attack on Caesar Cipher
Ciphertext: ZNK WAOIQ HXUCT LUD
Key Transformed text Key Transformed text
1 YMJ VZNHP GWTBS KTC 14 LZW IMAUC TJGOF XGP
2 XLI UYMGO FVSAR JSB 15 KYV HLZTB SIFNE WFO
3 WKH TXLFN EURZQ IRA 16 JXU GKYSA RHEMD VEN
4 VJG SWKEM DTQYP HQZ 17 IWT FJXRZ QGDLC UDM
5 UIF RVJDL CSPXOGPY
18 HVS EIWQY PFCKB TCL
6 THE QUICK BROWN FOX
19 GUR DHVPX OEBJA SBK
7 SGD PTHBJ AQNVM ENW
8 RFC OSGAI ZPMUL DMV 20 FTQ CGUOW NDAIZ RAJ
9 QEB NRFZH YOLTK CLU 21 ESP BFTNV MCZHY QZI
10 PDA MQEYG XNKSJ BKT 22 DRO AESMU LBYGX PYH
11 OCZ LPDXF WMJRI AJS 23 CQN ZDRLT KAXFW OXG
12 NBY KOCWE VLIQH ZIR 24 BPM YCQKS JZWEV NWF
13 MAX JNBVD UKHPG YHQ 25 AOL XBPJR IYVDU MVE
2) Simple substitution
It is an improvement to the Caesar Cipher.
Instead of shifting the alphabets by some number, this scheme uses some permutation of
the letters in alphabet.
The sender and the receiver decide on a randomly selected permutation of the letters of
the alphabet.
With 26 letters in alphabet, the possible permutations are 26! which is equal to 4x1026.
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: y n l k x b s h m i w d p j r o q v f e a u g t
z c
Attack on Monoalphabetic Cipher
The relative frequencies of the letters in the ciphertext (in percentages) are
Ciphertext:
uzqsovuohxmopvgpozpevsgzwszopfpesxudbmetsxaizvuephzhmdzs
hzowsfpappdtsvpquzwymxuzuhsxepyepopdzszufpombzwpfupzhmdj
udtmohmq
In our ciphertext, the most common digram is ZW, which appears
three times. So equate Z with t, W with h and P with e.
Now notice that the sequence ZWP appears in the ciphertext, and
we can translate that sequence as “the.”
Attack on Monoalphabetic Cipher (Cont…)
If the cryptanalyst knows the nature of the plaintext, then the analyst can exploit the
regularities of the language.
The relative frequency of the letters can be determined and compared to a standard
frequency distribution for English.
If the message were long enough, this technique alone might be sufficient, but because
this is a relatively short message, we cannot expect an exact match.
3. Multiplicative cipher
Multiplicative cipher to encrypt the message “hello” with a key of 7. The ciphertext is
“XCZZU”.
4. Affine cipher
The affine cipher uses a pair of keys in which the first key is from Z 26* and the second is
from Z26. The size of the key domain is 26 × 12 = 312.
Use an affine cipher to encrypt the message “hello” with the key pair (7, 2).
Use the affine cipher to decrypt the message “ZEBBW” with the key pair (7, 2) in modulus
26.
Plaintext = "HELLO"
Autokey = N
Ciphertext = "ULPWZ"
Example
Given plain text is : H E L L O Let's decrypt:
Key is :NHELL
Cipher Text(C) :U L P W Z
Let's encrypt: Key(K) :N H E L L
---------------------
Plain Text(P) Applying the formula: H E L L O
:H E L L O
Hence Plaintext is: HELLO
Corresponding Number: 7 4 11 11 14
Key(K) :N H E L L
Corresponding Number: 13 7 4 11 11
---------------------
Applying the formula: 20 11 15 22 25
Letters are :U L P W Z
O C U R E
Example: N A B D F
Keyword= OCCURRENCE
Plaintext= TALL TREES G H I/J K L
M P Q S T
V W X Y Z
Playfair Cipher - Encrypt Plaintext
Playfair, treats digrams (two letters) in the plaintext as single units and translates these
units into ciphertext digrams.
Make Pairs of letters add filler letter “X” if same letter appears in a pair.
Key Distribution: Distributing and securely managing the key can be challenging. If the key is
compromised, the entire encryption system becomes vulnerable.
Known-plaintext Attacks: The Playfair cipher is susceptible to known-plaintext attacks. If an attacker has
access to some parts of the encrypted text and the corresponding plaintext, they can analyze the
patterns and potentially deduce parts of the key.
Frequency Analysis: Similar to other classical ciphers, frequency analysis can be applied to ciphertext
encrypted with the Playfair cipher. This involves analyzing the frequency of certain digraphs (pairs of
letters) to deduce information about the plaintext.
Insecure for Large Data: The Playfair cipher is not well-suited for encrypting large amounts of data. It
was primarily designed for manual encryption and decryption of short messages.
Limited Alphabet: The Playfair cipher works with a 5x5 grid of letters, so it cannot handle characters
outside of the English alphabet. This limitation makes it unsuitable for encrypting messages in other
languages or containing special characters.
No Authentication: The Playfair cipher does not provide any form of authentication. An attacker might
modify the ciphertext, and the recipient would have no way of knowing if the message has been
tampered with.
Cryptanalysis Techniques: Various cryptanalysis techniques, such as hill climbing and simulated
annealing, can be applied to break the Playfair cipher, especially when multiple rounds of encryption
are used.
2. Hill Cipher
Hill Cipher is a popular symmetric key encryption algorithm that was developed by Lester S.
Hill in 1929. It is a polygraphic substitution cipher that encrypts plaintext by dividing it into
blocks of n letters and transforming those blocks using a matrix-based algorithm.
Hill Cipher is widely used in various applications, including military communications,
banking, and computer security.
Use Cases of Hill Cipher:
Military communications: Hill Cipher has been used by the military to encrypt sensitive
communications and protect them from interception.
Banking: Hill Cipher has been used by banks to protect financial transactions and customer
data from unauthorized access.
Computer security: Hill Cipher has been used in various computer security applications,
including encryption of passwords and other sensitive data.
Encryption Process of Hill Cipher:
Hill Cipher encrypts plaintext by dividing it into blocks of n letters and transforming those
blocks using a matrix-based algorithm.
The encryption algorithm involves multiplying the block of plaintext by a key matrix to
produce a block of ciphertext.
The key matrix used for encryption must be invertible, meaning that it has an inverse
matrix that can be used for decryption.
* Hill Cipher can be made more secure by using larger block sizes and more complex key
matrices.
Decryption Process of Hill Cipher:
Hill Cipher decrypts ciphertext by multiplying the block of ciphertext by the inverse of the
key matrix to produce a block of plaintext.
The inverse matrix is calculated using matrix algebra and must exist for decryption to be
possible.
The decrypted plaintext is then reassembled from the blocks of n letters.
Hill Cipher
Hill cipher is based on linear algebra
Each letter is represented by numbers from 0 to 25 and calculations are done modulo 26.
Encryption and decryption can be given by the following formula:
Encryption:
C=P.K mod 26
Decryption:
P=C.K-1 mod 26
mod 26
Hill Cipher Encryption
To encrypt a message using the Hill Cipher we must first turn our keyword and plaintext
into a matrix (a 2 x 2 matrix or a 3 x 3 matrix, etc).
=
Hill Cipher Encryption (Cont…)
== Plaintext
( )( ) ( )( )
E
X
A
M
=
4
23
0
12
C=P.K mod 26
( 7
11
8
11 )( )
4
23 ( 7
11
8
11 )( )
0
12
x 4 + 8 x 23 = 212 x 0 + 8 x 12 = 96
x 4 + 11 x 23 = 297 x 0 + 11 x 12 = 132
( 7
11
8
11 )( ) (
4
23
=
2 12
297 ) ( 7
11
8
11 )( ) (
0
12
=
96
132 )
= mod 26 = = mod 26 =
Ciphertext = “ELSC”
Hill Cipher Decryption
P=CK-1 mod 26
Step:1 Find Inverse of key matrix
Step:2 Multiply the Multiplicative Inverse of the Determinant by the Adjoin Matrix
Step:3 Multiply inverse key matrix with ciphertext matrix to obtain plaintext matrix
Inverse of key matrix
2 X 2 inverse of matrix
[ ] [ ]
−1
a b 1 d −b
=
c d ad − cb −c a
3 X 3 inverse of matrix
−1 1
A = ∙ adjoin( A )
determinant ( A )
Hill Cipher Encryption (Cont…)
= Ciphertext
( )( ) ( )( )
E
L
S
C
=
4
11
18
2
P=CK-1 mod 26
( 25
1
22
23 )( )
4
11 ( 25
1
22
23 )( )
18
2
x 4 + 22 x 11 = 342 x 18 + 22 x 2 = 494
x 4 + 23 x 11 = 257 x 18 + 23 x 2 = 64
( 25
1
22
23 )( ) (
4
11
=
342
257 ) ( 7
11
8
11 )( ) (
0
12
=
494
64 )
= mod 26 = = mod 26 =
Plaintext = “EXAM”
Some cryptography books express the plaintext and ciphertext as column vectors, so that
the column vector is placed after the matrix rather than the row vector placed before the
matrix.
We have to encrypt the message ‘ACT’ (n=3).The key is ‘GYBNQKURP’ which can be
written as the nxn matrix:
K
e
y
PT = HELLO
KEY = GMGMG
CT = NQRXU
4. Vernam Cipher
One of the goals of cryptography is perfect secrecy. A study by Shannon has shown that
perfect secrecy can be achieved if each plaintext symbol is encrypted with a key
randomly chosen from a key domain. This idea is used in a cipher called one-time pad,
invented by Vernam
The ciphertext is generated by applying the logical XOR operation to the individual bits of
plaintext and the key stream.
5. One time pad
The one-time pad, which is a provably secure cryptosystem,
was developed by Gilbert Vernam in 1918.
The message is represented as a binary string (a sequence of 0’s
and 1’s using a coding mechanism such as ASCII coding.
The key is a truly random sequence of 0’s and 1’s of the same
length as the message.
message =‘IF’
then its ASCII code =(1001001 1000110)
key = (1010110 0110001)
Encryption:
• 1001001 1000110 plaintext
• 1010110 0110001 key
• 0011111 1110110 ciphertext
Transposition Ciphers
A transposition cipher does not substitute one symbol for another, instead it changes the
location of the symbols.
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 send the message “Meet me at the park” to Bob, Alice writes
Key: 4 3 1 2 5 6 7
Plaintext: a t t a c k p
o s t p o n e
d u n t i l t
w o a m x y z
Ciphertext: TTNAAPTMTSUOAODWCOIXKNLYPETZ
Same thing can be used as a matrices to show the encryption/decryption process for a
transposition cipher.
Double transposition
Cryptography and Cryptanalysis
Cryptography and Cryptanalysis
• Cryptography is the study of the design of techniques for ensuring the secrecy and/or
authenticity of information
• Cryptanalysis deals with the defeating such techniques to recover information, or
forging information that will be accepted as authentic
STREAM AND BLOCK CIPHERS
Symmetric encryption algorithms are categorized into two: block and stream ciphers.
• Stream Ciphers
• Block Ciphers
• Combination
Symmetric cryptography involves using a shared key/secret to access an encoded message
between two entities. The sender shares the key cipher with the receiver to decrypt the
message. The encryption algorithm emulates a one-time pad system to protect the original
message from unauthorized access.
The cipher algorithms generate a truly random key cipher used only once with the one-time
pad system. Anyone who does not possess the secret/key cannot interpret the encrypted
message.
Block ciphers encrypt data in blocks of set lengths, while stream ciphers do not and
instead encrypt plaintext one byte at a time. The two encryption approaches, therefore,
vary widely in implementation and use cases.
Block ciphers convert data in plaintext into ciphertext in fixed-size blocks. The block size
generally depends on the encryption scheme and is usually in octaves (64-bit or 128-bit
blocks).
• If the plaintext length is not a multiple of 8, the encryption scheme uses padding to ensure complete
blocks. For instance, to perform 128-bit encryption on a 150-bit plaintext, the encryption scheme
provides two blocks, 1 with 128 bits and one with the 22 bits left. 106 Redundant bits are added to the
last block to make the entire block equal to the encryption scheme’s ciphertext block size.
Cryptographic Algorithms
Cryptographic algorithms and protocols can be grouped into four
main areas
Cryptographic
algorithms and
protocols
Data integrity
Authentication
Symmetric
Asymmetric algorithms
Protocols
encryption
encryption usedused
used to to
are
to protect
schemes
conceal
secure theblocks
based
small of
ondata,
contents
blocks the
of
of such
data,
blocks as
usesuch
of
or
messages,
streams
as offrom
cryptographic
encryptiondata alteration.
algorithms
keys
of any designed
and size,
hash to authenticate
including
function messages,
values, whichtheare
files, identity
used of
encryption
in
entities.
keys,
digital
and
signatures.
passwords