Number Theory
Number Theory
Cryptosystem
Prof. M Rahaman
Some Mathematics: A Brief Introduction to Galois Fields
• A finite field, sometimes also called Galois field, is a set with a finite number of elements. Roughly
speaking, a Galois field is a finite set of elements in which we can add, subtract, multiply and invert.
• Before we introduce the definition of a field, we first need the concept of a simpler algebraic structure, a
group
2/28
• The set of integers Zₘ (also denoted as ℤₘ) consists of the elements {0, 1, …, m-1}.
• The set of real numbers forms a field with the following properties:
• Additive Group: The neutral element for the additive group is 0. For any real
number a, there exists an additive inverse, denoted as -a such that a + (-a) ≡ 0 (mod
m).
• Multiplicative Group: The neutral element for the multiplicative group is 1. Every
nonzero element a has a multiplicative inverse, denoted as 1/a such that a · a⁻¹ ≡ 1
(mod m).
3/28
• In cryptography, we are almost always interested in fields with a finite number
of elements, which we call finite fields or Galois fields. The number of elements
in the field is called the order or cardinality of the field.
4/28
Find the multiplication inverse pairs of module 5
Solution:
5/28
Content of this Chapter
6/29
Euclidean Algorithm
• Compute the greatest common divisor gcd (r0, r1) of two integers r0 and r1
• Example:
r0 = 84 = 2 . 2 . 3 . 7
r1 = 30 = 2 . 3 . 5
9
Extended Euclidean Algorithm
• An extension of the algorithm allows us to compute modular inverses, which is of
major importance in public-key
• cryptography. In addition to computing the gcd, the extended Euclidean algorithm
(EEA) computes a linear combination of the form: gcd(r0,r1) = s·r0 +t ·r1
• where s and t are integer coefficients. This equation is often referred to as
Diophantine equation.
10/29
Extended Euclidean Algorithm (cont...)
• Extend the Euclidean algorithm to find modular inverse of r1 mod r0
• EEA computes s,t, and the gcd :
• Take the relation mod r0
• Note that gcd (r0, r1) = 1 in order for the inverse to exist
11/29
Example We consider the extended Euclidean algorithm to find the coefficient of s 0 and s1. here r0 = 973 and r1 = 301
12/29
compute 12−1 mod 67. The values 12 and 67 are relatively prime, i.e., gcd(67,12) = 1. If we
apply the EEA, we obtain the coefficients s and t in gcd(67,12) = 1 = s·67+t ·12. starting with
the values r0 = 67 and r1 = 12,
Euclidian Rewrite Euclid Solution
13
Example 6.7. Compute the inverse of A(x) = x2 in the finite field GF(23) with P(x) = x3 + x + 1
14/29
Euler‘s Phi Function 1/2
• New problem, important for public-key systems, e.g., RSA:
Given the set of the m integers {0, 1, 2, …, m -1},
How many numbers in the set are relatively prime to m ?
• Testing one gcd per number in the set is extremely slow for large m. 15/29
Euler‘s Phi Function 2/2
• If canonical factorization of m known:
(where pi primes and ei positive integers)
• then calculate Phi according to the relation
16/29
Fermat‘s Little Theorem
• Given a prime p and an integer a:
• Can be rewritten as
Example: a = 2, p = 7
19
Example: How many multiplications are required to compute the simple exponentiation x 8.
Alternate method(Faster)
• which requires only three squaring that are roughly as complex as a multiplication.
• This fast method works fine but is restricted to exponents that are powers of 2, i.e., values e
and d of the form 2i .
20
How many multiplications are needed to compute general exponent
x26,
require 25 multiplications.
• A faster way is as follows:
• This approach takes a total of six operations, two multiplications and four squarings.
• We see that we can achieve the desired result by performing two basic operations:
• Squaring the current result,
• Multiplying the current result by the base element x
• But we do not know the sequence in which the squaring and multiplications have to be performed for
other exponents.
• Solution: square-and-multiply algorithm
• It provides a systematic way for finding the sequence in which we have to perform squaring and
multiplications by x for computing xH.
21
Square-and-Multiply algorithm in brief
The algorithm is based on scanning the bit of the exponent from the left (the most
significant bit) to the right (the least significant bit).
In every iteration, i.e., for every exponent bit,
• the current result is squared.
If and only if the currently scanned exponent bit has the value 1,
- a multiplication of the current result by x is executed following the squaring.
22
Square-and-Multiply
• Basic principle: Scan exponent bits from left to right and square/multiply
operand accordingly
Algorithm: Square-and-Multiply for xH mod n
Input: Exponent H, base element x, Modulus n
Output: y = xH mod n
1. Determine binary representation H = (ht, ht-1, ..., h0)2
2. FOR i = t-1 TO 0
3. y = y2 mod n
4. IF hi = 1 THEN
5. y = y * x mod n
6. RETURN y
• Rule: Square in every iteration (Step 3) and multiply current result by x if the
exponent bit hi = 1 (Step 5)
23 /34
• Modulo reduction after each step keeps the operand y small
Example: Square-and-Multiply
• Computes x26 without modulo reduction
• Binary representation of exponent: 26 =(1,1,0,1,0)2=(h4,h3,h2,h1,h0)2
Step Binary exponent Op Comment
1b x2 * x = x 3 (11)2 MUL h3 = 1
2b - (110)2 - h2 = 0
4b - (11010)2 - h0 = 0
24 /34
Speed-Up Techniques
25 /34
RSA an example
BOB
ALICE
1. Choose p = 37 and q = 89
Message x = 153
2. Compute n = p * q = 3293
3. Φ(n) = (83-1) * (263-1) = 21484
4. Choose e = 35
5. d ≡ e-1 ≡2987 mod 3293
Kpub = (3293,35)
27
The Chinese Remainder Theorem (cont. )
As we know that since p and q are prime, so
cp-1 ≡ 1 mod p and
cq-1 ≡ 1 mod q
28
CRT Rule
• If x ≡ a1 mod m1 x≡
• If x ≡ a2 mod m2
❑
… 𝑴
𝑴 𝟏 = 𝒔𝒐 𝒐𝒏. 𝒘𝒉𝒆𝒓𝒆 𝑴 =𝒎𝟏 ∗ 𝒎𝟐 …∗ 𝒎𝒏
• If x ≡ an mod mn then 𝒎𝟏 ❑
Given To find
a 1= 5 m1= 37 M1= 89 =5 M=37*89=3293
a2= 64 m2 = 89 M2= 37 77