03. Number Theory and Finite Fields

Discrete mathematics: cyroptology deals with finite objects (e.g. alphabets, blocks of characters)

Modular arithmetic; deals with finite number of values.

Basic Number Theory

Factorization

Z={,3,2,1,0,1,2,3,}\mathbb{Z} = \{ \dots, -3, -2, -1, 0, 1, 2, 3, \dots \} is the set of integers.

Given a,bZa, b \in \mathbb{Z}, aa divides bb if there exists kZk \in \mathbb{Z} such that ak=bak = b. In this case, aa is a factor of bb: aba|b.

An integer p>1p > 1 is prime iff its only divisors are 11 and pp.

Properties

If aba|b and aca|c, then a(b+c)a|(b+c).

If pp is prime and pabp|ab, pap|a OR pbp|b.

Division algorithm

Given a,bZa, b \in \mathbb{Z} such that a>ba > b, then there exists q,rZq, r \in \mathbb{Z} such that:

a=bq+r a = bq + r

qq is the quotient and 0r>b0 \ge r \gt b is the remainder. r<a2r \lt \frac{a}{2}.

Greatest Common Divisor

dd is the GCD of aa and bb; gcd(a,b)=dgcd(a, b) = d if:

aa and bb are relatively prime if gcd(a,b)=1gcd(a, b) = 1

Euclidean Algorithm

To find d=gcd(a,b)d = gcd(a, b):

a=bq1+r1 for 0>r1>bb=r1q2+r2 for 0>r2>r1r1=r2q3+r3 for 0>r3>r2rk2=rk1qk+rk for 0>rk>rk1rk1=rkqk+1 with rk+1=0 \begin{aligned} a &= bq_1 + r_1 \text{ for } 0 \gt r_1 \gt b \\ b &= r_1q_2 + r_2 \text{ for } 0 \gt r_2 \gt r_1 \\ r_1 &= r_2q_3 + r_3 \text{ for } 0 \gt r_3 \gt r_2 \\ & \dots \\ r_{k - 2} &= r_{k - 1}q_k + r_k \text{ for } 0 \gt r_k \gt r_{k - 1} \\ r_{k - 1} &= r_kq_{k + 1} \text{ with } r_{k + 1} = 0 \end{aligned}

Hence, d=rk=gcd(a,b)d = r_k = gcd(a, b).

In psuedo-code:

def gcd(a, b):
  r[-1] = a
  r[0] = b
  k = 0
  while r[k] != 0:
    q[k] = floor(r[k - 1]/r[k])
    r[r + 1] = r[k - 1] - q[k]r[k]
    k = k + 1
  
  k = k - 1
  return r[k]
Back-Substitution

Find xx, yy in ax+by=d=rkax + by = d = r_k.

rk3=rk2qk1+rk1 r_{k - 3} = r_{k - 2}q_{k - 1} + r_{k - 1}

Can be rewritten as:

rk1=rk3rk2qk1 r_{k - 1} = r_{k - 3} - r_{k - 2}q_{k - 1}

rk2=rk1qk+rkr_{k - 2} = r_{k - 1}q_k + r_k can be rewritten as rk=rk2rk1qkr_k = r_{k - 2} - r_{k - 1}q_k. rk1r_{k - 1} can be substituted with the value above. Hence, this process can be repeated until you have rk1r_{k - 1} in terms of the original values.

Example: gcd(17,3)gcd(17, 3):

17=3×5+23=2×1+12=1×2 \begin{aligned} 17 &= 3 \times 5 + 2 \\ 3 &= 2 \times 1 + 1 \\ 2 &= 1 \times 2 \end{aligned}

Back-substitution:

1=32×1=3(173×5)×1=17×1+3×6 \begin{aligned} 1 &= 3 - 2 \times 1 \\ &= 3 - (17 - 3 \times 5) \times 1 \\ &= 17 \times - 1 + 3 \times 6 \end{aligned}

The result shows that 316(mod17)3^{-1} \equiv 6 \pmod{17}.

Modular Arithmetic

bb is a residue of a(modn)a \pmod n if ab=kna - b = kn for some integer kk:

ab(modn)ab=kn a \equiv b \pmod n \Longleftrightarrow a - b = kn

Given ab(modn)a \equiv b \pmod n and cd(modn)c \equiv d \pmod n:

a+cb+d(modn)acbd(modn)kakb(modn) \begin{aligned} a + c &\equiv b + d \pmod n \\ ac &\equiv bd \pmod n \\ ka &\equiv kb \pmod n \end{aligned}

