Lecture Outline#
- Review of the Extended Euclidean Algorithm
- Expressing the GCD as a linear combination
- Modular multiplicative inverse
- Introduction to the Chinese Remainder Theorem (CRT)
- Introduction to the RSA cryptographic algorithm
Learning Outcomes#
By the end of this lecture, students should be able to:
- Understand the purpose of the Extended Euclidean Algorithm
- Express the GCD as a linear combination
- Compute modular multiplicative inverses
- Identify when a multiplicative inverse exists
- Solve simultaneous congruence equations using CRT
- Perform the basic RSA Key Generation
Extended Euclidean Algorithm (Review)#
The Extended Euclidean Algorithm is an algorithm to compute integers 𝑥 and 𝑦 such that.
ax+by=gcd(a,b)
By reversing the steps in the Euclidean algorithm, it is possible to find these integers 𝑥 and 𝑦.
Example:
Find gcd(12,34) and Express it as a Linear Combination
Solution:
341210=12(2)+10=10(1)+2=2(5)+02=12+10(−1)=12+[34+12(−2)](−1)=12+34(−1)+12(2)=12(3)+34(−1)Hence, the coefficients are x=3 and y=−1.
This process allows you to find 𝑥 and 𝑦 such that 12x+34y=gcd(12,34)
Example:
Find gcd(93,219) and Express it as a Linear Combination
Solution:
2199333276=93(2)+33=33(2)+27=27(1)+6=6(4)+3=3(2)+03=27+6(−4)=27+[33+27(−1)](−4)=27+33(−4)+27(4)=33(−4)+27(5)=33(−4)+[93+33(−2)](5)=33(−4)+93(5)+33(−10)=33(−14)+93(5)=[219+93(−2)](−14)+93(5)=219(−14)+93(28)+93(5)=93(33)+219(−14)Hence, the coefficients are x=33 and y=−14.
This process allows you to find 𝑥 and 𝑦 such that 93x+219y=gcd(93,219)=3
Assignment: Complete these exercises and submit during seminar class
- Find the gcd and Express them as Linear Combinations:
- gcd(120,35)
- gcd(145,252)
- gcd(100,240)
Show how you computed your answers.
Only handwritten solutions.
No copy-paste will be accepted.
Modular Multiplicative Inverse#
The modular multiplicative inverse of an integer a modulo m is an integer x such that the product ax is congruent to 1 modulo m.
ax≡1modm
Here 𝑥 is the multiplicative inverse of a, and we can also write the above equation as
amodm=1modm⇒axmodm=1
The existence of such an x depends on a and m being coprime, i.e., gcd(a,m)=1. Otherwise we can say that there is no multiplicative inverse.
Example:
Find a number 𝑥 such that: 3x≡1 (mod12)
Trail and Error Method#
3×1mod173×2mod173×3mod173×4mod173×5mod173×6mod17=3=6=9=12=15=1Here the value of x=6. This method is very difficult when the number is very large.
Extended Euclidean Algorithm Method#
gcd1732(3,17)=3(5)+2=2(1)+1=1(2)+01=3+2(−1)=3+[17+3(−5)](−1)=3+17(−1)+3(5)=3(6)+17(−1)ax+by=gcd(a,b)3x+17y=1⇒x=6Here x=6 is the multiplicative inverse
Example:
Find a number 𝑥 such that: 35x≡1 (mod8)
Another Approach#
We can write 35xmod8=1mod8
(a×b)modn(35×x)mod835xmod835xmod8=[(amodn)×(bmodn)]modn=[(35mod8)×(xmod8)]mod8=[(3×x)mod8]=3xmod8=1mod83xmod83xmod83×3mod8=1mod8=1mod8=1Therefore, x=3 is the multiplicative inverse.
Check
35×3mod8=1
105mod8=1
Example:
Find a number 𝑥 such that:
- 40x≡1mod7
- 20x≡1mod3
Waiting…
Application#
The modular multiplicative inverse is crucial in various fields, including cryptography, where it’s used in algorithms like RSA for public key encryption and decryption.
Chinese Remainder Theorem#
The Chinese Remainder Theorem (CRT) is a powerful tool in number theory and discrete mathematics that allows you to solve a system of simultaneous linear congruences with different moduli, under the condition that the moduli are pairwise coprime (i.e., the gcd of each pair of moduli is 1).
Assume we have a system of equations:
xx..x≡a1 (modm1)≡a2 (modm2)...............≡ak (modmk)Where m1,m2,...,mk are pairwise coprime. The theorem states that there is a unique solution modulo 𝑀, where 𝑀 is the product of all the moduli (M=m1×m2×...×mk).
Step-by-Step Method to Find the Solution
- Compute 𝑀: M=m1×m2×...×mk.
- Compute the partial products: For each 𝑖, calculate Mi=miM .
- Find the modular inverses: For each 𝑖, find an integer yi such that Miyi≡1 (modmi). This yi is the modular inverse of Mi modulo mi.
- Calculate the solution: The solution 𝑥 can be found as follows:
x=(a1M1y1+a2M2y2+...+akMkyk)modM
Example
Let’s solve the system:
xxx≡2 (mod3)≡3 (mod5)≡2 (mod7)Step 1: Compute 𝑀: M=m1×m2×m3.
M=3×5×7=105
Step 2: Compute the partial product Mi=miM
M1M2M3=m1M=3105=35=m2M=5105=21=m3M=7105=15Step 3: Find the modular inverses.
- Find y1 such that 35y1≡1 (mod3)
y1=2 works because
35×2=70≡1 (mod3)
- Find y2 such that 21y2≡1 (mod5)
y2=1 works because
21×1=21≡1 (mod5)
- Find y3 such that 15y3≡1 (mod7)
y3=1 works because
15×1=15≡1 (mod7)
Step 4: Calculate the solution.
xxxxx=(a1M1y1+a2M2y2+…+akMkyk)modM=(2×35×2+3×21×1+2×15×1)mod105=(140+63+30)mod105=233mod105=23Thus, x=23 is the unique solution that satisfies all the original congruences.
Assignment: Complete this exercise and submit during seminar class
Determine the value of 𝑥 using the Chinese Remainder Theorem
xxx≡3 (mod5)≡1 (mod7)≡6 (mod8)Show how you computed your answers.
Only handwritten solutions.
No copy-paste will be accepted.
RSA Algorithm#
The RSA algorithm is a widely used public key cryptography system that enables secure data transmission.
Named after its inventors Rivest, Shamir, and Adleman, RSA is based on the practical difficulty of factoring the product of two large prime numbers, a problem known as integer factorization.
How RSA Works#
Key Generation:
- Choose two large prime numbers, p and q.
- Calculate n: n = p × q. This n is used as the modulus for both the public and private keys.
- Calculate the totient function, ϕ(n)=(p−1)×(q−1).
- Choose an integer e such that 1<e<ϕ(n) and e is coprime to ϕ(n); e is the public exponent.
- Determine d as the modular multiplicative inverse of e modulo ϕ(n). This means d is the number such that (d×e)modϕ(n)=1. d is the private exponent.
Encryption:
Given a plaintext message M, the ciphertext C is computed as:
C=MemodnDecryption:
To retrieve the plaintext M from the ciphertext C, use the private key d:
M=Cdmodn
Example
Choose two prime numbers:
- Let p=11 and q=3.
Compute n and ϕ(n):
- n=p×q=11×3=33
- ϕ(n)=(p−1)×(q−1)=10×2=20.
Choose e:
- Let e=7 (which is coprime to ϕ(n)=20).
Compute d:
- d is the modular multiplicative inverse of e modulo ϕ(n).
d needs to satisfy d×7≡1 (mod20) .
By testing values or using extended Euclidean algorithm, we find d=3 (since 3×7=21≡1 (mod20)).
Example
Encryption:SupposeCCCCthe plaintext M=4=Memodn=47mod33=16384mod33=16Decryption:CMMMM=16=Cdmodn=163mod33=4096mod33=4Try#
Try: Complete the RSA Encryption Algorithm
Choose two prime numbers:
- Let p=61 and q=53.
Compute n and ϕ(n):
- n=p×q = …………………………………
- ϕ(n) = …………………………………
Choose e:
- Let e=17
Compute d: …………………………………
Encryption:
Suppose the plaintext M=3
C = …………………………………
Decryption:
M = …………………………………