Tutorial 2.3: Number Theory Foundations for Cryptography

Table of Contents

Learning Objectives

After completing this tutorial, you should be able to:

Overview

Modern cryptography is built upon a foundation of pure mathematics—specifically, number theory. While classical ciphers required only basic arithmetic, the cryptographic algorithms that secure today's digital world—RSA, Diffie-Hellman, Elliptic Curve Cryptography, and AES—are deeply rooted in the properties of integers, modular arithmetic, prime numbers, and finite fields.

This tutorial provides the mathematical infrastructure necessary for understanding the cryptographic algorithms covered in subsequent tutorials. We will develop the number theory concepts essential to public-key cryptography (RSA, Diffie-Hellman, ECC) and symmetric cryptography (AES, which operates in finite fields).

The journey begins with the fundamental building blocks: divisibility, modular arithmetic, and prime numbers. We then explore the Euclidean algorithm (one of the oldest known algorithms) and its extended version, which is essential for computing modular inverses—a critical operation in RSA. Euler's and Fermat's theorems provide the mathematical justification for the RSA algorithm's correctness, and finite fields form the algebraic structure in which AES and many other modern ciphers operate.

This tutorial is mathematically rigorous but designed to be accessible to undergraduate students. We provide extensive worked examples, proofs of key theorems, and practical applications that connect the mathematics to cryptographic practice.

Why Number Theory for Cryptography?

The security of modern cryptosystems rests on the presumed difficulty of certain mathematical problems:

Understanding these problems and the number theory behind them is essential for understanding why these cryptosystems are secure and how they are implemented.

Relationship to the Tutorial Series

In Tutorial 2.2, we explored classical cryptography and its historical context. The classical ciphers used simple arithmetic; modern cryptography requires deep number theory. This tutorial bridges that gap by providing the mathematical tools that will be used throughout the rest of Unit 2. Tutorials 2.4–2.10 (symmetric cryptography) will rely on finite fields; Tutorials 2.11–2.14 (public-key cryptography) will rely on modular arithmetic, prime numbers, and Euler's theorem.

Integer Arithmetic and Divisibility

We begin with the basic arithmetic of integers—the foundation upon which all number theory is built.

Definition: Divisibility
An integer d divides an integer n (written d | n) if there exists an integer k such that n = d · k. We say d is a divisor or factor of n.

If d does not divide n, we write dn.

Properties of Divisibility:

  1. If a | b and b | c, then a | c (transitivity).
  2. If a | b and a | c, then a | (b + c) and a | (bc).
  3. If a | b and a | c, then a | (m·b + n·c) for any integers m and n.
  4. If a | b and b ≠ 0, then |a| ≤ |b|.
Definition: Prime Number
A positive integer p > 1 is prime if its only positive divisors are 1 and p itself. A positive integer greater than 1 that is not prime is called composite.
Fundamental Theorem of Arithmetic
Every integer n > 1 can be expressed uniquely as a product of prime numbers (up to order). That is:

n = p1e1 · p2e2 · … · pkek

where the pi are distinct primes and the ei are positive integers.

Worked Example: Factor 360.

360 = 36 · 10 = (6²) · (2·5) = (2·3)² · 2·5 = 2² · 3² · 2 · 5 = 2³ · 3² · 5.

Thus 360 = 2³ · 3² · 5¹.

Modular Arithmetic

Modular arithmetic is arithmetic on a finite set of integers, {0, 1, 2, …, m – 1}, with operations defined modulo m. This is the arithmetic used in virtually all modern cryptosystems.

Definition: Congruence
Two integers a and b are congruent modulo m (written ab (mod m)) if m divides (ab). Equivalently, a and b have the same remainder when divided by m.

The integer m is called the modulus.

Basic Operations:

  1. Addition: (a + b) mod m = ((a mod m) + (b mod m)) mod m
  2. Subtraction: (a – b) mod m = ((a mod m) – (b mod m)) mod m
  3. Multiplication: (a · b) mod m = ((a mod m) · (b mod m)) mod m

