You are on page 1of 24

CRYPTOGRAPHY https://deepaharivinod.blogspot.

com

MODULE 1
Classical Encryption Techniques: Symmetric cipher model, Substitution
techniques, and Transposition techniques (Text 1: Chapter 1)

Basic Concepts of Number Theory and Finite Fields: Euclidean algorithm,


Modular arithmetic (Text 1: Chapter 3)

Text Books:

1. William Stallings , “Cryptography and Network Security Principles and


Practice”, Pearson Education Inc., 6th Edition, 2014, ISBN: 978-93-325-1877-3

Explore Electronics 1
CRYPTOGRAPHY https://deepaharivinod.blogspot.com

MODULE 1
Symmetric cipher model
Symmetric encryption also referred to as conventional encryption or single-key
encryption.

Plaintext: This is the original intelligible message or data that is fed into the
algorithm as input.
● Encryption algorithm: The encryption algorithm performs various
substitutions and transformations on the plaintext.
● Secret key: The secret key is also input to the encryption algorithm. The key
is a value independent of the plaintext and of the algorithm. The algorithm will
produce a different output depending on the specific key being used at the time.
The exact substitutions and transformations performed by the algorithm depend
on the key.

Explore Electronics 2
CRYPTOGRAPHY https://deepaharivinod.blogspot.com

● Cipher text: This is the scrambled message produced as output. It depends on


the plaintext and the secret key. For a given message, two different keys will
produce two different cipher texts. The cipher text is an apparently random
stream of data and, as it stands, is unintelligible.

● Decryption algorithm: This is essentially the encryption algorithm run in


reverse. It takes the cipher text and the secret key and produces the original
plaintext.

A source produces a message in plaintext, X = [X1, X2, ..., XM]. The M


elements of X are letters in some finite alphabet. Traditionally, the alphabet
usually consisted of the 26 capital letters. Nowadays, the binary alphabet {0, 1}
is typically used. For encryption, a key of the form K = [K1, K2, ..., KJ] is
generated. If the key is generated at the message source, then it must also be
provided to the destination by means of some secure channel. Alternatively, a
third party could generate the key and securely deliver it to both source and
destination. With the message X and the encryption key K as input, the
encryption algorithm forms the cipher text

Explore Electronics 3
CRYPTOGRAPHY https://deepaharivinod.blogspot.com

Y = [Y1, Y2, ..., YN]. We can write this as


Y = E(K, X)
This notation indicates that Y is produced by using encryption algorithm
E as a function of the plaintext X, with the specific function determined by the
value of the key K. The intended receiver, in possession of the key, is able to
invert the transformation: X = D(K, Y) .

An opponent, observing Y but not having access to K or X, may attempt


to recover X or K or both X and K. It is assumed that the opponent knows the
encryption (E) and decryption (D) algorithms. If the opponent is interested in
only this particular message, then the focus of the effort is to recover X by
generating a plaintext estimate X.

Cryptography

Cryptographic systems are characterized along three independent


dimensions:

1. The Type of operations used for transforming plaintext to cipher


text. All encryption algorithms are based on two general
principles:

 Substitution: each element in the plaintext (bit, letter, group of bits or


letters) is mapped into another element,
 Transposition: elements in the plaintext are rearranged.

The fundamental requirement is that no information be lost (all operations


are reversible). Product systems involve multiple stages of substitutions and

transpositions.

2. The number of keys used.

 If both sender and receiver use the same key, the system is
referred to as symmetric, single-key, secret-key, or conventional
encryption.

Explore Electronics 4
CRYPTOGRAPHY https://deepaharivinod.blogspot.com

 If the sender and receiver use different keys, the system is


referred to as asymmetric, two-key, or public-key encryption.

3. The way in which the plaintext is processed.

 A block cipher processes the input one block of elements at a time,


producing an output block for each input block.
 A stream cipher processes the input elements continuously, producing
