Unit V Modular Arithmetic
Unit V Modular Arithmetic
Unit V Modular Arithmetic
• Theorem 8: If (𝒂, 𝒃) = 𝟏 and if 𝒄|𝒂 and 𝒅|𝒃 • Theorem 11: Every integer 𝒏 > 𝟏 is either a
then (𝒄, 𝒅) = 𝟏 prime number or a product of prime numbers
Proof: (𝑎, 𝑏) = 1 ⇒ 𝑠𝑎 + 𝑡𝑏 = 1 -(1) and (The Fundamental Theorem of Arithmetic)
𝑐|𝑎 ⇒ 𝑎 = 𝑐𝑘1 -(2) Proof: If 𝑛 is a prime, the theorem is proved. If
𝑑|𝑏 ⇒ 𝑏 = 𝑑𝑘2 -(3) 𝑛 ≠ 1 and 𝑛 is not a prime, then 𝑛 = 𝑎𝑏, for some
Substituting (3,2) in (1) ⇒ 𝑠𝑐𝑘1 + 𝑡𝑑𝑘2 = 1 𝑎, 𝑏 ∈ 𝑍 ∋ 0 < 𝑎 < 𝑛, 0 < 𝑏 < 𝑛.
⇒ (𝑠𝑘1 )𝑐 + (𝑡𝑘2 )𝑑 = 1 Let 𝑃(𝑛) stands for the proposition that 𝑛 can be
⇒ (𝑐, 𝑑) = 1 factorized as stated in the theorem.
Let us assume that 𝑃(𝑘) is true for 𝑘 < 𝑛. Then
• Theorem 9: If (𝒂, 𝒃) = 𝟏 then (𝒂𝒏 ,𝒃 𝒏)
= 𝟏 for 𝑃(𝑎) and 𝑃(𝑏) are true, i.e., 𝑎 and 𝑏 can be
all 𝒏 ≥ 𝟏 factorized as a product of positive prime numbers.
Proof: (𝑎, 𝑏) = 1 ⇒ 𝑠𝑎 + 𝑡𝑏 = 1 -(1) i.e., 𝑎 = 𝑝1 𝑝2 … 𝑝𝑟 and 𝑏 = 𝑞1 𝑞2 … 𝑞𝑟 .
(𝑠𝑎 + 𝑡𝑏)2𝑛−1 = 1 ⇒ 𝑛 = 𝑎𝑏 = (𝑝1 𝑝2 … 𝑝𝑟 )(𝑞1 𝑞2 … 𝑞𝑟 )
𝟐𝒏 − 𝟏 (𝒂𝒔)𝟐𝒏−𝟏 𝟐𝒏 − 𝟏 (𝒂𝒔)𝟐𝒏−𝟐 (𝒃𝒕)𝟏 Hence 𝑃(𝑛) is true, i.e., the theorem is proved.
( ) +( )
𝟎 𝟏
𝟐𝒏 − 𝟏 (𝒂𝒔)𝟐𝒏−𝟑 (𝒃𝒕)𝟐
+( ) +⋯ • Theorem 12: There are infinitely many prime
𝟐
𝟐𝒏 − 𝟏 (𝒂𝒔)𝒏 (𝒃𝒕)𝒏−𝟏 numbers
+( )
𝒏−𝟏 Proof: Let there be a finite number of primes
2𝑛 − 1 (𝑎𝑠)𝑛−1 (𝑏𝑡)𝑛 (𝑝1 , 𝑝2 , … 𝑝𝑛 )
+( ) +⋯
𝑛
2𝑛 − 1 (𝑏𝑡)2𝑛−1 Consider 𝑝 = 𝑝1 𝑝2 … 𝑝𝑛 + 1 > 𝑝𝑖 ∀𝑖
+( ) =1
2𝑛 − 1 Since there are finite primes and 𝑝 is greater than
Here first 𝑛 terms are divisible by 𝑎𝑛 and last 𝑛 all, we can conclude that 𝒑 is not prime.
𝑛
terms are divisible by 𝑏 , hence above equation 𝑝
Let divide 𝑝 by 𝑝1 ⇒ 𝑝 = 𝑝2 𝑝3 … 𝑝𝑛 + 𝑝
1
1 1
can be written as
𝑎𝑛 𝑢 + 𝑏 𝑛 𝑣 = 1
Page 1
Modular Arithmetic
1
Clearly 𝑝 is not an integer, it is true for any 𝑝𝑖 , • Write 𝑎 in quotient remainder form (𝑎 = 𝑏 ⋅ 𝑞 +
1
𝑟)
hence none of the 𝑝𝑖 is a factor of 𝑝.
• Find GCD(B,R) using the Euclidean Algorithm
𝑝 is a number that can not be factorized by the
since GCD(A,B) = GCD(B,R)
prime numbers hence, from Theorem 11, 𝒑 must
be prime
𝑝 is prime and not prime. Which is a contradiction.
Find the GCD of the following using the division
So our assumption is wrong. i.e., there are
algorithm
infinitely many primes.
i) 27, 87 ii) 165,418 iii) 30, 42, 70
iv) 50,90,240 v) 18,24,30,38
• Theorem 13: If a prime 𝒑 does not divide 𝒂,
i) 27, 87 𝑎 = 𝑏𝑞 + 𝑟
then (𝒑, 𝒂) = 𝟏
𝑞 𝑎 𝑏 𝑟
Proof: Let (𝑝, 𝑎) = 𝑑
3 87 27 6
⇒ 𝑑|𝑝 but 𝑝 is prime, so 𝑑 must be 1 or 𝑝 itself.
4 27 6 3
Also 𝑑|𝑎 ⇒ 𝑑 ≠ 𝑝, because 𝑝 ∤ 𝑎. ⇒ 𝑑 = 1.
2 6 3 0
3 0
• Theorem 14: If a prime 𝒑 divides 𝒂𝒃, then 𝒑|𝒂
or 𝒑|𝒃. More generally, if a prime 𝒑 divides a
ii) 165, 418 𝑎 = 𝑏𝑞 + 𝑟
product 𝒂𝟏 𝒂𝟐 … 𝒂𝒏 then 𝒑 divides at least one of
the factors 𝑞 𝑎 𝑏 𝑟
Proof: Suppose 𝑝|𝑎𝑏 and that 𝑝 ∤ 𝑎. We will 2 418 165 88
prove that 𝑝|𝑏. 1 165 88 77
From theorem 13 we have (𝑝, 𝑎) = 1, then from 1 88 77 11
Theorem 4, 1 = 𝑝𝑠 + 𝑎𝑡 7 77 11 0
𝑏 = 𝑠 𝑝𝑏 + 𝑡𝑏 𝑎 11 0
Since 𝑝|𝑠𝑝𝑏 and 𝑝|𝑎𝑏 ⇒ 𝑝|𝑡𝑏𝑎, we get 𝑝|𝑏.
Similarly, we can prove it in general for 1 ≤ 𝑖 ≤ 𝑛 iii) 30, 42, 70
using induction. Find GCD(30,42)
𝑞 𝑎 𝑏 𝑟
The Euclidean Algorithm for finding 1 42 30 12
GCD(A,B) is as follows: 2 30 12 6
• If 𝑎 = 0 then 𝐺𝐶𝐷(𝑎, 𝑏) = 𝑏, since the 2 12 6 0
𝐺𝐶𝐷(0, 𝑏) = 𝑏, and we can stop. 6 0
• If 𝐵 = 0 then 𝐺𝐶𝐷(𝑎, 𝑏) = 𝑎, since the GCD(30,42) = 6
𝐺𝐶𝐷(𝑎, 0) = 𝑎, and we can stop. Now find GCD(6,70)
Page 2
Modular Arithmetic
𝑞 𝑎 𝑏 𝑟
% Are m and n greater than zero?
11 70 6 4
if m <= 0 || n <= 0
1 6 4 2 res = -3;
2 4 2 0 return
2 0 end
GCD(6,70)=2
% Swap m and n if m less than n
GCD(30,42,70)=2
% to allow the algorithm to function
properly
MATLAB Code if m < n
prompt1 = "Enter the first number: "; tmp = m;
m = input(prompt1); %Get the first number m = n;
prompt2 = "Enter the second number: "; n = tmp;
n = input(prompt2); %Get the first number end
ans=euclid(m,n); %Call the recursive function
euclid % Result of modulus is zero so we have
if ans==-1 found the gcd
fprintf('Enter the numeric if mod(m,n) == 0
values\n') fprintf('GCD(%d,%d)=>',m,n);
elseif ans==-2 res = n;
fprintf('Enter the integral else
values\n') fprintf('GCD(%d,%d)=>',m,n);
elseif ans==-3 res = euclid(n,mod(m,n)); % Euclid's
fprintf('Enter the positive algorithm
values\n') end
else
fprintf('%d\n',ans) end
end
Page 3
Modular Arithmetic
𝑐 𝑐
Let 𝑥0 = 𝑠 𝑑 and 𝑦0 = 𝑡 𝑑 such that 𝑑 = 𝑠𝑎 + 𝑡𝑏, be the
Find GCD of given numbers and express GCD as a particular solution of the Diophantine equation, the
linear combination of the given numbers general solution of the Diophantine equation is given
i) 826,1890 by
𝑎 = 1890, 𝑏 = 826 {coeff of 𝑦}
𝑞 𝑎 𝑏 𝑟 𝑠1 𝑠2 𝑠3 𝑡1 𝑡2 𝑡3 𝑥 = 𝑥0 + 𝑛
𝑑
2 1890 826 238 1 0 1 0 1 -2 {coeff of 𝑥}
𝑦 = 𝑦0 − 𝑛
3 826 238 112 0 1 -3 1 -2 7 𝑑
2 238 112 14 1 -3 7 -2 7 -16 where 𝑛 ∈ 𝑍, 𝑑 = gcd(𝑎, 𝑏).
8 112 14 0 -3 7 -59 7 -16 135
14 0 Determine whether the following LDE’s are
solvable or not:
𝒈𝒄𝒅(𝟏𝟖𝟗𝟎, 𝟖𝟐𝟔) = 𝟏𝟒; 𝒔 = 𝟕, 𝒕 = −𝟏𝟔
i) 12𝑥 + 18𝑦 = 30
⇒ 14 = 7 × 1890 + (−16) × 826
gcd(12,18)=6 and 30 is a multiple of 6. Hence given
ii) 165,418
LDE is solvable.
𝑎 = 418, 𝑏 = 165
ii) 6𝑥 + 8𝑦 = 25
𝑞 𝑎 𝑏 𝑟 𝑠1 𝑠2 𝑠3 𝑡1 𝑡2 𝑡3
gcd(6,8)=2 and 25 is not a multiple of 2. Hence
2 418 165 88 1 0 1 0 1 -2
given LDE is not solvable.
1 165 88 77 0 1 -1 1 -2 3
1 88 77 11 1 -1 2 -2 3 -5
Find the general solution of the following LDE’s:
7 77 11 0 -1 2 -15 3 -5 38
11 0
i) 𝟐𝟖𝒙 + 𝟗𝟏𝒚 = 𝟏𝟏𝟗
𝒈𝒄𝒅(𝟒𝟏𝟖, 𝟏𝟔𝟓) = 𝟏𝟏; 𝒔 = 𝟐, 𝒕 = −𝟓
𝑎 = 91, 𝑏 = 28
⇒ 11 = (2)418 + (−5)165
gcd(91,28)=7, 7|119 ⇒ given LDE has solution
Online Calculator for Extd. Euclidian Alg.
𝑞 𝑎 𝑏 𝑟 𝑠1 𝑠2 𝑠3 𝑡1 𝑡2 𝑡3
https://www.extendedeuclideanalgorithm.com/calculat
3 91 28 7 1 0 1 0 1 -3
or.php?mode=1
4 28 7 0 0 1 -4 1 -3 13
7 0
Linear Diophantine Equation(LDE)
7 = (1)91 + (−3)28
For any 𝑎, 𝑏, 𝑐 ∈ 𝑍, the simplest form of the
The particular solution of 28𝑥 + 91𝑦 = 119 is given
Diophantine equation takes the form 𝑎𝑥 + 𝑏𝑦 = 𝑐.
by
Suppose 𝑎 and 𝑏 are integers, then the Diophantine
𝑐
equation 𝑎𝑥 + 𝑏𝑦 = 𝑐 has a solution iff 𝑐 is a multiple 𝑥0 = 𝑠 = −3 × 17 = −51,
𝑑
of 𝑔𝑐𝑑(𝑎, 𝑏). 𝑐
𝑦0 = 𝑡 = 1 × 17 = 17
𝑑
⇒ 28(−51) + 91(17) = 119
Page 4
Modular Arithmetic
Page 5
Modular Arithmetic
Page 6
Modular Arithmetic
Page 7
Modular Arithmetic
⇒ 𝑎𝑝−1 (1 ⋅ 2 ⋅ 3 … (𝑝 − 1)) 7 = 2)
i.e., 2⇒ 164 ≡ 2(𝑚𝑜𝑑 7)
≡ 1 ⋅ 2 ⋅ 3 … (𝑝 − 1)(𝑚𝑜𝑑 𝑝)
⇒ 𝑎𝑝−1 ≡ 1(𝑚𝑜𝑑 𝑝) By transitivity property 1653 ≡ 2(𝑚𝑜𝑑 7)
So the remainder is 2
Using Fermat’s theorem, find the remainder
Solve the following Linear Congruences using FLT
(i) When 𝟕𝟐𝟎𝟎𝟏 is divided by 5.
1) 𝟏𝟐𝒙 ≡ 𝟔(𝒎𝒐𝒅 𝟕)
Sol: 𝑝 = 5, 𝑝 − 1 = 4
Sol: Since gcd(12,7)=1, 127−1 = 126 ≡ 1(𝑚𝑜𝑑 7)
By FLT, 74 ≡ 1(𝑚𝑜𝑑 5)
⇒ 1 ≡ 126 (𝑚𝑜𝑑 7)
⇒ (74 )500 ≡ 1500 (𝑚𝑜𝑑 5)
⇒ 𝑥 ≡ 126 𝑥(𝑚𝑜𝑑 7)
⇒ 72000 ≡ 7(𝑚𝑜𝑑 5)
⇒ 𝑥 ≡ 125 12𝑥(𝑚𝑜𝑑 7)
⇒ 72000 ≡ 2(𝑚𝑜𝑑 5)
So the remainder is 2. ⇒ 𝑥 ≡ 125 6(𝑚𝑜𝑑 7)
Now take 125 ≡ 55 (𝑚𝑜𝑑 7)
(ii) When 𝟑𝟐𝟒𝟕 is divided by 17.
Sol: 𝑝 = 17, 𝑝 − 1 = 16 ⇒ 55 = (52 )2 5, but 25 ≡ 4(𝑚𝑜𝑑 7)
Page 8
Modular Arithmetic
Page 9
Modular Arithmetic
• Calculate the Cipher text (encrypted message) 𝑐 = Note: Here (𝑛, 𝑗) can be seen by everyone, only who
𝑚𝑗 (𝑚𝑜𝑑 𝑛), where 𝑚 is the original message. has private key 𝑑 can see the message 𝑚. To find the
• 𝑐 can be decrypted using same (𝑛, 𝑗) by using 𝑑 as 𝑑, one has to do the prime factorization of 𝑛, which is
𝑐 𝑑 (𝑚𝑜𝑑 𝑛) = 𝑚 very difficult by the advanced computers.
Example
▪ Let A wants to send a message Modular Arithmetic Encipher the plaintext message ENDSIGHT using
in cryptography RSA with n = 8633 and j = 5
ENDSIGHT={069 078 068 083 073 071 072 084}
▪ The receiver B has to calculate 𝑛, 𝑗 and a private key
𝑑. To calculate 𝑛, 𝑗 695 (𝑚𝑜𝑑 8633) = 8005 similarly calculate the c
o Let us take any two prime numbers value for each number, then Cipher text c will be
c={8005 5646 6873 1302 3404 1415 3342 702}
𝑝1 = 53, 𝑝2 = 49
o 𝑛 = 𝑝1 𝑝2 = 3127
o 𝜙(𝑛) = (𝑝1 − 1)(𝑝2 − 1) = 3016
Page 10
Modular Arithmetic
Page 11