Cryptography · Unit 2 · 10 hrs
Symmetric Ciphers
Exam-focused notes for Symmetric Ciphers (Cryptography, CSC327): what the TU syllabus asks and how it has actually been tested, with 14 solved past questions from this unit.
Symmetric Ciphers in short
Where Unit 1 covered ciphers that operate on individual letters, this unit covers the ciphers built from bits and bytes that dominate modern practice: the Feistel and substitution-permutation network structures, DES and its multiple-encryption variants, the finite-field arithmetic that AES and other block ciphers rely on, IDEA, AES itself, and the standard modes used to apply any block cipher to a message longer than one block.
What this unit covers
- Fiestel Cipher Structure
- Substitution Permutation Network (SPN)
- Data Encryption Standards (DES)
- Double DES
- Triple DES
- Finite Fields: Groups Rings, Fields, Modular Arithmetic, Euclidean Algorithm, Galois Fields (GF(p) & GF(2n)), Polynomial Arithmetic
- International Data Encryption Standard (IDEA)
- Advanced Encryption Standards (AES) Cipher
- Modes of Block Cipher Encryptions (Electronic Code Book, Cipher Block Chaining, Cipher Feedback Mode, Output Feedback Mode, Counter Mode)
Fiestel Cipher Structure
2082
Feistel Cipher Structure and AES Key Expansion
Show solved answerHide answer
Feistel Cipher Structure and AES Key Expansion
Part A: Feistel Cipher Structure
A Feistel Cipher is a symmetric block cipher design that splits a plaintext block into two equal halves and processes them through several rounds of substitution and permutation using round sub-keys derived from the master key.
Working
A block of $2w$ bits is divided into $L_0$ (left) and $R_0$ (right).
For each round $i$:
$$L_i = R_{i-1}$$ $$R_i = L_{i-1} \oplus F(R_{i-1}, K_i)$$
where $K_i$ is the round sub-key and $F$ is the round function (which need not be invertible).
Block Diagram (words)
- Split plaintext into $L_0$ and $R_0$.
- Feed $R_0$ and $K_1$ into $F$.
- XOR $F$ output with $L_0 \Rightarrow R_1$.
- $R_0$ becomes $L_1$ (swap).
- Repeat for $n$ rounds; recombine $L_n, R_n$ into ciphertext.
Key Properties
- Same structure for encryption and decryption (sub-keys reversed for decryption).
- $F$ need not be invertible.
- Security grows with more rounds.
- Examples: DES (16 rounds), Blowfish, Camellia.
Part B: AES Key Expansion - First 4 Bytes After First Iteration
Given Data
Key (16 bytes) grouped into 4 words:
| Word | Bytes |
|---|---|
| $W_0$ | 2B 7E 15 16 |
| $W_1$ | 28 AE D2 A6 |
| $W_2$ | AB F7 97 66 |
| $W_3$ | 01 02 03 04 |
S-Box row 0 provided (sufficient, since all bytes being substituted have upper nibble 0).
Formula
$$W_4 = W_0 \oplus g(W_3)$$
Step 1: RotWord of $W_3 = [01,02,03,04]$: $$[02,\ 03,\ 04,\ 01]$$
Step 2: SubBytes (row 0 of S-Box):
| Byte | S-Box |
|---|---|
| 02 → col 2 | 77 |
| 03 → col 3 | 7B |
| 04 → col 4 | F2 |
| 01 → col 1 | 7C |
$$[77,\ 7B,\ F2,\ 7C]$$
Step 3: XOR Rcon(1) = [01,00,00,00]: $$[77\oplus01,\ 7B,\ F2,\ 7C] = [76,\ 7B,\ F2,\ 7C]$$
So $g(W_3) = [76, 7B, F2, 7C]$.
Step 4: Compute $W_4 = W_0 \oplus g(W_3)$:
| $W_0$ | $g(W_3)$ | XOR |
|---|---|---|
| 2B | 76 | 5D |
| 7E | 7B | 05 |
| 15 | F2 | E7 |
| 16 | 7C | 6A |
Verification of first byte: $2B = 0010,1011$, $76 = 0111,0110$, XOR $= 0101,1101 = 5D$. ✓
Final Answer
$$\boxed{W_4 = [5D,\ 05,\ E7,\ 6A]}$$
The first 4 bytes of the next key after the first iteration are 5D 05 E7 6A.
Modes of Block Cipher Encryptions
2082 · 5 marks
Explain any two modes of block cipher encryption. [5]
International Data Encryption Standard
2081
Tracing the First Full Round of IDEA Algorithm
IDEA (International Data Encryption Algorithm) is a symmetric block cipher that operates on 64-bit plaintext blocks using a 128-bit key, performing 8 identical rounds with operations: multiplication modulo $2^{16}+1$, addition modulo $2^{16}$, and XOR.
2076 · 10 marks
Cryptography Question
Among monoalphabetic and polyalphabetic cipher, which one is more vulnerable? Justify your statement. Which types of keys are considered weak keys in DES? Explain the round operation in IDEA.[10]
Show solved answerHide answer
Cryptography: Monoalphabetic vs Polyalphabetic, DES Weak Keys, and IDEA Round Operation
Part A: Monoalphabetic vs Polyalphabetic, Which is More Vulnerable?
Monoalphabetic cipher is more vulnerable than polyalphabetic cipher.
Definition
- Monoalphabetic Cipher: A substitution cipher where each plaintext letter is always replaced by the same fixed ciphertext letter throughout the entire message. Example: Caesar Cipher.
- Polyalphabetic Cipher: A substitution cipher that uses multiple substitution alphabets in rotation. Example: Vigenere Cipher.
Justification
| Feature | Monoalphabetic | Polyalphabetic |
|---|---|---|
| Substitution alphabets used | Single fixed alphabet | Multiple alphabets in rotation |
| Letter frequency preserved? | Yes | No (flattened) |
| Vulnerable to frequency analysis? | Yes, easily | Much harder |
| Security level | Low | Higher |
Why monoalphabetic is weaker:
- Since every occurrence of a plaintext letter maps to the same ciphertext letter, the statistical frequency distribution of the original language is preserved in the ciphertext.
- An attacker can perform frequency analysis: in English, 'E' appears ~13% of the time, 'T' ~9%, etc. By counting ciphertext letter frequencies and matching them to known language frequencies, the key can be recovered without brute force.
- In polyalphabetic ciphers, the same plaintext letter is encrypted differently depending on its position (e.g., 'E' may become 'H' at one position and 'R' at another). This flattens the frequency distribution, making frequency analysis ineffective.
Conclusion
Monoalphabetic cipher is significantly more vulnerable because its one-to-one fixed mapping leaks the statistical patterns of the plaintext language, allowing easy cryptanalysis through frequency analysis.
Part B: Weak Keys in DES
Background
DES is a block cipher that encrypts 64-bit plaintext using a 56-bit key over 16 rounds, generating 16 subkeys (one per round) through a key schedule.
Definition of Weak Keys
Weak keys in DES are keys that produce identical subkeys for all 16 rounds. This means:
$$E_K(E_K(P)) = P$$
That is, encrypting twice with the same weak key returns the original plaintext, making encryption equivalent to decryption. This severely reduces security.
The 4 Weak Keys
| Weak Key (Hex) | Bit Pattern |
|---|---|
0101 0101 0101 0101 | All zeros (after parity removal) |
FEFE FEFE FEFE FEFE | All ones (after parity removal) |
1F1F 1F1F 0E0E 0E0E | First half zeros, second half ones |
E0E0 E0E0 F1F1 F1F1 | First half ones, second half zeros |
These keys produce subkeys that are either all zeros or all ones in both halves of the key register (C and D registers), so all 16 subkeys are identical.
Semi-Weak Keys
DES also has 12 semi-weak keys (6 pairs) where:
$$E_{K_1}(P) = D_{K_2}(P)$$
Encrypting with key $K_1$ is the same as decrypting with key $K_2$. These pairs produce only two distinct subkeys alternating across 16 rounds.
Why They Are Dangerous
- Weak keys reduce the effective key space.
- An attacker who suspects a weak key is in use can test only a handful of keys rather than $2^{56}$ possibilities.
- In practice, weak keys should be detected and rejected during key generation.
Part C: Round Operation in IDEA
Overview
IDEA (International Data Encryption Algorithm) is a symmetric block cipher with the following parameters:
- Block size: 64 bits
- Key size: 128 bits
- Structure: 8 full rounds + 1 output transformation (half round)
- Subkeys: 52 subkeys of 16 bits each (6 per full round + 4 for output transformation)
Three Algebraic Operations
IDEA derives its strength from mixing three algebraically incompatible operations on 16-bit sub-blocks:
| Symbol | Operation | Modulus |
|---|---|---|
| $\oplus$ | Bitwise XOR | $2^{16}$ |
| $\boxplus$ | Addition | $2^{16}$ |
| $\odot$ | Multiplication | $2^{16} + 1 = 65537$ |
These three operations come from different algebraic groups, making algebraic cryptanalysis extremely difficult.
Input Division
The 64-bit plaintext block is divided into four 16-bit sub-blocks:
$$X_1, \quad X_2, \quad X_3, \quad X_4$$
Steps in One Full Round (using subkeys $K_1$ through $K_6$)
Step 1: Apply first four subkeys
$$a = X_1 \odot K_1$$ $$b = X_2 \boxplus K_2$$ $$c = X_3 \boxplus K_3$$ $$d = X_4 \odot K_4$$
Step 2: XOR cross combinations
$$e = a \oplus c$$ $$f = b \oplus d$$
Step 3: MA (Multiplication-Addition) Structure
The MA structure uses subkeys $K_5$ and $K_6$:
$$g = e \odot K_5$$ $$h = (f \boxplus g) \odot K_6$$ $$i = g \boxplus h$$
Step 4: XOR to produce round outputs
$$Y_1 = a \oplus h$$ $$Y_2 = c \oplus h$$ $$Y_3 = b \oplus i$$ $$Y_4 = d \oplus i$$
The final round output $(Y_1, Y_2, Y_3, Y_4)$ becomes the input to the next round (or, after the eighth round, to the output transformation), and the swap of the two middle blocks between rounds ensures full diffusion of the plaintext bits across the 64-bit block by the end of the cipher.
Finite Fields
2081 · 5 marks
Find the multiplicative inverse of polynomial (95) using extended euclidean Algorithm. [5]
Show solved answerHide answer
Multiplicative Inverse in GF(2⁸) using the Extended Euclidean Algorithm
Given
- Element to invert: 95 (hexadecimal), interpreted as an element of $GF(2^8)$.
- $95_{16} = 1001,0101_2$, giving polynomial
$$b(x) = x^7 + x^4 + x^2 + 1$$
- AES irreducible (reduction) polynomial:
$$m(x) = x^8 + x^4 + x^3 + x + 1$$
Note: The question only states "95" and "extended Euclidean algorithm". The irreducible polynomial is not explicitly given; the AES standard modulus is assumed since this is the standard BIT/cryptography context.
Goal: find $b(x)^{-1} \bmod m(x)$.
Solution
All arithmetic is in $GF(2)$ (addition = XOR).
Initialize:
- $r_0 = m(x)=x^8+x^4+x^3+x+1$, $; t_0=0$
- $r_1 = b(x)=x^7+x^4+x^2+1$, $; t_1=1$
Recurrence: $r_{i+1}=r_{i-1}-q_i r_i$, $;t_{i+1}=t_{i-1}-q_i t_i$.
Division 1: $r_0 \div r_1$
$$x^8+x^4+x^3+x+1 ;=; x\cdot(x^7+x^4+x^2+1) + r_2$$
$x\cdot b = x^8+x^5+x^3+x$. XOR:
$$r_2 = (x^8+x^4+x^3+x+1)\oplus(x^8+x^5+x^3+x)=x^5+x^4+1$$
- $q_1=x$
- $t_2=t_0-q_1t_1 = 0 - x\cdot1 = x$
Division 2: $r_1 \div r_2$
Divide $x^7+x^4+x^2+1$ by $x^5+x^4+1$:
- $x^2$: $x^2(x^5+x^4+1)=x^7+x^6+x^2$; XOR → $x^6+x^4+1$
- $x$: $x(x^5+x^4+1)=x^6+x^5+x$; XOR → $x^5+x^4+x+1$
- $1$: $x^5+x^4+1$; XOR → $x$
So:
- $q_2=x^2+x+1$, $; r_3=x$
- $t_3=t_1-q_2t_2 = 1 - (x^2+x+1)(x) = 1+(x^3+x^2+x)=x^3+x^2+x+1$
Division 3: $r_2 \div r_3$
Divide $x^5+x^4+1$ by $x$:
$$x^5+x^4+1 = x\cdot(x^4+x^3)+1$$
So:
- $q_3=x^4+x^3$, $; r_4=1$
- $t_4=t_2-q_3t_3 = x - (x^4+x^3)(x^3+x^2+x+1)$
Compute $(x^4+x^3)(x^3+x^2+x+1)$:
$x^4\cdot(x^3+x^2+x+1)=x^7+x^6+x^5+x^4$ $x^3\cdot(x^3+x^2+x+1)=x^6+x^5+x^4+x^3$
XOR (add): $x^6\oplus x^6=0$, $x^5\oplus x^5=0$, $x^4\oplus x^4=0$:
$$=x^7+x^3$$
Then:
$$t_4 = x \oplus (x^7+x^3) = x^7+x^3+x$$
Since $r_4 = 1 = \gcd$, the inverse of $b(x)$ modulo $m(x)$ is $t_4$.
Verification
$$b(x)^{-1} = x^7 + x^3 + x$$
Check $b(x)\cdot t_4 \bmod m(x)$:
$b = x^7+x^4+x^2+1$, $t_4=x^7+x^3+x$.
Product:
- $x^7\cdot t_4 = x^{14}+x^{10}+x^8$
- $x^4\cdot t_4 = x^{11}+x^7+x^5$
- $x^2\cdot t_4 = x^9+x^5+x^3$
- $1\cdot t_4 = x^7+x^3+x$
XOR all: $x^5\oplus x^5=0$, $x^7\oplus x^7=0$, $x^3\oplus x^3=0$:
$$= x^{14}+x^{11}+x^{10}+x^9+x^8+x$$
Reduce mod $m(x)=x^8+x^4+x^3+x+1$ (i.e. $x^8\equiv x^4+x^3+x+1$):
-
$x^8\equiv x^4+x^3+x+1$
-
$x^9\equiv x^5+x^4+x^2+x$
-
$x^{10}\equiv x^6+x^5+x^3+x^2$
-
$x^{11}\equiv x^7+x^6+x^4+x^3$
-
$x^{14}=x^6\cdot x^8\equiv x^6(x^4+x^3+x+1)=x^{10}+x^9+x^7+x^6$
reduce: $x^{10}\to x^6+x^5+x^3+x^2$, $x^9\to x^5+x^4+x^2+x$ $x^{14}\equiv (x^6+x^5+x^3+x^2)+(x^5+x^4+x^2+x)+x^7+x^6$ $= x^7+x^4+x^3+x$
Sum all reduced terms (XOR):
| term | reduced |
|---|---|
| $x^{14}$ | $x^7+x^4+x^3+x$ |
| $x^{11}$ | $x^7+x^6+x^4+x^3$ |
| $x^{10}$ | $x^6+x^5+x^3+x^2$ |
| $x^9$ | $x^5+x^4+x^2+x$ |
| $x^8$ | $x^4+x^3+x+1$ |
| $x$ | $x$ |
XOR column by column:
- $x^7$: $1+1=0$
- $x^6$: $1+1=0$
- $x^5$: $1+1=0$
- $x^4$: $1+1+1+1=0$
- $x^3$: $1+1+1+1=0$
- $x^2$: $1+1=0$
- $x^1$: $1+1+1+1=0$
- $x^0$: $1$
$$= 1 \checkmark$$
Final Answer
$$\boxed{b(x)^{-1} = x^7 + x^3 + x}$$
In binary: $1000,1010$, i.e. hexadecimal 8A.
Completing the computation through $t_4$ gives the inverse $x^7+x^3+x$, which multiplies back to $1$.
2080 · 5 marks
Show that the set of integers is Ring under addition and multiplication. [5]
2078 · 10 marks
Define Galois field with an example. Explain any two modes of block cipher encryption. Determine the quadratic residues of 7.[10]
Show solved answerHide answer
Galois Field, Block Cipher Modes, and Quadratic Residues
Given
- Modulus for quadratic residues: $n = 7$
- Tasks: (a) define Galois field with example, (b) explain any two block cipher modes, (c) find quadratic residues of 7.
No numeric data is missing. All parts are solvable.
Solution
Part 1: Galois Field
Definition: A Galois Field (Finite Field), denoted $GF(p^n)$, is a field containing a finite number of elements, satisfying all field axioms (closure, associativity, commutativity, additive and multiplicative identities, additive and multiplicative inverses for non-zero elements, and distributivity).
The order (number of elements) must be a prime power $p^n$, where $p$ is prime and $n \geq 1$.
- $GF(p)$: elements ${0, 1, \ldots, p-1}$ with arithmetic mod $p$.
- $GF(2^8)$ is used in AES.
Example: $GF(7) = {0, 1, 2, 3, 4, 5, 6}$ (arithmetic mod 7)
Addition: $5 + 4 = 9 \equiv 2 \pmod 7$
Multiplication: $3 \times 5 = 15 \equiv 1 \pmod 7$
Multiplicative inverse: since $3 \times 5 \equiv 1 \pmod 7$, we have $3^{-1} = 5$.
Every non-zero element has an inverse, so $GF(7)$ is a valid Galois field.
Part 2: Two Modes of Block Cipher Encryption
Mode 1: Electronic Codebook (ECB)
- Plaintext is split into fixed-size blocks ($P_1, P_2, \ldots$).
- Each block is encrypted independently with the same key $K$: $$C_i = E(K, P_i)$$
- Advantages: Simple, fast, fully parallelizable; random access to blocks.
- Disadvantages: Identical plaintext blocks give identical ciphertext blocks, exposing data patterns; weak for structured data.
Mode 2: Cipher Block Chaining (CBC)
- Each plaintext block is XORed with the previous ciphertext block before encryption. An Initialization Vector (IV) seeds the first block: $$C_i = E(K,; P_i \oplus C_{i-1}), \qquad C_0 = IV$$
- Decryption: $P_i = D(K, C_i) \oplus C_{i-1}$
- Advantages: Identical plaintext blocks give different ciphertext (hides patterns); more secure than ECB.
- Disadvantages: Encryption is sequential (not parallelizable); a transmission error in one block corrupts that block and the next during decryption.
Part 3: Quadratic Residues of 7
An integer $a$ is a quadratic residue mod $n$ if there exists $x$ with $x^2 \equiv a \pmod n$ and $\gcd(a,n)=1$.
Compute $x^2 \bmod 7$ for $x = 1$ to $6$:
| $x$ | $x^2$ | $x^2 \bmod 7$ |
|---|---|---|
| 1 | 1 | 1 |
| 2 | 4 | 4 |
| 3 | 9 | 2 |
| 4 | 16 | 2 |
| 5 | 25 | 4 |
| 6 | 36 | 1 |
Distinct quadratic residues: $$QR(7) = {1, 2, 4}$$
Non-residues: ${3, 5, 6}$
Check with formula: For prime $p$, number of QRs $= \dfrac{p-1}{2} = \dfrac{7-1}{2} = 3$. ✓ (matches ${1,2,4}$)
Final Answers
- $GF(7) = {0,\ldots,6}$ under mod-7 arithmetic is the example Galois field.
- ECB and CBC modes explained as above.
- Quadratic residues of 7: ${1, 2, 4}$.
Double DES
2080 · 10 marks
Write down the encryption and decryption process at 2-DES and 3-DES. Explain the Fiestal cipher structure. Divide $5x^2 + 4x + 6$ by $2x + 1$ over GF(7). [10]
Advanced Encryption Standards
2079
Security Policy and Mechanism, Block vs Stream Cipher, and AES Key Expansion
2076 · 5 marks
Explain the procedure of mix column transformation in AES with an example. [5]
Make Unit 2 stick
Practice CSC327 with flashcards & quizzes