Properties of Modular Arithmetic:

Definition: Modular Inverse
An integer a has a multiplicative inverse modulo m if there exists an integer a−1 such that a · a−1 ≡ 1 (mod m). Such an inverse exists if and only if gcd(a, m) = 1. If gcd(a, m) = 1, we say a and m are coprime or relatively prime.
Key Insight: Division in modular arithmetic is defined by multiplication by the modular inverse. The inverse exists only when the numbers are coprime. This is why prime moduli are so common in cryptography—every non-zero element of Zp (for prime p) has a multiplicative inverse.

Modular Exponentiation

Modular exponentiation—computing ae mod m—is a fundamental operation in public-key cryptography. Efficient algorithms (such as square-and-multiply) compute this in O(log e) steps.

Worked Example: Modular Exponentiation
Compute 34 mod 7.
34 = 81. 81 mod 7 = 81 – 77 = 4.
Using square-and-multiply: 32 = 9 ≡ 2 (mod 7); 34 = (32)2 ≡ 22 = 4 (mod 7).
Result: 4.

Prime Numbers

Prime numbers are the building blocks of integers and form the foundation of many cryptographic systems. The distribution of primes, their density, and methods for finding them are of central importance.

Distribution of Primes

The Prime Number Theorem states that the number of primes less than or equal to x, denoted π(x), satisfies:

π(x) ~ x / ln(x)

For example, there are approximately 1012 / ln(1012) ≈ 1012 / 27.6 ≈ 3.6 × 1010 primes less than 1012.

For cryptographic purposes, we need primes of specific sizes (e.g., 1024-bit, 2048-bit, or 3072-bit primes for RSA). The density of primes near n is about 1/ln(n), so for a 2048-bit number (≈ 10616), the probability that a randomly chosen number in that range is prime is about 1/1418. This means we can find primes efficiently by random sampling and testing.

Relatively Prime Numbers

Two integers a and b are relatively prime (or coprime) if gcd(a, b) = 1. The probability that two random integers are relatively prime is 6/π² ≈ 0.6079. This arises from the fact that the probability they share a prime factor p is 1/p², and the product over all primes of (1 – 1/p²) = 6/π².

Greatest Common Divisor and the Euclidean Algorithm

Definition: Greatest Common Divisor (GCD)
The greatest common divisor of two integers a and b, not both zero, is the largest integer d such that d | a and d | b. We write gcd(a, b) = d.

The Euclidean algorithm, one of the oldest known algorithms (Euclid, c. 300 BCE), computes the GCD efficiently without factoring the numbers.

Euclidean Algorithm
For integers ab > 0, the following recurrence holds:
gcd(a, b) = gcd(b, a mod b)
The algorithm terminates when a mod b = 0, at which point gcd = b.
Pseudocode:
function gcd(a, b):
  while b ≠ 0:
    r ← a mod b
    a ← b
    b ← r
  return a
Worked Example: Euclidean Algorithm
Compute gcd(1071, 462).
1071 = 2 · 462 + 147
462 = 3 · 147 + 21
147 = 7 · 21 + 0
Therefore, gcd(1071, 462) = 21.

Extended Euclidean Algorithm

The extended Euclidean algorithm not only computes gcd(a, b) but also finds integers x and y such that:

a·x + b·y = gcd(a, b)

These coefficients are essential for computing modular inverses. When gcd(a, b) = 1, the equation becomes:

a·x + b·y = 1

Taking both sides modulo b, we get a·x ≡ 1 (mod b), so x is the modular inverse of a modulo b.

Extended Euclidean Algorithm (Pseudocode)
function extended_gcd(a, b):
  if b = 0: return (a, 1, 0)
  (g, x1, y1) ← extended_gcd(b, a mod b)
  x ← y1
  y ← x1 – floor(a/b)·y1
  return (g, x, y)