b(modn)b \pmod n denotes the unique value aa in the complete set of residues {0,1,,n1}\{ 0, 1, \dots, n-1\} such that:

ab(modn) a \equiv b \pmod n

In other words, b(modn)b \pmod n is the remainder after dividing aa by nn.

Residue Class

The set {r0,r1,,rn1}\{ r_0, r_1, \dots, r_{n - 1}\} is a complete set of residues modulo nn if for every aNa \in \mathbb{N}, ari(modn)a \equiv r_i \pmod n for exactly one rir_i.

The set {0,1,,n1}\{ 0, 1, \dots, n - 1\} is denoted as Zn\mathbb{Z}_n.

Groups

A group G\mathbb{G} is a set with binary operation \cdot and:

A group is abelian when it is the operation is commutative; ab=baa \cdot b = b\cdot a for a,bGa, b \in \mathbb{G}.

Cyclic Groups

The order G|\mathbb{G}| of a group G\mathbb{G} is the number of elements in G\mathbb{G}.

gkg^k denotes the repeated application of gGg \in \mathbb{G} using the group operation. e.g. g3=gggg^3 = g \cdot g \cdot g.

The order g|g| of gGg \in \mathbb{G} is the smallest integer kk such that gk=1g^k = 1.

gg is a generator for G\mathbb{G} if g=G|g| = |\mathbb{G}|.

A group is cyclic if it has a generator.

Computing Inverses Modulo nn

The inverse if aa (if it exists) is a value xx such that ax1(modn)ax \equiv 1 \pmod n; it is written as a1(modn)a^{-1} \pmod n. This means that aa must be coprime to nn.

Theorem: let 0>a>n0 \gt a \gt n; aa has an inverse modulo nn iff gcd(a,n)=1gcd(a, n) = 1.

The Euclidean algorithm can be used to find the inverse of aa.

If xx such that ax1(modn)ax \equiv 1 \pmod n, there is an integer yy such that ax=1+ynax = 1 + yn.

Hence, starting from gcd(a,n)=1gcd(a, n) = 1, use back substitution to find xx and yy in the equation ax+ny=1ax + ny = 1. the yy value gives the inverse.

Group of Primes Modulus Zp\mathbb{Z}^*_p

Zp=1,2,,p1\mathbb{Z}^*_p = {1, 2, \dots, p - 1} is a complete set of residues modulo the prime pp with the value 00 removed.

Properties:

It can be thought of as the multiplicative group of integers 1,2,,p11, 2, \dots, p - 1 which have inverses modulo pp.

Finding Generators

A generator of Zp\mathbb{Z}^*_p is an element of order p1p - 1

Lagrange theorem: the order of any element must exactly divide p1p - 1.

To find a generator of Zp\mathbb{Z}^*_p:

Example

Find a generator for Z11\mathbb{Z}_{11}^*.

Z11|\mathbb{Z}_{11}^*| is 1010 as 1111 is prime. 10=2510 = 2 \cdot 5, so to check if gZ11g \in \mathbb{Z}_{11}^* is a generator, check if g2≢1(mod11)g^2 \not\equiv 1 \pmod{11}, g5≢1(mod11)g^5 \not\equiv 1 \pmod{11}:

Groups of Composite Modulus Zp\mathbb{Z}^*_p

For any non-prime nn, Zn\mathbb{Z}_n^* is a group of residues that have an inverse under multiplication.

Properties:

e.g. Z6={1,5}\mathbb{Z}_6^* = \{1, 5\} (elements coprime to 66).

Example

Find a generator for Z9\mathbb{Z}_9^*.

Z9={1,2,4,5,7,8,}\mathbb{Z}_9^* = \{ 1, 2, 4, 5, 7, 8, \} so Z9=6|\mathbb{Z}_9^*| = 6

Fields

A field F\mathbb{F} is a set with two binary operations, ++ and \cdot, with the properties such that:

Theorem: only finite fields of size pnp^n exist, where pp is a prime and nn is any positive integer.

Finite Field GF(p)GF(p)

For a finite field GF(p)=ZpGF(p) = \mathbb{Z}_p:

Finite Field GF(2)GF(2)

GF(2)GF(2) is the simplest field with two elements, 00 and 11:

Finite Field GF(28)GF(2^8)

GF(28)GF(2^8) is the field used for calculations in AES (block cipher).

Arithmetic in this field is considered as polynomial arithmetic where the field elements are polynomials with binary coefficients. e.g. 00101101x5+x3+x2+10010 1101 \leftrightarrow x^5 + x^3 + x^2 + 1

Properties: