0% found this document useful (0 votes)
9 views

LECTURES Information Security Notes

The document discusses different techniques of cryptography including Caesar cipher, monoalphabetic cipher, Playfair cipher and Vigenère cipher. It explains how to encrypt and decrypt text using each of these techniques through examples.

Uploaded by

Ahmad Raza
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

LECTURES Information Security Notes

The document discusses different techniques of cryptography including Caesar cipher, monoalphabetic cipher, Playfair cipher and Vigenère cipher. It explains how to encrypt and decrypt text using each of these techniques through examples.

Uploaded by

Ahmad Raza
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 42

Advanced Network Security & Cryptography

Ceaser Cipher:

In ceaser cipher every alphabet has a specific no. as under,

1. Draw a matrix of alphabetic A to Z


2. Give the index 0 to 25 to each alphabetic
3. In case of Encryption, we add the each alphabetic index and key, if there sum is greater than 25
then we take MOD of 26 the answer of MOD is used as an index of Cipher Text.
4. In case of decryption, we subtract the key from the index of Cipher Text; if the result is in
positive form then use the result as an index of the alphabetic, otherwise if the result is in
negative form then we add the negative result with 26. i.e. if the Cipher Alphabetic is G.
Cipher = G (index is 6)
Key = 8
Then 6 – 8 = -2 (Result is Negative)
So 26 + (-2) = 26 – 2 = 24 which is Y

Step # 1: Draw a table or matrix of all alphabetic and give them index starts from 0 and end with 25.

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

Step # 2: add the index of the plain text alphabetic with the key. Where Plain Text = HELLO and key is 8,
H has an index 7, so we add 8 + 7 = 15 so result is less than 26 so the Cipher index is 15 which is P.

Encryption

If we have the following plan text, and the KEY= 8

Plain text = HELLO


Cipher = PMTTW

H = 7, Key = 8 so 7 + 8 = 15 (P)
E = 4, key = 8 so 4 + 8 = 12 (M)
L = 11, Key = 8 so 11 + 8 = 19 (T)
L = 11, Key = 8 so 11 + 8 = 19 (T)
O = 14, Key = 8 so 14 + 8 = 22 (W)

Thus the Cipher = PMTTW of the Plain Text HELLO

P a g e | 1 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University, Islamabad
Advanced Network Security & Cryptography

Decryption

Cipher = PMTTW
P = 15, Key = 8, so 15 – 8 = 7 (H)
M = 12, Key = 8, so 12 – 8 = 4 (E)
T = 19, Key = 8, so 19 - 8 = 11 (L)
T = 19, Key = 8, so 19 - 8 = 11 (L)
W = 22, key = 8, so 22 – 8 = 14 (O)
So Cipher PMTTW has a Plain Text HELLO
Plain text = HELLO

Example # 2:
Encryption

key = 7
Plain text = PAKISTAN

P = 15, Key = 7, so 15 + 7 = 22 (W)


A = 0, Key = 7, so 0 + 7 = 7 (H)
K = 10, key = 7, so 10 + 7 = 17 (R)
I = 8, Key = 7, so 8 + 7 = 15 (P)
S = 18, Key = 7, so 18 + 7 = 25 (Z)
T = 19, Key = 7, so 19 + 7 = 26 > 25 so 26 MOD 26 = 0 (A)
A = 0, Key = 7, so 0 + 7 = 7 (H)
N = 13, key 7, so 13 + 7 = 20 (U)

Cipher = WHRPZAHU

Decryption
When we want to perform decryption then subtract the “key” from cipher text.

Cipher = WHRPZAHU

W = 22, Key = 7, so 22 – 7 = 15 (P)


H = 7, Key = 7, so 7 - 7 = 0 (A)
R = 17, key = 7, so 17 – 7 = 10 (K)
P = 15, key = 7, so 15 – 7 = 8 (I)
Z = 25, key = 7, so 25 – 7 = 18 (S)
A = 0, key = 7, so 0 – 7 = -7 < 0, so 26 + (– 7) = 19 (T)
H = 7, Key = 7, so 7 - 7 = 0 (A)
U = 20, key = 7, so 20 – 7 = 13 (N)

Plain text = PAKISTAN

P a g e | 2 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University, Islamabad
Advanced Network Security & Cryptography

Mono Alphabetic:
In mono alphabetic each alphabet is replace with another alphabet as in the following table.

G C K X Y Z
A B C D E F
O N P M Q R
G H I J K L
U V W S T A
M N O P Q R
B H D E F L
S T U V W X
J I
Y Z

Example:
Plain text = PAKISTAN
Cipher = SGQPBHGV
Here “P” is replaced with its equivalent letter “S” and onward.

Play Fair Technique:

In play fair technique we make a key-table which is 5*5 length as under.


Example:
Plain text = PAKISTAN
Key = NETWORK SECURITY

Key-Table
Write the key letters in key-table, no letter will repeat and remain cells are filled by remaining
alphabet as under.

N E T W O
R K S C U
I/J Y A B D
F G H L M
P Q V X Z

There are following conditions to make the Cipher.


1) Make the pairs of plain text, if there are odd letters in plain text then add “ X “ in the end to
make it even.
2) If there are two consective same letters in plain text then add “ X “ between them.
e.g ( HAPPY = HAPXPY ).
3) To make cipher if the letters of plain text are in same row or same column then the cipher is
Next letter.
4) If the letters of plain text are not in same row or column then cipher is there correspondence
letters.

P a g e | 3 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University, Islamabad
Advanced Network Security & Cryptography

5) In case of decryption, if same row or column then take previous (backword) letter.

Encryption

Plain text = PA KI ST AN
Cipher = VI RY AS IT

Pair 1= PA See the P in A column and its correspondence letter is “ V “, and see A in P column and its
correspondence letter is “ I “.
Pair 2= KI See the K in I column and its correspondence letter is “ R “, and see I in K column and its
correspondence letter is “ Y “.
Pair 3= ST Here S and T are in same column so the next letter of S is “ A “ and T is “ S “.
Pair 4= AN See A in N column and its correspondence letter is “ I “ and see N in A column and its
correspondence letter is “ T “.

Decryption
Perform reverse procedure to convert the cipher into plain text.

P a g e | 4 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University, Islamabad
Advanced Network Security & Cryptography

Vigener Cipher:

In vigener the key-table is 26*26 length as under.


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
F 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 E
G G H I J K L M N O P Q R S T U V W X Y Z A B C D E F
H H I J K L M N O P Q R S T U V W X Y Z A B C D E F G
I I J K L M N O P Q R S T U V W X Y Z A B C D E F G H
J J K L M N O P Q R S T U V W X Y Z A B C D E F G H I
K K L M N O P Q R S T U V W X Y Z A B C D E F G H I J
L L M N O P Q R S T U V W X Y Z A B C D E F G H I J K
M M N O P Q R S T U V W X Y Z A B C D E F G H I J K L
N N O P Q R S T U V W X Y Z A B C D E F G H I J K L M
O O P Q R S T U V W X Y Z A B C D E F G H I J K L M N
P P 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
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
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
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
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

Encryption
Plain text = NETWORK  Row
Key = SECURITY  Column
See the plain text in row in the key column to make the cipher.

Plain text = NETWORK


Cipher = FIVQFZD
Decryption
Cipher = FIVQFZD
Key = SECURITY  Column
See the key S (Column) and find the Cipher F in S Column where we find F that row is our Plain Text. For
example we find F from the key column S which is nth row so plain text is N.

P a g e | 5 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University, Islamabad
Advanced Network Security & Cryptography

Note: if key letter is less than the letters of plain text then repeat the key. e.g

Plain text = PAKIS TAN


Key = HELLO HEL

Vigener Cipher With Auto-Key:


In vigener cipher with auto-key , if plain text letters is less than key letters then add plain text as
a key letters. e.g.

Plain text = PAKIS TAN


Key = HELLO PAK

Vigener Cipher With One Time Pad:


In this cipher the plain text and key has equal letter length. E.g

Plain text = NETWORK SECURITY  15 Letters


Key = CRYPTOGRAPHY AND  15 Letters

Vernam Cipher:
Vernam cipher use bits to convert plaint text into cipher, it use the exclusive-OR operation. In
this cipher we convert the plaint text and key into 0,1 form first. E.g

Encryption Exclusive-OR operation


Plain text = 10010 A B A+B
Key = 11001 + 0 0 0
Cipher = 01011 0 1 1
1 0 1
Decryption 1 1 0

Cipher = 01011
Key = 11001 +
Plain text = 10010

Note: All the techniques that we read above are substitution Cipher, in which each letter is replace
with a letter.

P a g e | 6 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University, Islamabad
Advanced Network Security & Cryptography

Transposition Ciphers

1) Rail Fence Cipher:

In this cipher the plain text is write diagonally and read it horizontally to make cipher. Here no.
of rows equal to key value.
Example # 1:

Plain text = PAKISTAN


Key = 2 (shows the no. of rows)
Encryption

P K S A
A I T N

Cipher = PKSAAITN

Decryption

On decryption side count the cipher letter and divide them by key value to find how much rows
are there. Here write horizontally and read it diagonally to make plain text from cipher.
Cipher = PKSAAITN
Total letters = 8/2 = 4 (which shows the no. of letters in each rows)

P K S A
A I T N
Plain text = PAKISTAN

Example # 2:
Encryption
Plain text = CRYPTOGRAPHY AND NETWORK SECURITY
Key = 3 (shows the no. of rows)

C P G H N E O S U T
R T R Y D T R E R Y
Y O P A N W K C I

Cipher = CPGHNEOSUT RTRYDTRERY YOPANWKCI

Decryption

Cipher = CPGHNEOSUT RTRYDTRERY YOPANWKCI

