Greatest Common Divisor and Least Common Multiple
The Greatest Common Divisor (GCD) and Least Common Multiple (LCM) are fundamental concepts in number theory that play crucial roles in cryptography, particularly in key generation and modular arithmetic operations.
Greatest Common Divisor (GCD)
Definition
The Greatest Common Divisor (also called Greatest Common Factor) of two integers a and b is the largest positive integer that divides both a and b.
Notation: GCD(a,b) or (a,b)
Properties of GCD
- For any integer n, GCD(n,0) = |n|
- GCD(a,b) = GCD(|a|,|b|)
- GCD(a,b) = GCD(b,a)
- GCD(a,b) = GCD(a-b,b) when a > b
- If m is any integer, then GCD(a,b) = GCD(a+mb,b)
The Euclidean Algorithm
The most efficient way to compute the GCD of two numbers is using the Euclidean algorithm.
Algorithm:
- Let a and b be the two numbers
- Divide a by b to get quotient q and remainder r
- If r = 0, b is the GCD
- Otherwise, set a = b and b = r, and repeat from step 2
Example:
Find GCD(48,18)
48 = 2 × 18 + 12
18 = 1 × 12 + 6
12 = 2 × 6 + 0
Therefore, GCD(48,18) = 6
Extended Euclidean Algorithm
The Extended Euclidean Algorithm finds integers x and y such that:
ax + by = GCD(a,b)
This is particularly important in cryptography for finding multiplicative inverses in modular arithmetic.
Example:
Find x and y such that 48x + 18y = GCD(48,18)
48 = 2 × 18 + 12
18 = 1 × 12 + 6
12 = 2 × 6 + 0
Working backwards:
6 = 18 - 1(12)
6 = 18 - 1(48 - 2(18))
6 = 3(18) - 1(48)
Therefore, x = -1 and y = 3
Least Common Multiple (LCM)
Definition
The Least Common Multiple of two integers a and b is the smallest positive integer that is divisible by both a and b.
Notation: LCM(a,b) or [a,b]
Properties of LCM
- LCM(a,b) = |a × b| ÷ GCD(a,b)
- LCM(a,b) = LCM(|a|,|b|)
- LCM(a,b) = LCM(b,a)
- For any integers a and b, GCD(a,b) × LCM(a,b) = |a × b|
Computing LCM
The most efficient way to compute LCM is:
- First find GCD using the Euclidean algorithm
- Then use the formula: LCM(a,b) = |a × b| ÷ GCD(a,b)
Example:
Find LCM(48,18)
We found earlier that GCD(48,18) = 6
LCM(48,18) = |48 × 18| ÷ 6
= 864 ÷ 6
= 144
Applications in Cryptography
1. Key Generation
- GCD is used to verify coprimality in RSA key generation
- Extended Euclidean Algorithm is used to find private keys
2. Modular Arithmetic
- Finding multiplicative inverses modulo n
- Chinese Remainder Theorem applications
3. RSA Cryptosystem
- Checking if chosen values are suitable for keys
- Computing Euler's totient function φ(n)
Practice Problems
- Find GCD(56,42) using the Euclidean algorithm
- Find x and y such that 56x + 42y = GCD(56,42)
- Calculate LCM(56,42)
- Show that GCD(56,42) × LCM(56,42) = 56 × 42
Solutions:
GCD(56,42):
56 = 1 × 42 + 14 42 = 3 × 14 + 0 Therefore, GCD(56,42) = 14
Extended Euclidean Algorithm:
56 = 1 × 42 + 14 42 = 3 × 14 + 0 14 = 56 - 1(42) Therefore, x = 1 and y = -1
LCM(56,42):
LCM = (56 × 42) ÷ GCD(56,42) = 2352 ÷ 14 = 168
Verification:
GCD × LCM = 14 × 168 = 2352 56 × 42 = 2352
Next Steps
After mastering GCD and LCM, you should study:
- Modular multiplicative inverses
- Chinese Remainder Theorem
- Euler's totient function
- RSA key generation
These concepts build directly on your understanding of GCD and LCM.
Common Pitfalls
- Forgetting that GCD(a,0) = |a|
- Not considering negative numbers
- Not verifying coprimality in cryptographic applications
- Inefficient computation methods for large numbers
Remember that efficient GCD computation is crucial in cryptographic applications where large numbers are involved.