Worked Example: Extended Euclidean Algorithm
Find the modular inverse of 3 modulo 26.
We need x such that 3x ≡ 1 (mod 26).
Run extended_gcd(26, 3):
26 = 8·3 + 2
3 = 1·2 + 1
2 = 2·1 + 0
Back-substitute:
1 = 3 – 1·2
2 = 26 – 8·3
1 = 3 – 1·(26 – 8·3) = 9·3 – 1·26
Thus 9·3 – 1·26 = 1, so 3−1 ≡ 9 (mod 26).
Verification: 3·9 = 27 ≡ 1 (mod 26). ✓

Fermat's Theorem and Euler's Theorem

These two theorems provide the mathematical basis for RSA and other public-key cryptosystems. They relate exponentiation modulo n to the totient function.

Fermat's Little Theorem
If p is a prime number and a is any integer not divisible by p, then:

ap−1 ≡ 1 (mod p)

Equivalently, for any integer a (not necessarily coprime to p), apa (mod p).
Euler's Theorem
If a and n are relatively prime (gcd(a, n) = 1), then:

aφ(n) ≡ 1 (mod n)

where φ(n) is Euler's totient function (the number of integers 1 ≤ k ≤ n with gcd(k, n) = 1).

Euler's theorem is a generalization of Fermat's Little Theorem, which is the special case where n = p is prime (φ(p) = p – 1).

Application: RSA
RSA encryption uses the fact that for a public key (n, e) and private key d satisfying e·d ≡ 1 (mod φ(n)), we have:
(Me)d ≡ Me·d ≡ M1 + k·φ(n) ≡ M · (Mφ(n))k ≡ M (mod n)
This relies on Euler's theorem: Mφ(n) ≡ 1 (mod n).

Euler's Phi (Totient) Function

Definition: Euler's Totient Function
φ(n) is the number of integers in {1, 2, …, n} that are relatively prime to n.

Properties:

  1. For a prime p: φ(p) = p – 1.
  2. For n = pk (where p is prime): φ(pk) = pk – pk−1 = pk(1 – 1/p).
  3. For n = p·q where p and q are distinct primes: φ(p·q) = (p – 1)·(q – 1).
  4. For coprime a and b: φ(a·b) = φ(a)·φ(b) (multiplicative property).
Worked Example: Computing φ(n)
φ(10): numbers 1..10 relatively prime to 10 are {1,3,7,9} → φ(10) = 4.
φ(10) = φ(2·5) = (2–1)·(5–1) = 1·4 = 4. ✓
φ(12) = φ(2²·3) = φ(2²)·φ(3) = (4–2)·(3–1) = 2·2 = 4.
Check: {1,5,7,11} → φ(12) = 4. ✓

Finite Fields and Galois Fields

A field is a set equipped with two operations (addition and multiplication) that satisfy the usual algebraic properties: associativity, commutativity, distributivity, existence of additive and multiplicative identities (0 and 1), and existence of additive inverses and multiplicative inverses for all non-zero elements.

A finite field (or Galois field) is a field with a finite number of elements. Finite fields are denoted GF(q) where q = pm is a prime power.

There are two types of finite fields used in cryptography:

  1. Prime fields GF(p): The set {0, 1, …, p–1} with arithmetic modulo p (p prime).
  2. Extension fields GF(2m): The set of polynomials of degree less than m with coefficients in GF(2), with arithmetic modulo a fixed irreducible polynomial of degree m.

Prime Fields GF(p)

In GF(p), elements are integers modulo p. Addition and multiplication are performed modulo p. Every non-zero element has a multiplicative inverse because p is prime.

Worked Example: GF(7)
Elements: {0, 1, 2, 3, 4, 5, 6}
4 + 5 = 9 ≡ 2 (mod 7)
4 · 5 = 20 ≡ 6 (mod 7)
Inverse of 3 in GF(7): 3·5 = 15 ≡ 1 (mod 7), so 3−1 = 5.

Extension Fields GF(2m)

GF(2m) is the field of polynomials over GF(2) modulo an irreducible polynomial of degree m. Elements are represented as binary polynomials:

a(x) = am−1xm−1 + … + a1x + a0, where ai ∈ {0, 1}

Addition is bitwise XOR (polynomial addition). Multiplication is polynomial multiplication modulo the irreducible polynomial.

Why GF(2m) is important: AES uses the field GF(2⁸) with the irreducible polynomial x⁸ + x⁴ + x³ + x + 1 (0x11B). The S-box and MixColumns operations in AES are defined using arithmetic in this field.

Worked Example: GF(2³) with irreducible polynomial x³ + x + 1
Elements: polynomials of degree ≤ 2.
Addition: (x² + 1) + (x + 1) = x² + x (since 1+1=0 in GF(2)).
Multiplication: (x + 1)·(x² + x) = x³ + x² + x² + x = x³ + x.
Reduce modulo x³ + x + 1: x³ ≡ –x – 1 ≡ x + 1 (since –1 = 1 in GF(2)).
Result: (x + 1) + x = 1.
So (x+1)·(x²+x) ≡ 1 (mod x³+x+1). Thus the elements are inverses.

Discrete Logarithms

Definition: Discrete Logarithm
Let g be a generator (primitive root) of a finite cyclic group G of order n. For any element h ∈ G, the discrete logarithm of h base g is the unique integer x (0 ≤ x < n) such that gx = h.

In the context of modular arithmetic, the discrete logarithm problem (DLP) is:

Given a prime p, a generator g of Zp, and an element h ∈ Zp, find x such that gxh (mod p).

Why it's hard: Computing gx mod p (modular exponentiation) is easy (polynomial time). But reversing the operation—finding x from g, h, and p—is believed to be hard (subexponential time with current algorithms). This asymmetry is the foundation of the Diffie-Hellman key exchange and the Digital Signature Algorithm (DSA).

Worked Example: Discrete Logarithm
Let p = 23, g = 5 (a primitive root modulo 23).
Compute gx mod 23 for x = 0..21:
5⁰=1, 5¹=5, 5²=25≡2, 5³=10, 5⁴=50≡4, 5⁵=20, 5⁶=100≡8, 5⁷=40≡17, 5⁸=85≡16, 5⁹=80≡11, 5¹⁰=55≡9, 5¹¹=45≡22, 5¹²=110≡18, 5¹³=90≡21, 5¹⁴=105≡13, 5¹⁵=65≡19, 5¹⁶=95≡3, 5¹⁷=15, 5¹⁸=75≡6, 5¹⁹=30≡7, 5²⁰=35≡12, 5²¹=60≡14.
If h = 11, then log₅(11) = 9 because 5⁹ ≡ 11 (mod 23).
If h = 7, then log₅(7) = 19 because 5¹⁹ ≡ 7 (mod 23).

Elliptic Curve Discrete Logarithm Problem (ECDLP)

The ECDLP is the analog of the discrete logarithm problem in the group of points on an elliptic curve over a finite field. Given points P and Q on an elliptic curve, find k such that Q = k·P (scalar multiplication). The ECDLP is believed to be harder than the DLP in finite fields, allowing for smaller key sizes for equivalent security.

Primality Testing

Generating large prime numbers for cryptographic key generation requires efficient primality testing. The goal is to determine whether a given large integer is prime (or, more practically, is prime with very high probability).

Trial Division

The simplest method: test divisibility by all primes ≤ √n. This is infeasible for large n (e.g., 1024-bit numbers).

Fermat's Primality Test

Based on Fermat's Little Theorem: if n is prime and 1 ≤ a < n, then an−1 ≡ 1 (mod n). If we find an a such that this fails, n is composite. However, there are composite numbers (Carmichael numbers) that pass the test for all a coprime to n.

Fermat Primality Test
function fermat_test(n, k):
  for i = 1 to k:
    a ← random integer in [2, n–2]
    if an−1 mod n ≠ 1: return "composite"
  return "probably prime"

Miller-Rabin Primality Test

The Miller-Rabin test is a probabilistic test that is widely used in practice. It is based on the fact that if n is prime, the only square roots of 1 modulo n are ±1.

Miller-Rabin Test
function miller_rabin(n, k):
  if n < 2: return composite
  if n = 2 or n = 3: return prime
  write n–1 = 2s·d with d odd
  for i = 1 to k:
    a ← random in [2, n–2]
    x ← ad mod n
    if x = 1 or x = n–1: continue
    for r = 1 to s–1:
      x ← x² mod n
      if x = n–1: break
    if x ≠ n–1: return "composite"
  return "probably prime"

The Miller-Rabin test has a false positive rate of at most 4−k for k iterations. With k = 40, the error probability is negligible (≈ 10−24).

Deterministic Primality Testing

The AKS primality test (2002) is a deterministic polynomial-time algorithm, but it is too slow in practice for large numbers. For cryptographic key generation, probabilistic tests with multiple iterations are standard.

Number Theory in Cryptography: A Unified View

Number Theory ConceptCryptographic ApplicationExample Algorithm
Prime numbers, factorizationRSA security relies on difficulty of factoring n = p·qRSA key generation
Modular arithmetic, Euler's theoremRSA encryption/decryption, correctness proofRSA
Discrete logarithmsSecurity of Diffie-Hellman and DSADiffie-Hellman, DSA
Finite fields (GF(p) and GF(2m))Elliptic curve cryptography, AESECC, AES
Extended Euclidean algorithmComputing modular inverses for RSA and ECCRSA key generation, ECC
Primality testingGenerating secure prime numbers for keysMiller-Rabin
Euler's totient functionRSA key generation: φ(n) = (p–1)(q–1)RSA
Chinese Remainder TheoremEfficient RSA decryption (CRT optimization)RSA-CRT

Key Takeaways

Section Summaries

Quiz

  1. What is the Fundamental Theorem of Arithmetic?
  2. AnswerThe Fundamental Theorem of Arithmetic states that every integer greater than 1 can be expressed uniquely as a product of prime numbers (up to order). This is the prime factorization theorem.
  3. When does a modular inverse of a modulo m exist?
  4. AnswerA modular inverse of a modulo m exists if and only if gcd(a, m) = 1 (i.e., a and m are relatively prime).
  5. State Fermat's Little Theorem.
  6. AnswerIf p is a prime and a is an integer not divisible by p, then ap−1 ≡ 1 (mod p). Equivalently, ap ≡ a (mod p) for all integers a.
  7. What is Euler's totient function φ(n) and how is it computed for n = p·q where p and q are distinct primes?
  8. Answerφ(n) is the number of integers 1 ≤ k ≤ n that are relatively prime to n. For n = p·q (p and q distinct primes), φ(n) = (p–1)·(q–1).
  9. What is the purpose of the extended Euclidean algorithm?
  10. AnswerThe extended Euclidean algorithm computes not only gcd(a, b) but also integers x and y such that a·x + b·y = gcd(a, b). This is used to compute modular inverses.
  11. What is a finite field and why is it important in cryptography?
  12. AnswerA finite field is a field with a finite number of elements. Finite fields are used in AES (GF(2⁸)), ECC (elliptic curves over finite fields), and many other cryptographic algorithms. They provide a structure where addition, multiplication, and inverses are well-defined and efficiently computable.
  13. What is the discrete logarithm problem?
  14. AnswerGiven a prime p, a generator g of Zp, and an element h, find x such that gx ≡ h (mod p). The difficulty of this problem underpins the security of Diffie-Hellman and DSA.
  15. Why is the Miller-Rabin test used instead of trial division for large numbers?
  16. AnswerTrial division requires testing all primes up to √n, which is infeasible for large numbers (e.g., 1024-bit integers). Miller-Rabin is a probabilistic test that runs in polynomial time and can determine primality with high probability.
  17. Compute φ(20).
  18. Answer20 = 2² · 5. φ(20) = φ(2²)·φ(5) = (4–2)·(5–1) = 2·4 = 8. The numbers relatively prime to 20: {1,3,7,9,11,13,17,19} → 8 numbers.
  19. What is the key mathematical problem underlying the security of RSA?
  20. AnswerThe security of RSA relies on the difficulty of factoring large integers. Specifically, given n = p·q (where p and q are large primes), it is computationally infeasible to find p and q when n is sufficiently large (e.g., 2048 bits).