P a g e | 7 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University, Islamabad
Advanced Network Security & Cryptography

Total letters = 29/3 ( first row=10 letter, second row= 10, third row=9 )

C P G H N E O S U T
R T R Y D T R E R Y
Y O P A N W K C I

Read diagonally from above,


Plain text = CRYPTOGRAPHY AND NETWORK SECURITY

P a g e | 8 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University, Islamabad
Advanced Network Security & Cryptography

2) Row Transposition:

Plain text = CRYPTOGRAPHY AND NETWORK SECURITY


Key = 1 5 4 2 3
Encryption
1 5 4 2 3
C R Y P T
O G R A P
H Y A N D
N E T W O
R K S E C
U R I T Y
To make cipher read column wise, according to the key no. i.e less no. write first and onwards.

Cipher = COHNRU PANWET TPDOCY YRATSA RGYEKR


= COHNRUPANWETTPDOCYYRATSARGYEKR
Decryption

Cipher = COHNRUPANWETTPDOCYYRATSARGYEKR
Key = 1 5 4 2 3
To convert this cipher to plain text count the cipher letters and divide with no. ok key.
Here total letters 30/5= 6 ( which shows the no. of letters in each column)

1 5 4 2 3
C R Y P T
O G R A P
H Y A N D
N E T W O
R K S E C
U R I T Y
Read row wise form above table to make plain text.

Plain text = CRYPTOGRAPHY AND NETWORK SECURITY


3) Columnar Transposition:

Plain text = CRYPTOGRAPHY AND NETWORK SECURITY


Key = 1 5 4 2 3
Encryption

1 C O H N R U
5 R G Y E K R
4 Y R A T S I
2 P A N W E T
3 T P D O C Y

P a g e | 9 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University, Islamabad
Advanced Network Security & Cryptography

To make cipher read row wise according to no. value i.e less no. read first and onwards.
Cipher = COHNRU PANWET TPDOCY YRATSA RGYEKR
= COHNRUPANWETTPDOCYYRATSARGYEKR
Decryption

Cipher = COHNRUPANWETTPDOCYYRATSARGYEKR
Key = 1 5 4 2 3

To decrypt the cipher text count the cipher letters divided it by key no. i.e.
Here total letters 30 / 5= 6 (which shows the no. of letters in each row)

1 C O H N R U
5 R G Y E K R
4 Y R A T S I
2 P A N W E T
3 T P D O C Y

Read it column wise to make plain text which is,

Plain text = CRYPTOGRAPHY AND NETWORK SECURITY

P a g e | 10 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

Hill Cipher Algorithm:

 In Hill Cipher Index of Ceaser Cipher is used.


 Plain Text is used Column Matrix.
 Key is given in Matrix Form.

Example:
Plain Text: Network
0 1 2 3 4 5
2 3
Key: A B C D E F
1 3 6 7 8 9 10 11
G H I J K L
Solution: 12 13 14 15 16 17
M N O P Q R
Encryption: 18 19 20 21 22 23
S T U V W X
Plain Text: NETWORK 24 25
Where N = 13, E = 4, T = 19, W = 22, O = 14, R = 17, K = 10 Y Z

Key is 2 x 2 so we use Pairs of Plain Text i.e. NE, TW, OR, KX

NE:

2 3 13
MOD 26
1 3 4

2 x 13+3 x 4
MOD 26
1 x 13+3 x 4

26+12
MOD 26
13+12

38
MOD 26
25

38 MOD 26 = 12 & 25 MOD 26 = 25

12 = M & 25 = Z

M
Z

CIPHER of Plain Text NE = MZ

TW:

P a g e | 11 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

T = 19, W = 22

2 3 19
MOD 26
1 3 22

2 x 19+3 x 22
MOD 26
1 x 19+3 x 22

38+66
MOD 26
19+66

104
MOD 26
85

104 MOD 26 = 0 & 85 MOD 26 = 7

0=A&7=H

A
H

CIPHER of Plain Text TW = AH

OR:

O = 14, R = 17

2 3 14
MOD 26
1 3 17

2 x 14+ 3 x 17
MOD 26
1 x 14+ 3 x 17

28+51
MOD 26
14+ 51

79
MOD 26
65

79 MOD 26 = 1 & 65 MOD 26 = 13

1 = B & 13 = N

B
N

P a g e | 12 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

CIPHER of Plain Text OR = BN

KX:

K = 10, X = 23

2 3 10
MOD 26
1 3 23

2 x 10+3 x 23
MOD 26
1 x 10+3 x 23

20+69
MOD 26
10+69

89
MOD 26
79

89 MOD 26 = 11 & 79 MOD 26 = 1

11 = L & 1 = B

L
B

CIPHER of Plain Text KX = LB

Thus
Plain Text = NE TW OR KX
Cipher = MZ AH BN LB

Decryption:

CIPHER = MZ AH BN LB

Formula:

C = K x P MOD 26
P = K-1 C (Order of K & C is important)

Adj of K
K-1 = = (Adj of K) x K-1
¿ A∨¿ ¿

P a g e | 13 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

2 3
K=
1 3
 In Adj of K interchange a11 with a22 and change the sign of a12 & a21

3 −3
Adj of K =
−1 2

|K| = (a11 x a22) – (a12 x a21)


|K| = (3 x 2) – (3 x 1)
|K| = 6 – (3) = 6 – 3 = 3

K-1 = Inverse 1
(Row x col) MOD 26
0 1 2 3 4 5 6 7 8 9 1 11 1 13 14 1 16 1 18 1 20 2 22 2 24 2
0 2 5 7 9 1 3 5
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 1 2 3 4 5 6 7 8 9 1 11 1 13 14 1 16 1 18 1 20 2 22 2 24 2
0 2 5 7 9 1 3 5
2 0 2 4 6 8 10 1 14 1 18 2 22 2 0 2 4 6 8 10 1 14 1 18 2 22 2
2 6 0 4 2 6 0 4
3 0 3 6 9 1 15 1 21 2 1 4 7 1 13 16 1 22 2 2 5 8 1 14 1 20 2
2 8 4 0 9 5 1 7 3
4 0 4 8 12 1 20 2 2 6 10 1 18 2 0 4 8 12 1 20 2 2 6 10 1 18 2
6 4 4 2 6 4 4 2
5 0 5 1 15 2 25 4 9 1 19 2 3 8 13 18 2 2 7 12 1 22 1 6 1 16 2
0 0 4 4 3 7 1 1
6 .
. .
. .
2 .
5

 3’s inverse is 9
 5’s inverse is 21

|K| = 6 – (3) = 6 – 3 = 3

K-1 = 3-1 = 9 (From Modulus arithmetic of 3 is 9)

Now Formula:

K-1 = (Adj of K) x K-1 MOD 26

3 −3 -1
K-1 = 3 Mod 26
−1 2

3 −3
9 MOD 26
−1 2

3 x 9 −3 x 9
MOD 26
−1 x 9 2 x 9

27 MOD 26 −27 MOD 26


−9 MOD 26 18 MOD 26

P a g e | 14 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

27 MOD 26 = 1, -27 MOD 26 = -27 + 26 = -1 + 26 = 25, -9 MOD 26 = -9 + 26 = 17, 18 MOD 26 = 18

1 25
K-1 =
17 18

CIPHER = MZ AH BN LB

MZ:

M = 12, Z = 25

P = K-1 C Mod 26

1 25 M
P= MOD 26
17 18 Z

1 25 12
P= MOD 26
17 18 25

1 x 12+25 x 25
P= MOD 26
17 x 12+18 x 25

12+ 625
P= M OD 26
204+ 450

637
P= M OD 26
654

637 MOD 26
P=
654 MOD 26

13
P=
4

N
P=
E

Thus MZ = NE

CIPHER = AH BN LB

AH:

A = 0, H = 7

P = K-1 C Mod 26

P a g e | 15 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

1 25 A
P= MOD 26
17 18 H

1 25 0
P= MOD 26
17 18 7

1 x 0+ 25 x 7
P= MOD 26
17 x 0+18 x 7

0+175
P= M OD 26
0+126

175
P= M OD 26
126

175 MOD 26
P=
126 MOD 26

19
P=
22

T
P=
W

Thus AH = TW

CIPHER = BN LB

BN:

B = 1, N = 13

P = K-1 C Mod 26

1 25 B
P= MOD 26
17 18 N

1 25 1
P= MOD 26
17 18 13

1 x 1+25 x 13
P= MOD 26
17 x 1+18 x 13

1+325
P= M OD 26
17+234

326
P= M OD 26
251

P a g e | 16 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

326 MOD 26
P=
251 MOD 26

14
P=
17

O
P=
R

Thus BN = OR

CIPHER = LB

LB:

L = 11, B = 1

P = K-1 C Mod 26

1 25 L
P= MOD 26
17 18 B

1 25 11
P= MOD 26
17 18 1

1 x 11+ 25 x 1
P= MOD 26
17 x 11+18 x 1

11+25
P= M OD 26
187+18

36
P= M OD 26
205

36 MOD 26
P=
205 MOD 26

10
P=
23

K
P=
X

Thus LB = KX

Thus

Cipher Text = MZ AH BN LB

P a g e | 17 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

Plain Text = NE TW OR KX

P a g e | 18 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

Data Encryption Standard (DES):

The Data Encryption Standard (DES) is a symmetric-key block cipher published by the National
Institute of Standards and Technology (NIST).

DES is a block cipher, as shown in Figure.

Encryption and decryption with DES

DES STRUCTURE

The encryption process is made of two permutations (P-boxes), which we call initial and final
permutations, and sixteen Feistel rounds.

General structure of DES

P a g e | 19 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