output one element at a time, as it goes along.
CRYPTOGRAPHY
 The word cryptography was derives from combining 2 Greek words.
“Krypto” it means “hidden” and “graphene” meaning “writing”.
Cryptography is the art of secret information writing or secret data
writing.
 The main goal of cryptography is a data secure from unauthorized
persons or attackers or hackers.
 Cryptography is a method of storing and transmitting data in a
particular form so that only those for whom it is intended can read and
process it.

 Encryption is a technique for transforming plain-text into an unreadable


cipher-text or unintelligible format.
 Decryption is a technique for transforming cipher text (unreadable data)
into plain text or original data (secret or confidential data).

Explore Electronics 5
CRYPTOGRAPHY https://deepaharivinod.blogspot.com

 The key is also a group of bits which as a major role in the process of
encryption and decryption.
Types of Cryptography
1. Symmetric Key Cryptography (Secret Key Cryptography)
2. Asymmetric Key Cryptography (Public Key Cryptography)
3. Hash Function
1. Symmetric Key Cryptography: Symmetric key cryptography is called
secret key cryptography or shared key or private key cryptography and it uses a
same key or single-key for both of encryption & decryption method. The
Symmetric key system is the DEC (data encryption standard).Symmetric key
cryptography systems are simpler and faster.
2. Asymmetric Key Cryptography (Public Key Cryptography): where a
different
keys used for encryption and decryption. The different keys are a private key &
a public key.
3. Hash functions: uses a mathematical transformation to irreversibility
“encrypt” information. It is a one-way encryption. Uses no key for encryption
and decryption.
Advantages
 Enter (key) length will be generally short.
 Symmetric key cipher can be joined together to prepare stronger ciphers.
 It hides those secret or confidential messages and your protection or
privacy may be sheltered or protected or safe.
Application
 On line banking.
 On line transaction.
 Media data base system.
 Medical application.

Explore Electronics 6
CRYPTOGRAPHY https://deepaharivinod.blogspot.com

4. Cryptanalysis

The objective of attacking an encryption system is to recover the key in


use rather then simply to recover the plaintext of a single cipher text. There are
two general approaches to attacking a conventional encryption scheme:
Cryptanalysis: Cryptanalytic attacks rely on the nature of the algorithm plus
perhaps some knowledge of the general characteristics of the plaintext or even
some sample plain text cipher text pairs. This type of attack exploits the
characteristics of the algorithm to attempt to deduce a specific plaintext or to
deduce the key being used.
Brute-force attack: The attacker tries every possible key on a piece of cipher
text until an intelligible translation into plaintext is obtained. On average, half of
all possible keys must be tried to achieve success.

Substitution Techniques
The two basic building blocks of all encryption techniques are
substitution and transposition. A substitution technique is one in which the
letters of plaintext are replaced by other letters or by numbers or symbols. If the

Explore Electronics 7
CRYPTOGRAPHY https://deepaharivinod.blogspot.com

plaintext is viewed as a sequence of bits, then substitution involves replacing


plaintext bit patterns with cipher text bit patterns.

Caesar Cipher
The Caesar cipher involves replacing each letter of the alphabet with the
letter standing three places further down the alphabet. For example,

plain: meet me after the toga party


cipher: PHHW PH DIWHU WKH WRJD SDUWB

Note that the alphabet is wrapped around, so that the letter following Z is A. We
can define the transformation by listing all possibilities, as follows:
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 B C

Assign a numerical equivalent to each letter:

Then the algorithm can be expressed as follows. For each plaintext letter p,
substitute the cipher text letter C:

C = E(3, p) = (p + 3) mod 26

A shift may be of any amount, so that the general Caesar algorithm is

C = E(k, p) = (p + k) mod 26
Explore Electronics 8
CRYPTOGRAPHY https://deepaharivinod.blogspot.com

where k takes on a value in the range 1 to 25. The decryption algorithm is


simply

p = D(k, C) = (C-k) mod 26

If it is known that a given cipher text is a Caesar cipher, then a brute-


force cryptanalysis is easily performed: simply try all the 25 possible keys.

Three important characteristics of this problem enabled us to use a brute force


cryptanalysis:

1. The encryption and decryption algorithms are known.


2. There are only 25 keys to try.
3. The language of the plaintext is known and easily recognizable.

Monoalphabetic Ciphers
 Instead of shifting alphabets by the fixed amount as in Caesar cipher, any
random permutation is assigned to the alphabets. This type of encryption
called Monoalphabetic substitution cipher.
 For example, a replaced by Q, B by D, C by T etc. then it will be
comparatively stronger than Caesar.

Playfair cipher
 In this technique, multiple (2) letters encrypted at a time.
 This technique uses a 5 X 5 matrix which also called the key matrix.
 Key used is “MONARCHY”

Explore Electronics 9
CRYPTOGRAPHY https://deepaharivinod.blogspot.com

 The plaintext encrypted two letters at a time, according to the following


rules:
 Repeating plaintext letters that are in the same pair are separated with a
filler letter, such as x, so that balloon would be treated as ba lx lo on.
 Two plaintext letters that fall in the same row of the matrix are each
replaced by the letter to the right, with the first element of the row
circularly following the last.
 For example, ar is encrypted as RM.
 Two plaintext letters that fall in the same column are each replaced by
the letter beneath, with the top element of the column circularly following
the last.
 For example, mu is encrypted as CM.
 Otherwise, each plaintext letter in a pair is replaced by the letter that lies
in its own row and the column occupied by the other plaintext letter.
Thus, hs become BP and ea becomes IM (or JM, as the enciphered
wishes).
 Security much improved over Monoalphabetic as here two letters are
encrypted at a time and hence there are 26 X 26 =676 diagrams and hence
it needs a 676 entry frequency table.
 However, it can break even if a few hundred letters known as much of
plaintext structure retained in the cipher text.

HILL CIPHER
Another interesting multiletter cipher is the Hill cipher, developed by the
mathematician Lester Hill in 1929. The encryption algorithm takes m
successive plaintext letters and substitutes for them m ciphertext letters. The
substitution is determined by m linear equations in which each character is
assigned a numerical value (a = 0, b = 1 ... z = 25).

Explore Electronics 10
CRYPTOGRAPHY https://deepaharivinod.blogspot.com

c1 = (k11P1 + k12P2 + k13P3) mod 26

c2 = (k21P1 + k22P2 + k23P3) mod 26

c3 = (k31P1 + k32P2 + k33P3) mod 26

This can be expressed in term of column vectors and matrices:

or
C = KP mod 26
where C and P are column vectors of length 3, representing the plaintext and
ciphertext, and K is a 3 x 3 matrix, representing the encryption key. Operations
are performed mod 26.
Table 1
A B C D E F G H I
0 1 2 3 4 5 6 7 8
J K L M N O P Q R
9 10 11 12 13 14 15 16 17
S T U V W X Y Z
18 19 20 21 22 23 24 25
S
We have to encrypt the message (plaintext) ‘ACT’ (n=3).
The key is ‘GYBNQKURP’ which can be written as the nxn matrix with the
 6 24 1 
help of above table as : k  13 16 10
20 17 15

Explore Electronics 11
CRYPTOGRAPHY https://deepaharivinod.blogspot.com

0
With reference to above table the message ‘ACT’ is written as vector P   2 
19

C = PK mod 26

 0   6 24 1 
C=  2  * 13 16 10 mod 26
   
19 20 17 15

 67 
C= 222 mod 26
319 

To find mode 26 divide the number by 26 & remainder will be the answer

Eg: 67 mod 26 = 15

222 mod 26 = 14

319 mod 26 = 7

Finding the corresponding letter for 15 from table 1 as P

Same way for letter for 14 as O & for letter for 7 as H

 A P
So ciphertext is POH P  C  C   O 
 
T   H 

For decryption

 6 24 1  P
k  13 16 10 C   O 
 
1
P= K ̄ C mod 26
20 17 15  H 

Explore Electronics 12
CRYPTOGRAPHY https://deepaharivinod.blogspot.com

Step 1: First find K ̄ 1  K ̄ 1 =| |


𝐴𝑑𝑗𝑜𝑖𝑛𝑡 𝐾

|𝑘| = 6(240 − 170) − 24(195 − 200) + 1(221 − 320)

=420+120-99

= 441

Step 2: find multiplicative inverse of determinant k using trial & error method

|K| ̄ 1 = 441*-- mod 26=1

Trial : 441*2mod 26= 24 not true

441*25 mod 26=1 true

|K| ̄ 1 = 25
|K| ̄ 1 = 25

Step 3: To find adjoint of matrix

The cofactor matrix consists of cofactors of the matrix A, which are calculated
according to the formula Cij=(−1)i+jMijCij=(−1)i+jMij, where Mij is the
determinant of the submatrix formed by deleting the i-th row and the j-th
column from the matrix A.

Explore Electronics 13
CRYPTOGRAPHY https://deepaharivinod.blogspot.com

After taking the transpose matrix will be

Step 4:find the corresponding positive numbers of the negative numbers in


above matrix using trial & error method

By using a equation n=q*m+r

Let n=343 then 343=--*26+---

=14*26+21 -343=21

Now n=343 then 99=--*26+---

=4*26+ 5 -99=5

-47=5

-216=18

Explore Electronics 14
CRYPTOGRAPHY https://deepaharivinod.blogspot.com

70 21 224
Now 𝐴𝑑𝑗𝑜𝑖𝑛𝑡 𝐾 =  5 70 5 
 5 378 18 

Step 5: K ̄ 1 = |K| ̄ 1 𝐴𝑑𝑗𝑜𝑖𝑛𝑡 𝐾

70 21 224 1750 525 5600


=25*  5 70 5  =  125 1750 125 
 
 5 378 18   125 9450 450 

Step 6: For simplification find K ̄ 1 mod 26

NOTE: To find mode 26 divide the number by 26 & remainder will be the
answer

 8 5 10
K̄ 1
= 21 8 21
21 12 8 

P= K ̄ 1 C mod 26

 8 5 10 15
P= 21 8 21 * 14 mod 26
21 12 8   7 

260 0  A
= 574 mod 26 =  2   C  Plain text is ACT
   
539  19 T 

POLYALPHABETIC CIPHERS
Another way to improve on the simple Monoalphabetic technique is to use
different Monoalphabetic substitutions as one proceeds through the plaintext
message. The best known, and one of the simplest, such algorithm is referred to
as the Vigenere cipher.The general name for this approach is polyalphabetic
substitution cipher. All these techniques have the following features in
common:

1. A set of related Monoalphabetic substitution rules is used.


Explore Electronics 15
CRYPTOGRAPHY https://deepaharivinod.blogspot.com

2. A key determines which particular rule is chosen for a given


transformation.

To encrypt a message, a key is needed that is as long as the message.


Usually, the key is a repeating keyword.
For example, if the keyword is ADD the message "CAD " is encrypted as
follows:
The below Table 2 is used to encrypt
KEY
A B C D E F G H I J K L MN O P Q R S T U V WX Y Z
P A A B C D E F G H I J K L MN O P Q R S T U V WX Y Z
L B B C D E F G H I J K L MN O P Q R S T U V WX Y Z A
A C C D E F G H I J K L MN O P Q R S T U V WX Y Z A B
I D D E F G H I J K L MN O P Q R S T U V WX Y Z A B C
N E E F G H I J K L MN O P Q R S T U V WX Y Z A B C D
F F G H I J K L MN O P Q R S T U V WX Y Z A B C D E
T G G H I J K L MN O P Q R S T U V WX Y Z A B C D E F
E H H I J K L MN O P Q R S T U V WX Y Z A B C D E F G
X I I J K L MN O P Q R S T U V WX Y Z A B C D E F G H
T J J K L MN O P Q R S T U V WX Y Z A B C D E F G H I