Exercises

  1. Divisibility and Prime Factorization

    Factor the following numbers into prime factors:

    1. 180
    2. 1001
    3. 3136
    4. 10! (10 factorial)
  2. Sample Solution
    1. 180 = 18·10 = 2·3² · 2·5 = 2²·3²·5
    2. 1001 = 7·11·13
    3. 3136 = 56² = (2³·7)² = 2⁶·7²
    4. 10! = 10·9·8·7·6·5·4·3·2·1 = (2·5)·(3²)·(2³)·7·(2·3)·5·2²·3·2 = 2⁸·3⁴·5²·7
  3. Modular Arithmetic

    Compute the following:

    1. (15 + 28) mod 12
    2. (47 – 92) mod 7
    3. 6 · 9 mod 15
    4. 7³ mod 11
    5. 2¹⁰ mod 17
  4. Sample Solution
    1. 15+28=43; 43 mod 12 = 43 – 36 = 7
    2. 47–92 = –45; –45 mod 7 = –45 + 49 = 4
    3. 6·9=54; 54 mod 15 = 54 – 45 = 9
    4. 7³=343; 343 mod 11: 11·31=341, remainder 2
    5. 2¹⁰=1024; 1024 mod 17: 17·60=1020, remainder 4
  5. Euclidean Algorithm

    Compute gcd(a, b) for the following pairs using the Euclidean algorithm:

    1. gcd(154, 42)
    2. gcd(1001, 91)
    3. gcd(612, 342)
  6. Sample Solution
    1. 154 = 3·42 + 28; 42 = 1·28 + 14; 28 = 2·14 + 0 → gcd=14
    2. 1001 = 11·91 + 0 → gcd=91
    3. 612 = 1·342 + 270; 342 = 1·270 + 72; 270 = 3·72 + 54; 72 = 1·54 + 18; 54 = 3·18 + 0 → gcd=18
  7. Extended Euclidean Algorithm and Modular Inverse

    Find the modular inverse of the following numbers modulo the given modulus:

    1. 3 mod 26
    2. 7 mod 31
    3. 11 mod 20 (if it exists)
  8. Sample Solution
    1. 3·9 = 27 ≡ 1 (mod 26) → 3−1 ≡ 9 (mod 26)
    2. 7·9 = 63 ≡ 1 (mod 31) → 7−1 ≡ 9 (mod 31) (since 63–62=1)
    3. gcd(11, 20) = 1, so inverse exists. 11·11 = 121 ≡ 1 (mod 20) → 11−1 ≡ 11 (mod 20)
  9. Euler's Totient Function

    Compute φ(n) for the following values of n:

    1. φ(17)
    2. φ(27)
    3. φ(100)
    4. φ(256)
  10. Sample Solution
    1. 17 is prime → φ(17) = 16
    2. 27 = 3³ → φ(27) = 27 – 9 = 18
    3. 100 = 2²·5² → φ(100) = φ(2²)·φ(5²) = (4–2)·(25–5) = 2·20 = 40
    4. 256 = 2⁸ → φ(256) = 256 – 128 = 128
  11. Euler's Theorem Verification

    Verify Euler's theorem for the following cases:

    1. a = 3, n = 10
    2. a = 2, n = 9
  12. Sample Solution
    1. φ(10)=4; 3⁴=81; 81 mod 10 = 1 → 3⁴ ≡ 1 (mod 10). ✓
    2. φ(9)=6; 2⁶=64; 64 mod 9 = 64 – 63 = 1 → 2⁶ ≡ 1 (mod 9). ✓

Homework

  1. RSA Key Generation Preliminaries

    Suppose you choose p = 17 and q = 23 for RSA.

    1. Compute n = p·q.
    2. Compute φ(n).
    3. Choose an encryption exponent e such that 1 < e < φ(n) and gcd(e, φ(n)) = 1. Justify your choice.
    4. Use the extended Euclidean algorithm to compute the decryption exponent d.
    5. Verify that e·d ≡ 1 (mod φ(n)).

    This exercise previews RSA key generation—you will use these same mathematical operations in Tutorial 2.12.

  2. Sample Answer

    a. n = 17·23 = 391

    b. φ(n) = (17–1)·(23–1) = 16·22 = 352

    c. Choose e = 3. Check gcd(3,352) = 1 (since 352 mod 3 = 1). ✓

    d. Find d such that 3·d ≡ 1 (mod 352). Extended Euclid: 352 = 117·3 + 1; 3 = 3·1 + 0. Back-substitute: 1 = 352 – 117·3 → 3·(−117) + 352·1 = 1, so d ≡ −117 ≡ 235 (mod 352).

    e. 3·235 = 705; 705 mod 352 = 705 – 704 = 1. ✓

  3. Finite Field Arithmetic in GF(2⁸)

    AES uses GF(2⁸) with irreducible polynomial x⁸ + x⁴ + x³ + x + 1 (0x11B).

    1. Compute the sum (in GF(2⁸)) of the polynomials (x⁷ + x⁵ + x² + 1) and (x⁶ + x⁵ + x³ + x).
    2. Compute the product (in GF(2⁸)) of (x + 1) and (x⁷ + x⁶ + x³ + x).
  4. Sample Answer

    a. Addition is XOR: (x⁷ + x⁵ + x² + 1) + (x⁶ + x⁵ + x³ + x) = x⁷ + x⁶ + (x⁵ + x⁵) + x³ + x² + x + 1 = x⁷ + x⁶ + x³ + x² + x + 1.

    b. (x+1)·(x⁷ + x⁶ + x³ + x) = x·(x⁷+x⁶+x³+x) + 1·(x⁷+x⁶+x³+x) = x⁸+x⁷+x⁴+x² + x⁷+x⁶+x³+x = x⁸ + (x⁷+x⁷) + x⁶ + x⁴ + x³ + x² + x = x⁸ + x⁶ + x⁴ + x³ + x² + x. Now reduce modulo x⁸+x⁴+x³+x+1: x⁸ ≡ x⁴+x³+x+1 (since x⁸ = x⁸, subtract to get 0). So result = (x⁴+x³+x+1) + x⁶+x⁴+x³+x²+x = x⁶ + (x⁴+x⁴) + (x³+x³) + x² + (x+x) + 1 = x⁶ + x² + 1.

  5. Discrete Logarithm in a Small Group

    Let p = 17 and g = 3 (a primitive root modulo 17).

    1. Compute the powers g⁰, g¹, g², …, g¹⁵ modulo 17 to verify that g is indeed a primitive root.
    2. Find log₃(13) modulo 17.
    3. Find log₃(5) modulo 17.
  6. Sample Answer

    a. Powers of 3 mod 17: 3⁰=1, 3¹=3, 3²=9, 3³=27≡10, 3⁴=30≡13, 3⁵=39≡5, 3⁶=15, 3⁷=45≡11, 3⁸=33≡16, 3⁹=48≡14, 3¹⁰=42≡8, 3¹¹=24≡7, 3¹²=21≡4, 3¹³=12, 3¹⁴=36≡2, 3¹⁵=6. All non-zero elements {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16} appear, so 3 is primitive.

    b. From the table, 3⁴ ≡ 13 (mod 17), so log₃(13) = 4.

    c. From the table, 3⁵ ≡ 5 (mod 17), so log₃(5) = 5.

  7. Miller-Rabin Primality Test

    Apply the Miller-Rabin test to n = 221 with a = 174. Show all steps and determine whether 221 is prime or composite.

    Hint: n−1 = 220 = 2²·55, so s=2 and d=55.

  8. Sample Answer

    n = 221, n−1 = 220 = 2²·55 → s=2, d=55.

    a = 174.

    x = ad mod n = 174⁵⁵ mod 221.

    Compute using modular exponentiation: 174² = 30276; 30276 mod 221: 221·137 = 30277, so 174² ≡ −1 ≡ 220 (mod 221).

    Then 174⁵⁵ = 174²·²⁷·¹ = (174²)²⁷·174. Since 174² ≡ −1, (174²)²⁷ ≡ (−1)²⁷ = −1 ≡ 220. So x = 220·174 = 38280; 38280 mod 221: 221·173 = 38233, remainder 47. So x = 47.

    Since x ≠ 1 and x ≠ n−1 (i.e., 220), we compute x² mod n: 47²=2209; 2209 mod 221: 221·9 = 1989, remainder 220. So x² ≡ 220 = n−1.

    Since we found a square root of 1 (x² ≡ −1), this is a "likely prime" result for this test.

    However, 221 = 13·17, so 221 is composite. Miller-Rabin with a single base did not catch it (it's a strong pseudoprime to base 174). Additional bases would catch it.

  9. Research: The AKS Primality Test

    Research the AKS primality test (Agrawal–Kayal–Saxena, 2002). Write a 300-word summary that addresses:

  10. Sample Answer

    A complete answer would explain that AKS was the first deterministic polynomial-time primality test (O(log¹² n) time). The key idea is based on the identity (x + a)ⁿ ≡ xⁿ + a (mod n) for all a when n is prime. The test checks this identity modulo (xʳ – 1) for carefully chosen r. Although theoretically significant, AKS is not practical for the large numbers used in cryptography (it is slower than Miller-Rabin). For cryptographic applications, probabilistic tests like Miller-Rabin remain the standard because they are fast and provide negligible error probability. However, AKS provides a theoretical guarantee that the problem of primality testing is in P, which has important theoretical implications.

Summary

This tutorial has provided the mathematical foundation necessary for understanding modern cryptographic algorithms. We began with the basic concepts of integer arithmetic, divisibility, and prime numbers, establishing the Fundamental Theorem of Arithmetic as the cornerstone.

We explored modular arithmetic in detail, including the concept of modular inverses and the conditions under which they exist. The Euclidean algorithm and its extended version provide efficient methods for computing GCDs and modular inverses—operations that are used repeatedly in cryptographic implementations.

Fermat's Little Theorem and Euler's Theorem provide the mathematical basis for RSA and other public-key systems. We saw how Euler's totient function φ(n) enables the RSA key generation process, and how Euler's theorem guarantees that encryption followed by decryption returns the original message.

Finite fields—particularly GF(p) and GF(2m)—provide the algebraic structures used in AES, ECC, and many other algorithms. The discrete logarithm problem, both in finite fields and on elliptic curves, is the basis for Diffie-Hellman and ECC security.

Finally, we examined primality testing, an essential component of cryptographic key generation. The Miller-Rabin test provides an efficient probabilistic method for generating large primes, which is used in practice for RSA and other public-key systems.

With this mathematical foundation in place, we are now prepared to explore cryptographic algorithms in depth—starting with symmetric encryption in the next tutorial.

Connection to the Next Tutorial

In Tutorial 2.4: Symmetric Encryption Fundamentals, we will apply the concepts of finite fields and modular arithmetic to understand the design and operation of symmetric key ciphers. We will explore the principles of confusion and diffusion (introduced in Tutorial 2.1) and see how they are implemented using the mathematical structures developed here.