Initial and Final Permutations

Initial and final permutation steps in DES

Initial and final permutation tables

How to read this table?

The 58th bit of input x will be the first bit of output IP(x), the 50th bit of x is the second bit of IP(x), etc.

P a g e | 20 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

The initial and final permutations are straight P-boxes that are inverses of each other. They have no
cryptography significance in DES

Example 1

Find the output of the initial permutation box when the input is given in hexadecimal as:

Solution

Only bit 25 and bit 64 are 1s; the other bits are 0s. In the final permutation, bit 25 becomes bit 64 and
bit 63 becomes bit 15. The result is

Rounds

DES uses 16 rounds. Each round of DES is a Feistel cipher.

A round in DES
(encryption site)

Expansion P-box

Since RI−1 is a 32-bit input and KI is a 48-bit key, we first need to expand RI−1 to 48 bits.

Expansion
permutation

P a g e | 21 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

Although the relationship between the input and output can be defined mathematically,

Expansion P-box table

P a g e | 22 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

Example:

Plain Text: FA39015B AB012359

Step # 1:

 Convert the plain text in hexadecimal form, and index it from 1 to 64.
 The divide the bits into two half of 32 bit each. (Left & Right Half)
 First 32 bits are left part (1-32 index) and last 32 bits are right part (33-64 index)

F = 1111 A = 1010 3 = 0011 9 = 1001 0 = 0000 1 = 0001 5 = 0101 B = 1011

A = 1010 B = 1011 0 = 0000 1 = 0001 2 = 0010 3 = 0011 5 = 0101 9 = 1001

Left Part: (index 1 to 32)

F = 1111 A = 1010 3 = 0011 9 = 1001 0 = 0000 1 = 0001 5 = 0101 B = 1011


1 2 3 4 5 6 7 8 9 10 11 12 1 14 15 16 1 18 19 20 2 22 23 24 2 26 27 28 2 30 31 32
3 7 1 5 9
1 1 1 1 1 0 1 0 0 0 1 1 1 0 0 1 0 0 0 0 0 0 0 1 0 1 0 1 1 0 1 1

Right Part: (index 33 to 64)

A = 1010 B = 1011 0 = 0000 1 = 0001 2 = 0010 3 = 0011 5 = 0101 9 = 1001


33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
1 0 1 0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 1 1 0 0 1

Step # 2:

 Now we perform operations (Initial Permutation) on the Right Half (Part) and then XOR with the
Left Half (Part).

P a g e | 23 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

Using Initial Permutation:


1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2
1 1 1 1 1 0 1 0 0 0 1 1 1 0 0 1 0 0 0 0 0 0 0 1 0 1 0 1 1 0 1 1

3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6
3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
1 0 1 0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 1 1 0 0 1

1 0 0 0 1 26 0 18 0 1
58 50 42 34 10 02
1 0 0 0 1 28 0 20 1 1
60 52 44 36 12 04
0 0 0 0 0 30 0 0 0
62 54 46 38 22 14 06
1 64 1 56 1 1 40 1 32 1 1 0
48 24 16 08
0 57 0 49 0 1 0 25 0 0 1
41 33 17 09 01
0 59 1 51 0 43 1 35 0 27 0 1 1
19 11 03
1 61 0 53 0 45 1 37 1 29 0 1 1
21 13 05
0 63 1 55 0 47 1 39 1 31 0 0 1
23 15 07

1 0 0 0 1 0 0 1
1 0 0 0 1 0 1 1
0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 0
0 0 0 1 0 0 0 1
0 1 0 1 0 0 1 1
1 0 0 1 1 0 1 1
0 1 0 1 1 0 0 1

Left Half
1 0 0 0 1 0 0 1
1 0 0 0 1 0 1 1
0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 0
Right Half
0 0 0 1 0 0 0 1
0 1 0 1 0 0 1 1
1 0 0 1 1 0 1 1
0 1 0 1 1 0 0 1

P a g e | 24 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

Step # 3:

 Make each 8 bits of the Right Half to 4 Bits


 Then using the P-Box convert each 4 bits to 6 bits.

Expansion P-box table

Previous Next bit


Actual
bit index bits index index

Right Half
0 0 0 1 0 0 0 1
0 1 0 1 0 0 1 1
1 0 0 1 1 0 1 1
0 1 0 1 1 0 0 1

According to Expansion Table Bit #: 32, 01, 02,03,04,05 and values are 100010

P a g e | 25 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

DES: S-boxes

S1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

0 14 4 13 1 2 15 11 8 3 10 6 12 5 9 0 7

1 0 15 7 4 14 2 13 1 10 6 12 11 9 5 3 8

2 4 1 14 8 13 6 2 11 15 12 9 7 3 10 5 0

3 15 12 8 2 4 9 1 7 5 11 3 14 10 0 6 13

100010:

Last & First bit: 10 which is 2 (row # 2)

Middle Four bits = 0001 which is 1 (column # 1)

See S-Box (S1) row # 2 & column # 1 from S1 (S-Box)

Row # 2 & Column # 1 (S1): 1


1 in hexadecimal: 0001

S2 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

0 15 1 8 14 6 11 3 4 9 7 2 13 12 0 5 10

1 3 13 4 7 15 2 8 14 12 0 1 10 6 9 11 5

2 0 14 7 11 10 4 13 1 5 8 12 6 9 3 2 15

3 13 8 10 1 3 15 4 2 11 6 7 12 0 5 14 9

100010:

Last & First bit: 10 which is 2 (row # 2)

Middle Four bits = 0001 which is 1 (column # 1)

See S-Box (S2) row # 2 & column # 1 from S2 (S-Box)


Row # 2 & Column # 1 (S2) = 14
14 in hexadecimal = 1110

P a g e | 26 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

S3 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

0 10 0 9 14 6 3 15 5 1 13 12 7 11 4 2 8

1 13 7 0 9 3 4 6 10 2 8 5 14 12 11 15 1

2 13 6 4 9 8 15 3 0 11 1 2 12 5 10 14 7

3 1 10 13 0 6 9 8 7 4 15 14 3 11 5 2 12

101010:

Last & First bit: 10 which is 2 (row # 2)

Middle Four bits = 0101 which is 5 (column # 5)

See S-Box (S3) row # 2 & column # 5 from S3 (S-Box)

Row # 2 & Column # 5 (S3): 15

15 in hexadecimal = 1111

S4 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

0 7 13 14 3 0 6 9 10 1 2 8 5 11 12 4 15

1 13 8 11 5 6 15 0 3 4 7 2 12 1 10 14 9

2 10 6 9 0 12 11 7 13 15 1 3 14 5 2 8 4

3 3 15 0 6 10 1 13 8 9 4 5 11 12 7 2 14

100111:

Last & First bit: 11 which is 3 (row # 3)

Middle Four bits = 0011 which is 3 (column # 3)

See S-Box (S4) row # 3 & column # 3 from S4 (S-Box)


Row # 3 & Column # 3 (S4): 6
6 in hexadecimal: 0110

S5 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

0 2 12 4 1 7 10 11 6 8 5 3 15 13 0 14 9

1 14 11 2 12 4 7 13 1 5 0 15 10 3 9 8 6

2 4 2 1 11 10 13 7 8 15 9 12 5 6 3 0 14

P a g e | 27 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

3 11 8 12 7 1 14 2 13 6 15 0 9 10 4 5 3

110011:

Last & First bit: 11 which is 3 (row # 3)

Middle Four bits = 1001 which is 9 (column # 9)

See S-Box (S5) row # 3 & column # 9 from S5 (S-Box)


Row # 3 & Column # 9 (S5): 15
15 in hexadecimal: 1111

S6 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

0 12 1 10 15 9 2 6 8 0 13 3 4 14 7 5 11

1 10 15 4 2 7 12 9 5 6 1 13 14 0 11 3 8

2 9 14 15 5 2 8 12 3 7 0 4 10 1 13 11 6

3 4 3 2 12 9 5 15 10 11 14 1 7 6 0 8 13

110110:

Last & First bit: 10 which is 2 (row # 2)

Middle Four bits = 1011 which is 11 (column # 11)

See S-Box (S6) row # 2 & column # 11 from S6 (S-Box)

Row # 2 & Column # 11 (S6): 10


10 in hexadecimal: 1010

S7 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

0 4 11 2 14 15 0 8 13 3 12 9 7 5 10 6 1

1 13 0 11 7 4 9 1 10 14 3 5 12 2 15 8 6

2 1 4 11 13 12 3 7 14 10 15 6 8 0 5 9 2

3 6 11 13 8 1 4 10 7 9 5 0 15 14 2 3 12

101011:

Last & First bit: 11 which is 3 (row # 3)

P a g e | 28 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

Middle Four bits = 0101 which is 5 (column # 5)

See S-Box (S7) row # 3 & column # 5 from S7 (S-Box)

Row # 3 & Column # 5 (S7): 4


4 in hexadecimal: 0100

S8 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

0 13 2 8 4 6 15 11 1 10 9 3 14 5 0 12 7

1 1 15 13 8 10 3 7 4 12 5 6 11 0 14 9 2

2 7 11 4 1 9 12 14 2 0 6 10 13 15 3 5 8

3 2 1 14 7 4 10 8 13 15 12 9 0 3 5 6 11

110010:

Last & First bit: 10 which is 2 (row # 2)

Middle Four bits = 1001 which is 9 (column # 9)

See S-Box (S8) row # 2 & column # 9 from S8 (S-Box)

Row # 2 & Column # 9 (S8): 6

6 in hexadecimal: 0110

0001 1110

1111 0110

1111 1010

0100 0110

Step # 4:

Straight permutation
table

P a g e | 29 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

0 1 1 1 0 29 0 12 0 1
16 07 20 21 28 17
0 1 1 1 1 05 1 18 1 1
01 15 23 26 31 10
0 0 0 1 0 32 1 0 1
02 08 24 14 27 03 09
1 19 0 13 1 1 06 0 22 1 1 0
30 11 04 25

XOR with Left Part:

01110001 (Right)
XOR 10001001 (Left)
------------------------------------------
11111000

01111111 (Right)
XOR 10001011 (Left)
---------------------------------------
11110100

00010101 (Right)
XOR 00000000 (Left)
-------------------------------------
00010101

10110110 (Right)
XOR 11111110 (Left)
--------------------------------
01001000

P a g e | 30 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

P a g e | 31 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

Left Part: Right Part:

01111000 11111000
10110101 11110100
00010001 00010101
01000100 01001000

+
Next Left Part:

11111000 Next Right Part:


11110100
01111000
00010101
10110101
01001000
00010001
01000100

P a g e | 32 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

Key Generation:

0X AB012345FE678DC9

A = 1010 B = 1011 0 = 0000 1 = 0001


2 = 0010 3 = 0011 4 = 0100 5 = 0101
F = 1111 E = 1110 6 = 0110 7 = 0111
8 = 1000 D = 1101 C = 1100 9 = 1001

1 1 0 1 0 25 0 17 0 1
57 49 41 33 09 01
1 0 1 1 1 26 0 18 0 0
58 50 42 34 10 02
0 0 1 1 0 27 1 0 1
59 51 43 35 19 11 03
0 60 0 0 1 36 0 63 0 1 1
52 44 55 47 39
0 31 1 0 1 0 62 1 1 1
23 15 07 54 46 38
1 30 0 0 0 06 1 61 1 0 1
22 14 53 45 37
0 29 0 0 1 05 0 28 0 0 0
21 13 20 12 04

Left Part Shift:

Left Part: 1101000110111000001101010001

Left Part Shift: 1010001101110000011010100011

Right Part Shift:

Right Part: 0011010101111000110100010000

Right Part Shift: 0110101011110001101000100000

Compression Table:

0 0 1 0 1 01 0 05 1 1
14 17 11 24 03 28
0 0 1 1 1 23 1 19 1 0
15 06 21 10 12 04
0 1 0 1 1 27 0 0 0
26 08 16 07 20 13 02
0 41 0 1 1 1 47 0 1 1
52 31 37 55 30 40
1 51 1 1 0 1 44 0 1 0
45 33 48 49 39 56
0 34 0 0 0 0 50 0 0 0
53 46 42 36 29 32

P a g e | 33 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

Key:
0010 1011
0011 1110
0101 1000
0011 1011
1110 1010
0000 0000

P a g e | 34 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

Advanced Encryption Standard (AES):

AES Conceptual Scheme:

Example:

Plain Text: 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF

Key: FF EE DD CC BB AA 99 88 77 66 55 44 33 22 11 00

W0 W1 W2 W3

Step # 1: Convert the plain text in states, convert plain text Column Wise & Key Row Wise

Plain Text States Col. Wise KEY Row. Wise


00 44 88 CC FF EE DD CC
11 55 99 DD BB AA 99 88
22 66 AA EE 77 66 55 44
33 77 BB FF 33 22 11 00

Step # 2: XOR both Plain Text & Key

00 = 0000 0000

FF = 1111 1111 (XOR)

--------------------------------------

FF = 1111 1111

--------------------------------------

44 = 0100 0100

EE = 1110 1110 (XOR)

---------------------------------------

AA = 1010 1010 and so on……..

P a g e | 35 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

After XOR (both plain text & Key) table show below:

After Pre Round


FF AA 55 00
AA FF 00 55
55 00 FF AA
00 55 AA FF

Note: First & Second Round is called Add Round

Step # 3: (First Round)

In this step we shift cells as under:

 First Row as it is (no change)


 Second Row one cell right shift
 Third Row two cells right shift
 Fourth Row three cells right shift

After Pre Round After Shift Rows


FF AA 55 00 FF AA 55 00
AA FF 00 55 55 AA FF 00
55 00 FF AA FF AA 55 00
00 55 AA FF 55 AA FF 00

Step # 4:

Substitute byte by using Sub Byte Table

P a g e | 36 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

FF means F row and F column (in substitution Table)

After Substitution
16 AC FC 63
FC AC 16 63
16 AC FC 63
FC AC 16 63

Note: We skip mix round at this time.

Step # 4: Now we make w4, w5, w6, w7 (key guarantor)

W4 = w0 XOR T4

W5 = w1 XOR w4

W6 = w2 XOR w5

W7 = w3 XOR w6

T4 =?

1. T4 = Rotate (W3) w3 means previous


2. Then on its result perform subbyte
3. Xor with round constant (formula = 2 n – 1 where n is round number)

W3 = 33 22 11 00

1. Rotate right one then it is like this 00 33 22 11


2. By using Sub Byte Table 63 C3 93 82
3. Round constant ( 2 1-1 = 20 = 1) then XOR 63 C3 93 82 with 1

0110 0011 1100 0011 1001 0011 1000 0010

0000 0000 0000 0000 0000 0000 0000 0001 XOR

-------------------------------------------------------------

0110 0011 1100 0011 1001 0011 1000 0011

63 C3 93 83

T4 = 63 C3 93 83

Thus

P a g e | 37 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

W4 = W0 XOR T4

W0 = FF EE DD CC

T4 = 63 C3 93 83 (XOR)

1111 1111 1110 1110 1101 1101 1100 1100

0110 0011 1100 0011 1001 0011 1000 0011 (XOR)

-----------------------------------------------------------------------

1001 1100 0010 1101 0100 1110 0100 1111

9C 2D 4E 4F

W4 = 9C 2D 4E 4F

W5 = ?

W5 = W1 XOR W4

W1 = BB AA 99 88

W4 = 9C 2D 4E 4F

1011 1011 1010 1010 1001 1001 1000 1000

1001 1100 0010 1101 0100 1110 0100 1111 (XOR)

0010 0111 1000 0111 1101 0111 1100 0111

27 87 D7 C7

W5 = 27 87 D7 C7

W6 = ?

W6 = W2 XOR W5

W2 = 77 66 55 44

W5 = 27 87 D7 C7

P a g e | 38 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

0111 0111 0110 0110 0101 0101 0100 0100

0010 0111 1000 0111 1101 0111 1100 0111 (XOR)

0101 0000 1110 0001 1000 0010 1000 0011

50 E1 82 83

W6 = 50 E1 82 83

W7 = ?

W7 = W3 XOR W6

W3 = 33 22 11 00

W6 = 50 E1 82 83

0011 0011 0010 0010 0001 0001 0000 0000

0101 0000 1110 0001 1000 0010 1000 0011 (XOR)

0110 0011 1100 0011 1001 0011 1000 0011

63 C3 93 83

W7 = 63 C3 93 83

Note:

 Mix column is not perform in final round


 128, 10 round
 256, 14 round

Pre Round: -

Plain Text XOR Key (W0 – W3)

Then Round # 1:

1. Sub Byte
2. Shift Rows
3. Mix Column
4. Add round Key (W4-W7)

Note: First is substitute row, then perform shift rows. In animation shift is column wise but we perform
only row wise.

P a g e | 39 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

Ravist Shanon Adleman (RSA):


 It is public key algorithm
 Public key is for encryption
 Private key is for decryption

Encryption (e, n) Public Key Decryption (d, n) Private Key


C = pe mod n P = cd mod n

How to Make a Public Key & Private Key:-

1. Choose two large prime numbers p & q.


2. Calculate n where n = p x q
3. Calculate ɸ(n) = (p-1) (q-1)
4. Choose any random number e.
5. Calculate d where e.d mod ɸ(n) = 1 (it means that e-1 for mod ɸ(n))
6. Encryption c = pe mod n
7. Decryption p = cd mod n

Note: Step # 1 to Step # 4 for public key. And step # 5 is for private key.

Example:

P = 3, q = 5

n = p x q = 3 x 5 = 15

ɸ (n) = (p-1) (q-1)

= (3-1) (5-1) = 2 x 4 = 8

Assume e = 11

Find d =? Where ɸ (n) = 8

e.d mod ɸ (n) = 1

11 x 1 mod 8 = 3

11 x 2 mod 8 = 6

11 x 3 mod 8 = 1 (Inverse)

So e = 11 and d = 3

P a g e | 40 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

Thus public key = (e, n) = (11, 15)

Private Key = (d, n) = (3, 15)

Encryption:

Assume p = 2

C = pe mod n

= 211 mod 15

= 2048 mod 15

C=8

Decryption:

P = Cd mod n

= 83 mod 15

= 512 mod 15

P=2

Example # 2:

P = 5, q = 7, e = 5

n = p x q = 5 x 7 = 35

ɸ (n) = (p-1) (q-1)

= (5-1) (7-1) = 4 x 6 = 24

e = 5, d =?

e x d mod ɸ (n)

5 x 1 mod 24 = 5

5 x 2 mod 24 = 10

5 x 3 mod 24 = 15

5 x 4 mod 24 = 20

P a g e | 41 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad
Advanced Network Security & Cryptography

5 x 5 mod 24 = 1 (Inverse)

d=5

Public Key = (e, n) = (5, 35)

Private Key = (d, n) = (5, 35)

Encryption:

Plain Text (P) = 2

C = pe mod n

= 25 mod 35

= 32 mod 35 = 32

C = 32

Decryption:

P = Cd mod n

= 325 mod 35

= 33554432 mod 35

P=2

P a g e | 42 Prepared By: Rana Javed Rashid (PhD Scholar), Islamic International University,
Islamabad

You might also like