2 Cryptographic Foundations

Information Security ยท Unit 2

Cryptographic Foundations

Exam-focused notes for Cryptographic Foundations (Information Security, BIT303): what the TU syllabus asks and how it has actually been tested, with 6 solved past questions from this unit.

Cryptographic Foundations in short

Cryptography depends on mathematics. This chapter covers the number theory, algorithms and classical ciphers that later chapters (DES, RSA, hashing) build on.

Cryptographic Foundations: notes

Number theory basics

For integers, $a \bmod n$ is the remainder when $a$ is divided by $n$. Two numbers are congruent modulo $n$ if they leave the same remainder: $a \equiv b \pmod n$.

Useful facts:

  • $\gcd(a,b)$ is the largest number that divides both. If $\gcd(a,b)=1$, the numbers are coprime.
  • A prime has exactly two divisors, 1 and itself.
  • Modular arithmetic works with sums and products: $(a+b) \bmod n = ((a \bmod n)+(b \bmod n)) \bmod n$.
  • The modular inverse of $a$ modulo $n$ is a number $x$ with $ax \equiv 1 \pmod n$. It exists only if $\gcd(a,n)=1$.
  • Fermat's little theorem: if $p$ is prime and $p \nmid a$, then $a^{p-1} \equiv 1 \pmod p$.

Euler totient function

The Euler totient $\phi(n)$ counts the numbers from 1 to $n$ that are coprime to $n$.

Rules:

  • For a prime $p$: $\phi(p) = p-1$.
  • For two different primes: $\phi(pq) = (p-1)(q-1)$.
  • For a prime power: $\phi(p^k) = p^k - p^{k-1}$.
  • For coprime $m,n$: $\phi(mn)=\phi(m)\phi(n)$.

Example: find $\phi(10)$. The numbers coprime to 10 are 1, 3, 7, 9, so $\phi(10)=4$. By the rule:

$$\phi(10)=\phi(2)\phi(5)=1\times 4=4$$

Another: $\phi(36)=\phi(4)\phi(9)=(4-2)(9-3)=2\times 6=12$.

Euler's theorem: if $\gcd(a,n)=1$, then $a^{\phi(n)} \equiv 1 \pmod n$. RSA is based on this.

What this unit covers

  • Number theory basics
  • Euler totient function
  • Extended Euclidean algorithm
  • Primality testing algorithms
  • Finite fields and polynomial operations
  • Substitution and transposition ciphers

Substitution and transposition ciphers

2082

Distinction between Substitution and Transposition Cipher, DES Sub-Key Generation, and Finite Fields

--- Feature Substitution Cipher Transposition Cipher --------- Basic Operation Replaces each plaintext character with another character Rearranges (permutes) the positions of plaintext characters Character Identity Characters change their identity Characters retain identity but change position Ke...

Open this answer on its own page โ†’

Finite fields and polynomial operations

2082 ยท 5 marks

Perform polynomial addition, subtraction and multiplication of $2x^2 + 4x + 2$ and $5x + 6$ over $GF(7)$. [5]

Show solved answer

Polynomial Arithmetic over GF(7)

Given

$$A(x) = 2x^2 + 4x + 2$$ $$B(x) = 5x + 6$$

Field: $GF(7)$, so all coefficients reduced $\bmod 7$.

Coefficient vectors:

  • $A: [x^2, x^1, x^0] = [2, 4, 2]$
  • $B: [x^2, x^1, x^0] = [0, 5, 6]$

Solution

1. Addition $A(x) + B(x)$

DegreeABSummod 7
$x^2$2022
$x^1$4592
$x^0$2681

$$\boxed{A(x) + B(x) = 2x^2 + 2x + 1}$$

2. Subtraction $A(x) - B(x)$

DegreeABDiffmod 7
$x^2$2022
$x^1$45-16
$x^0$26-43

$$\boxed{A(x) - B(x) = 2x^2 + 6x + 3}$$

3. Multiplication $A(x) \times B(x)$

Expand: $$(2x^2 + 4x + 2)(5x + 6)$$ $$= 10x^3 + 12x^2 + 20x^2 + 24x + 10x + 12$$

Collect: $$= 10x^3 + 32x^2 + 34x + 12$$

Reduce $\bmod 7$:

DegreeRawmod 7
$x^3$103
$x^2$324
$x^1$346
$x^0$125

$$\boxed{A(x) \times B(x) = 3x^3 + 4x^2 + 6x + 5}$$

Summary

OperationResult over $GF(7)$
$A + B$$2x^2 + 2x + 1$
$A - B$$2x^2 + 6x + 3$
$A \times B$$3x^3 + 4x^2 + 6x + 5$
Open this answer on its own page โ†’