STEP 1: Find the first letter C (of CAD) in the plaintext row (as highlighted in
yellow) & A (of ADD) in key coloumn (highlighted in blue) ciphertext is C
STEP 2 : Find the second letter A (of CAD) in the plaintext row & D (of
ADD) in key coloumn ciphertext is D
STEP 1: Find the first letter D (of CAD) in the plaintext row & D (of ADD) in
key coloumn ciphertext is G
Now cipher text is CDG
Decryption: k= ADD & C=CDG

Explore Electronics 16
CRYPTOGRAPHY https://deepaharivinod.blogspot.com

PLAIN TEXT
A B C D E F G H I J K L MN O P Q R S T U V WX Y Z
K A A B C D E F G H I J K L MN O P Q R S T U V WX Y Z
E B B C D E F G H I J K L MN O P Q R S T U V WX Y Z A
Y C C D E F G H I J K L MN O P Q R S T U V WX Y Z A B
D D E F G H I J K L MN O P Q R S T U V WX Y Z A B C
E E F G H I J K L MN O P Q R S T U V WX Y Z A B C D
F F G H I J K L MN O P Q R S T U V WX Y Z A B C D E
G G H I J K L MN O P Q R S T U V WX Y Z A B C D E F
H H I J K L MN O P Q R S T U V WX Y Z A B C D E F G
I I J K L MN O P Q R S T U V WX Y Z A B C D E F G H
J J K L MN O P Q R S T U V WX Y Z A B C D E F G H I

STEP 1: Find the first letter A (of ADD) in the key row (as highlighted in
yellow) & find C in that & check for ciphertext in respective coloumn that is C
STEP 2 : Find the second letter D (of ADD) in the key row (as highlighted in
blue) & find D in that & check for ciphertext in respective coloumn that is A
STEP 3 : Find thethird letter D (of ADD) in the key row (as highlighted in
orange) & find G in that & check for ciphertext in respective coloumn that is D
Decrypted plain text is CAD

One-Time Pad
The ultimate defense against such a cryptanalysis is to choose a keyword
that is as long as the plaintext and has no statistical relationship to it. Such a
system was introduced by an AT&T engineer named Gilbert Vernam in 1918.
His system works on binary data (bits) rather than letters.

Explore Electronics 17
CRYPTOGRAPHY https://deepaharivinod.blogspot.com

The cipher text is generated by performing the bitwise XOR of the plaintext and
the key. Because of the properties of the XOR, decryption simply involves the
same bitwise operation.
The system can be expressed succinctly as follows

TRANSPOSITION TECHNIQUES

1) Rail-Fence Technique
Transposition Techniques are based on the permutation of the plain-text
instead of substitution. A very different kind of mapping is achieved by
performing some sort of permutation on the plaintext letters. This technique is

Explore Electronics 18
CRYPTOGRAPHY https://deepaharivinod.blogspot.com

referred to as a transposition cipher. 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 encipher the message "meet me after the toga party" with a rail
fence of depth 2, we write the following:
m e m a t r h t g p r y
e t e f e t e o a a t

The encrypted message is “mematrhtgpryetefeteoaat “.

2) Columnar Transition Technique


It is a slight variation to the Rail-fence technique, let’s see its algorithm:

1. In a rectangle of pre-defined size, write the plain-text message row by


row.
2. Read the plain message in random order in a column-wise fashion. It
can be any order such as 2, 1, 3 etc.
3. Thus Cipher-text is obtained.

For example Original message: "INCLUDEHELP IS AWESOME".

Now we apply the above algorithm and create the rectangle of 4 columns
(we decide to make a rectangle with four column it can be any number.)

Now let’s decide on an order for the column as 4, 1, 3 and 2 and now we will
read the text in column-wise.

Explore Electronics 19
CRYPTOGRAPHY https://deepaharivinod.blogspot.com

Cipher-text: LHIEEIUESSCEPWMNDLAO

EUCLIDEAN ALGORITHM

One of the basic techniques of number theory is the Euclidean algorithm,


which is a simple procedure for determining the greatest common divisor of two
positive integers.

Greatest Common Divisor


Nonzero b is defined to be a divisor of a if a = mb for some m, where a,
b, and m are integers. We will use the notation gcd(a, b) to mean the greatest
common divisor of a and b. The positive integer c is said to be the greatest
common divisor of a and b if
1. c is a divisor of a and of b;
2. any divisor of a and b is a divisor of c.
An equivalent definition is the following:
gcd(a, b) = max[k, such that k|a and k|b]
Because we require that the greatest common divisor be positive,
gcd(a, b) = gcd(a, b) = gcd(a, b) = gcd(a, b). In general, gcd(a, b) = gcd(|a|,
|b|).

Finding the Greatest Common Divisor

The Euclidean algorithm is based on the following theorem: For any


nonnegative integer a and any positive integer b,

The algorithm assumes a > b > 0. It is acceptable to restrict the algorithm


to positive integers because gcd(a, b) = gcd(|a|, |b|).
Explore Electronics 20
CRYPTOGRAPHY https://deepaharivinod.blogspot.com

The algorithm has the following progression:

Example: Find the gcd(25,60)

Answer is 5

MODULAR ARITHMETIC

Explore Electronics 21
CRYPTOGRAPHY https://deepaharivinod.blogspot.com

Given any positive integer n and any nonnegative integer a, if we divide a by n,


we get an integer quotient q and an integer remainder r that obey the following
relationship:

Equation 4-1

where is the largest integer less than or equal to Figure demonstrates that,
given a and positive n, it is always possible to find q and r that satisfy the
preceding relationship. Represent the integers on the number line; a will fall
somewhere on that line (positive a is shown, a similar demonstration can be
made for negative a). Starting at 0, proceed to n, 2n, up to qn such that qn q+
1)n > a. The distance from qn to a is r, and we have found the unique values
of q and r. The remainder r is often referred to as a residue.

Figure : The Relationship a = qn + r, 0 n

.
f a is an integer and n is a positive integer, we define a mod n to be the
remainder when a is divided by n. The integer n is called the modulus. Thus, for
any integer a, we can always write:

a = n x a mod n)

Explore Electronics 22
CRYPTOGRAPHY https://deepaharivinod.blogspot.com

11 mod 7 = 4; -11 mod 7 = 3

Two integers a and b are said to be congruent modulo n, if

(a mod n) = (b mod n). This is written as a n).

Note:

Converting positive numbers

Example:

n=q*m+r

1) find 51 mod 10
solution: 51= q*10+r

51= 5*10+1 answer is 1


2) find 27 mod 6
solution: 27= q*6+r

27= 4*6+3 answer is 3

Converting negative numbers

Explore Electronics 23
CRYPTOGRAPHY https://deepaharivinod.blogspot.com

Example:

n=q*m+r

1) find -51 mod 10


solution: -51= q*10+r
using trial & errror method
10*q= greater value than 51
=10*6=60
60-51=9
-51= 6*10+9 answer is 9
2) find -27 mod 6
solution: -27= q*6+r
using trial & errror method
6*q= greater value than 27
=4*6=28
28-27=1
-27= 4*10+1 answer is 1
3) find -37 mod 5
solution: -37= q*5+r
using trial & errror method
5*q= greater value than 37
=8*5=40
40-37=3
-37= 6*6+3 answer is 3

Explore Electronics 24

You might also like