Cryptography and Network Security
Module 1.
Chapter 1 : A Model for Network Security
1.1 Why Network Security is needed
Modern networks carry sensitive data (credentials, financial records, academic
data). Threats include:
Eavesdropping (sniffing packets)
Tampering (altering data in transit)
Impersonation (spoofing sender/receiver)
Replay (reusing captured messages)
Denial of Service (service disruption)
1.2 Security Goals (CIA+)
Confidentiality: Only authorized users read data
Integrity: Data is not altered undetected
Authentication: Verify identities
Non-repudiation: Sender cannot deny sending
Availability: Services remain accessible
Network Security Model
Sender → [Encryption E with Key K] → Ciphertext → Insecure Network →
[Decryption D with Key K] → Receiver
Explanation:
The sender encrypts plaintext using algorithm E and key K.
Ciphertext travels over an insecure network.
The receiver decrypts using D and the same key K (symmetric model).
An adversary may attempt interception, modification, or impersonation.
Mathematical view:
C = E(K, P)
P = D(K, C)
1.4 Types of Attacks
Passive attacks: Eavesdropping, traffic analysis (no data change)
Active attacks: Modification, masquerade, replay, DoS
Cryptanalysis: Exploiting algorithm weaknesses
Brute force: Trying all possible keys
Introduction to Classical Encryption Techniques
Classical encryption techniques are early cryptographic methods developed
before modern computers.
They are mainly based on:
Substitution (replace letters/symbols)
Transposition (rearrange positions)
All classical techniques discussed here follow the Symmetric Cipher Model,
where the same secret key is used for encryption and decryption.
2. Symmetric Cipher Model (Secret-Key Cryptography)
2.1 Definition
In the symmetric cipher model, the same key (K) is used by both sender and
receiver to encrypt and decrypt the message.
Basic Diagram
Mathematical Representation
Encryption:
C=E(K,P)C = E(K, P)C=E(K,P)
Decryption:
P=D(K,C)P = D(K, C)P=D(K,C)
Where:
P = Plaintext
C = Ciphertext
E = Encryption algorithm
D = Decryption algorithm
K = Secret key
Components of the Symmetric Cipher Model
(a) Plaintext (P)
Original readable message
Example: HELLO WORLD
(b) Encryption Algorithm (E)
Converts plaintext into ciphertext
Example: Caesar cipher shifts letters
(c) Secret Key (K)
Controls transformation
Must be kept secret
Security depends more on key secrecy than algorithm secrecy
(Kerckhoffs’s principle)
(d) Ciphertext (C)
Encrypted, unreadable message
Example: KHOOR ZRUOG
(e) Decryption Algorithm (D)
Reverses encryption using the same key
Key Distribution Problem (Major Challenge)
Diagram: Key Distribution Issue
Sender ----(How to send key securely?)----> Receiver
(If key is intercepted → system breaks)
Problem:
Before communication, sender and receiver must share the secret key
securely.
If an attacker gets the key, all security is lost.
This is the main limitation of symmetric cryptography.
Types of Symmetric Ciphers (Conceptual View)
(a) Substitution Ciphers
Replace symbols/letters with others
Examples: Caesar, Monoalphabetic, Playfair, Hill
(b) Transposition Ciphers
Rearrange positions of symbols
Example: Rail Fence Cipher
(c) Product Ciphers
Combination of substitution + transposition
(Concept later used in DES, AES)
Attacks on Symmetric Cipher Model
Diagram: Attacker Model
Plaintext ----> Encryption ----> Ciphertext ----> Decryption ----> Plaintext
↑ ↑
Key Guess Interception
Types of Attacks:
Attack Type Description
Ciphertext-only Attacker sees only ciphertext
Known-plaintext Some plaintext–ciphertext pairs known
Chosen-plaintext Attacker chooses plaintexts
Brute force Try all possible keys
What is a Substitution Cipher?
A substitution cipher is a classical encryption technique in which:
Each letter of the plaintext is replaced (substituted) by another letter.
The substitution follows a fixed rule.
The receiver applies the reverse rule to decrypt.
Caesar Cipher is the simplest substitution cipher.
[Link] Cipher – Definition
The Caesar Cipher is a monoalphabetic substitution cipher in which:
Each letter in the plaintext is shifted by a fixed number of positions (K)
in the alphabet.
The same shift (key K) is used for both encryption and decryption.
Historically used by Julius Caesar to communicate securely.
Working Principle
Let:
Plaintext alphabet = A B C ... Z
Ciphertext alphabet = shifted by K positions
Example with K = 3:
Plaintext : 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
Ciphertext: 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
So:
A→D
B→E
C→F
X→A
Y→B
Z→C
Mathematical Representation
Let:
Letters be mapped as:
A = 0, B = 1, C = 2, …, Z = 25
Encryption:
C=E(P)=(P+K)mod 26
Decryption:
P=D(C)=(C−K)mod 26
Where:
P = plaintext letter number
C = ciphertext letter number
K = key (shift value)
mod 26 = wrap around after Z
Example
Plaintext: ATTACK Key:K = 3
Key Space (Very Small → Insecure)
Total possible keys:
K = 1 to 25 → Only 25 keys
This makes Caesar Cipher extremely weak.
Attacks on Caesar Cipher
Brute Force Attack
Attacker tries all 25 possible shifts:
Key = 1 → Try decoding
Key = 2 → Try decoding
...
Key = 25 → One result will make sense
Since English plaintext is recognizable, the correct key is found easily.
Frequency Analysis
Letter frequencies in English:
o E is most common
o T, A, O follow
Caesar cipher preserves letter frequency pattern (just shifted).
Easy to break.
What is a Monoalphabetic Cipher?
A monoalphabetic cipher is a classical substitution cipher in which:
Each letter of the plaintext is replaced by one fixed corresponding
letter of the ciphertext.
The same substitution mapping is used for the entire message.
Once the mapping is chosen, it does not change.
Example idea:
A→Q, B→W, C→E, …, Z→M
Every A in plaintext becomes Q in ciphertext.
Basic Working Principle
Mapping Table (Key)
Plaintext : 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
Ciphertext: Q W E R T Y U I O P A S D F G H J K L Z X C V B N M
This full mapping table is the secret key.
Mathematical View (Conceptual)
Let:
P = plaintext letter
C = ciphertext letter
f = substitution function (one-to-one mapping)
Encryption: C=f(P)
Decryption: P= P=f−1(C) Where f is a permutation of 26 letters.
Why Monoalphabetic Cipher is Insecure
Although key space is large, the cipher is vulnerable to frequency analysis
because:
The frequency of letters in English is preserved (just substituted)
Common letters:
o E, T, A, O, I, N
Common digraphs:
o TH, HE, IN
Common words:
o THE, AND, IS
What is the Playfair Cipher?
The Playfair Cipher is a classical digraph (pair-of-letters) substitution
cipher.
Instead of encrypting one letter at a time (like Caesar/monoalphabetic), it
encrypts two letters together.
This hides single-letter frequency patterns and makes cryptanalysis harder
than simple substitution.
Key Idea (Why Playfair is Stronger)
Operates on pairs (digraphs) → reduces single-letter frequency leakage
Uses a 5×5 key matrix built from a keyword
Combines substitution + positional rules (row/column/rectangle)
Convention: I and J are combined to fit 25 letters into a 5×5 grid.
Constructing the 5×5 Key Matrix (Encryption Key)
Step 1: Choose a keyword
Example keyword: MONARCHY
Step 2: Remove duplicate letters
MONARCHY → M O N A R C H Y
Step 3: Fill the 5×5 grid with keyword letters (I/J together), then the
remaining alphabet
Example 5×5 Matrix (I/J combined):
M O N A R
C H Y B D
E F G I/J K
L P Q S T
U V W X Z
Preparing the Plaintext (Important Rules)
Before encryption:
1. Split plaintext into digraphs (pairs)
2. If a pair has two identical letters, insert a filler (usually X)
3. If plaintext length is odd, append X
4. Replace J with I
Example:
Plaintext: BALLOON
Split: BA | LL | OO | N
Apply rules: BA | LX | LO | ON | X
Encryption Rules (Three Cases)
Let the plaintext pair be (A, B). Find their positions in the matrix.
✅Case 1: Same Row
Replace each letter with the letter to its right (wrap around at row end)
Example:
Row: L P Q S T
Pair: L P → P Q
Same Column
Replace each letter with the letter below it (wrap around at column
bottom)
Example:
Column: M C E L U
Pair: M C → C E
Rectangle (Different Row & Column)
Form a rectangle with the two letters as corners
Replace each letter with the one in the same row but the other column
Example:
Pair: M (row1,col1) and B (row2,col4)
Rectangle corners → Replace:
M → A (row1, col4)
B → C (row2, col1)
Hill Cipher
Unlike Playfair (which works on pairs), Hill Cipher works on blocks of size n
(e.g., 2 letters, 3 letters, etc.).
Idea
1. Convert letters to numbers:
A=0, B=1, C=2, ..., Z=25
2. Choose an invertible key matrix K (n×n).
3. Break plaintext into blocks of size n.
4. Encrypt using:
C = (K × P) mod 26
5. Convert numbers back to letters.
Step-by-Step Example (2×2 Hill
Cipher)
Step 2: Plaintext
HELLO
Convert letters to numbers:
H=7
E=4
L = 11
L = 11
O = 14
Group into 2-letter blocks (pad with X if needed):
HE → (7, 4)
LL → (11, 11)
OX → (14, 23) ← padded with X
Cipher block = HI
7→H
8→I
14 → O
25 → Z
Cipher block = OZ
Cipher block = HN
Polyalphabetic Cipher
A polyalphabetic cipher uses multiple substitution alphabets instead of just
one.
That means the same plaintext letter can encrypt to different ciphertext
letters depending on the key position. This defeats simple frequency analysis
(unlike Caesar/monoalphabetic ciphers).
The most famous polyalphabetic cipher is the Vigenère cipher, widely taught
in cryptography courses.
Core Idea
Choose a keyword (e.g., KEY)
Repeat the keyword to match plaintext length
Each letter of the key decides how much to shift the plaintext letter
Encryption is done using mod 26 arithmetic
Letter-to-Number Mapping
A = 0, B = 1, C = 2, ... Z = 25
Step 1: Choose Plaintext and Key
Plaintext : HELLO
Key : KEY
Repeat the key to match length of plaintext:
Plaintext : H E L L O
Key : K E Y K E
Step 2: Convert Letters to Numbers
Letter H E L L O
Value 7 4 11 11 14
Key K EY K E
Letter H E L L O
Val 10 4 24 10 4
Step 3: Encrypt Using Formula
C=(P+K)mod26
Plain (P) Key (K) (P + K) mod 26 Cipher
7 10 17 R
4 4 8 I
11 24 35 mod 26 = 9 J
11 10 21 V
14 4 18 S
Final Ciphertext
HELLO → RIJVS
Decryption Formula
P=(C−K)mod26
Same key is used again to decrypt.
Algorithm
Encryption Algorithm (Polyalphabetic / Vigenère)
1. Input plaintext P and key K
2. Repeat key to match length of plaintext
3. Convert P and K letters to numbers (A=0 to Z=25)
4. Compute:
Ci = (Pi + Ki) mod 26
5. Convert Ci back to letters
6. Output ciphertext
What is One-Time Pad (OTP)?
A One-Time Pad is a polyalphabetic cipher where:
The key is truly random
The key length = plaintext length
The key is used only once
Encryption is done using modular addition
Encryption:
Ci=(Pi+Ki) mod 26
Decryption:
Pi=(Ci−Ki) mod 26
Where:
P = Plaintext
K = Key
C = Ciphertext
A=0, B=1, ..., Z=25
Step-by-Step Worked Example (OTP)
Step 1: Choose Plaintext and Random Key
Plaintext : HELLO
Key (random, same length) : XMCKL
Key must be random & same length as plaintext
Step 2: Convert Letters to Numbers (A=0 to Z=25)
Letter H E L L O
Value 7 4 11 11 14
Key X M C K L
Letter H E L L O
Value 23 12 2 10 11
Step 3: Encrypt Using OTP Formula
C=(P+K)mod26
Plain (P) Key (K) (P + K) mod 26 Cipher
7 23 30 mod 26 = 4 E
4 12 16 Q
11 2 13 N
11 10 21 V
14 11 25 Z
Final Ciphertext
HELLO → EQNVZ
Step 4: Decryption
P=(C−K)mod26
Cipher (C) Key (K) (C − K) mod 26 Plain
4 23 -19 mod 26 = 7 H
16 12 4 E
13 2 11 L
21 10 11 L
25 11 14 O
Recovered Plaintext = HELLO
Algorithm (Write This in Exam)
One-Time Pad Encryption Algorithm
1. Input plaintext P
2. Generate a random key K of same length as P
3. Convert letters to numbers (A=0 to Z=25)
4. Compute:
Ci=(Pi+Ki)mod26
Convert numbers back to letters
Output ciphertext