Primality testing algorithms

2081 ยท 5 marks

Write Rabin Miller Algorithm for primality testing. Test whether 341 is prime or not using the algorithm. [5]

  • Number to test: $n = 341$ - Witness base (standard choice): $a = 2$ --- If $n$ is an odd prime, write $n - 1 = 2^s \cdot d$ with $d$ odd. Then for any witness $a$ coprime to $n$, either: $$a^d \equiv 1 \pmod{n} \quad\text{OR}\quad a^{2^r d} \equiv -1 \pmod{n} \text{ for some } 0 \le r < s$$ If ...
Open this answer on its own page โ†’

2079 ยท 5 marks

Define Euler Totient function. Determine whether 37 is Composite or not using Miller Rabin Primality testing. [5]

Show solved answer

Euler Totient Function & Miller-Rabin Primality Test


Part 1: Euler Totient Function

The Euler Totient Function, denoted $\phi(n)$, is defined as the number of positive integers less than or equal to $n$ that are relatively prime (coprime) to $n$.

$$\phi(n) = |{ k : 1 \le k \le n,\ \gcd(k, n) = 1 }|$$

Key properties:

  • If $p$ is prime: $\phi(p) = p - 1$
  • For a prime power: $\phi(p^k) = p^k - p^{k-1}$
  • Multiplicative: $\phi(mn) = \phi(m)\cdot\phi(n)$ when $\gcd(m,n) = 1$

Example: $\phi(37) = 36$ since 37 is prime.


Part 2: Miller-Rabin Test on $n = 37$

Algorithm

To test $n$ with a chosen witness $a$:

  1. Write $n - 1 = 2^s \cdot d$ with $d$ odd.
  2. Compute $x = a^d \bmod n$.
  3. If $x \equiv 1$ or $x \equiv -1 \pmod n$ โ†’ probably prime.
  4. Otherwise square $x$ repeatedly (for $r = 1, \dots, s-1$); if any gives $-1 \pmod n$ โ†’ probably prime.
  5. If none hold โ†’ composite.

Step 1: Express $n - 1 = 2^s \cdot d$

$$n - 1 = 36 = 2^2 \cdot 9$$

So $s = 2$, $d = 9$.


Step 2: Choose witness $a = 2$, compute $a^d \bmod n$

$$2^9 \bmod 37$$

  • $2^1 = 2$
  • $2^2 = 4$
  • $2^4 = 16$
  • $2^8 = 256 = 6\times 37 + 34 \equiv 34 \pmod{37}$
  • $2^9 = 2^8 \cdot 2 = 34 \times 2 = 68 \equiv 68 - 37 = 31 \pmod{37}$

$$x = 2^9 \equiv 31 \pmod{37}$$


Step 3: Check conditions

Initial check: Is $x \equiv 1$ or $x \equiv 36\ (\equiv -1)$? $$31 \ne 1, \quad 31 \ne 36 \quad \Rightarrow \text{ not yet passed}$$

Square once ($r = 1$): compute $2^{18} = x^2 \bmod 37$ $$31^2 = 961, \quad 961 = 25\times 37 + 36 = 925 + 36$$ $$2^{18} \equiv 36 \equiv -1 \pmod{37} \quad \checkmark$$

Condition satisfied.


Conclusion

Since $2^{18} \equiv -1 \pmod{37}$, the test passes for witness $a = 2$.

$$\boxed{37 \text{ is PROBABLY PRIME (not composite)}}$$

37 is in fact a prime number, so Miller-Rabin correctly reports it as not composite.

Open this answer on its own page โ†’

Euler totient function

2080 ยท 10 marks

Define Euler totient function with an example. Find the GCD of 12 and 32 using Extended Euclidean algorithm.[10]

  • Euler totient function: define with an example - Numbers for GCD: $a = 12$, $b = 32$ - Method: Extended Euclidean Algorithm --- The Euler Totient Function $\phi(n)$ counts the number of positive integers from $1$ to $n$ that are relatively prime (coprime) to $n$, i.e. those integers $k$ with
Open this answer on its own page โ†’

Extended Euclidean algorithm

0 ยท 5 marks

Write an algorithm for Extended Euclidean Algorithm. Illustrate the algorithm for a=84 and b=320. [5]

  • $a = 84$ - $b = 320$ - Goal: find $\gcd(a,b)$ and integers $x, y$ such that $ax + by = \gcd(a,b)$. --- The Extended Euclidean Algorithm computes $\gcd(a,b)$ along with coefficients $x, y$ satisfying: $$ax + by = \gcd(a,b)$$ The returned triple $(d, x, y)$ satisfies $ax + by = d = \gcd(a,b)$. --...
Open this answer on its own page โ†’