Discrete MathematicsModular Arithmetic and Cryptography3 of 6
Modular Arithmetic and Cryptography · 3
Modular Inverses and Linear Congruences
To solve an equation like 3x≡2(mod7) for x, we need a way to undo multiplying by 3 on a clock where fractions do not exist.
1
What Is a Modular Inverse?
We want to isolate x in the linear congruence 3x≡2(mod7) using only whole numbers on a 7-hour clock.
What Is a Modular Inverse?
On a 7-hour clock, there is no fraction 31, so instead we look for the whole number that multiplies with 3 to land on 1:
3⋅modular inverse 3−15≡1(mod7)
The −1 exponent in 3−1 means the whole number that turns 3 into 1 modulo 7, not the fraction 31.
Text solution
Find the modular inverse of 3 modulo 7Testing multiples of 3 on a 7-hour clock shows that 3×5=15 is 1 hour past two full laps of 7:
3⋅5=15≡1(mod7)⟹3−1≡5(mod7)
Multiply both sides of 3x≡2(mod7) by 5 and reduce modulo 7Multiplying by 5 turns 3x into 15x≡1x and leaves the solution on the right:
5⋅(3x)15xx≡5⋅2(mod7)≡10(mod7)≡3(mod7)
2
When Modular Inverses Exist
On a 7-hour clock, 3 had an inverse, but on other clocks some multipliers get stuck in a loop and never reach 1. We want to know which numbers a have a modular inverse on an m-hour clock.
When Modular Inverses Exist
When gcd(a,m)>1, steps of size a on an m-hour clock only land on multiples of gcd(a,m) and skip right over 1. When gcd(a,m)=1, Bézout's Identity guarantees integers x and y that combine a and m to make 1, and reducing that equation modulo m drops the full laps my to leave the inverse x:
ax+≡0(modm)my=1⟹aa−1x≡1(modm)
a has an inverse modulo m⟺gcd(a,m)=1
On a 10-hour clock, step sizes a that share a factor with 10(2,4,5,6,8) stay trapped in multiples of that factor and never reach 1, while step sizes with gcd(a,10)=1(1,3,7,9) visit every hour and land on 1 at their modular inverse.
On a 10-hour clock, repeated jumps reach hour 1 only when the step size shares no factor larger than 1 with 10.
3
Finding an Inverse with Bézout's Identity
When the clock is large, testing multiples by hand takes too long, so we use the Euclidean algorithm and Bézout's Identity to find the modular inverse of 17 modulo 43, that is, to solve 17x≡1(mod43).
Finding an Inverse with Bézout's Identity
17−1≡?(mod43)
Text solution
Run the Euclidean algorithm down to 1 and solve each row for its remainderDividing 43 by 17 and continuing with the remainders reaches gcd(17,43)=1 in three steps:
Reduce modulo 43 and convert the inverse to a positive clock numberCrossing out the two full laps 2(43)≡0(mod43) leaves −5 as the inverse of 17, and adding 43 gives the positive hour on the clock:
Now we want to solve any linear congruence ax≡b(modm) for x. Whether a has an inverse, and how many solutions exist on the m-hour clock, depends on g=gcd(a,m), which splits every problem into three cases.
Solving Linear Congruences: The Three Cases
axx≡b(modm)=?
Text solution
Case 1: gcd(a,m)=1: Solve 17x≡3(mod43)
Multiply both sides by 17−1≡−5(mod43) and add a lap of 43Because gcd(17,43)=1, there is one unique solution on the 43-hour clock, and multiplying by −5 is much faster by hand than multiplying by 38 before shifting to a positive hour:
Check whether gcd(4,10) divides the target 3Steps of 4 on a 10-hour clock only land on multiples of gcd(4,10)=2, so they can never hit the odd target 3:
gcd(4,10)=2∤3⟹no solution
Case 3: gcd(a,m)=g>1 and g∣b: Solve 4x≡6(mod10)
Divide the step size, target, and clock size by gcd(4,10)=2Because 4x=6+10k is divisible by 2 in every term, scaling the whole equation down by 2 gives a congruence on a 5-hour clock where the new step size and clock size share no factors:
24x2x≡26(mod210)≡3(mod5)
Multiply both sides by 2−1≡3(mod5) to solve on the 5-hour clockSince 2×3=6≡1(mod5), multiplying by 3 isolates x modulo 5:
3⋅(2x)x≡3⋅3(mod5)≡9≡4(mod5)
Add steps of 210=5 to list both solutions on the 10-hour clockBecause 4×5=20 is already two full laps of 10, the pattern of 4x repeats every 5 hours and hits 6 twice on the 10-hour clock:
x=4andx=4+5=9(mod10)
In 4x≡b(mod10), the path of 4x wraps twice around the even hours of the 10-hour clock, so odd targets b are never hit while every even target b is hit by two inputs x spaced 5 hours apart.
Taking steps of four around a ten-hour clock loops twice through the even hours, hitting every even hour at two inputs five hours apart and missing every odd hour.
5
Cancelling Common Factors in a Congruence
Scaling the clock down when we divide by a shared factor also tells us when we are allowed to cross out a common multiplier c from both sides of c⋅a≡c⋅b(modm).
Cancelling Common Factors in a Congruence
c⋅a⟹?a≡c⋅b(modm)≡b(modm)
When gcd(c,m)=1, cancelling c is really multiplying both sides by c−1(modm), so the clock size stays at m:
3⋅2⟹2≡3⋅12(mod10)≡12(mod10)(gcd(3,10)=1)
When gcd(c,m)=g>1,c has no inverse modulo m; dividing both sides by c also divides the shared factor g out of the clock size:
Here is how modular inverses, linear congruences, and cancellation all come down to checking the greatest common factor with the clock size.
Summary
a−1:a⋅x≡1(modm)
Key concepts
Every question about dividing or cancelling on an m-hour clock starts by checking g=gcd(a,m):
When g=1 (no shared factors with the clock)
The modular inverse a−1 exists and is the unique hour x satisfying ax≡1(modm). On a small clock, do not run the Euclidean algorithm; just test a few multiples to spot the pair that lands 1 past a multiple of m, like 3⋅5=15≡1(mod7) giving 3−1≡5(mod7). On a large clock, run the Euclidean algorithm and back-substitute to write Bézout's Identity ax+my=1, then drop my≡0(modm) so the coefficient of a is a−1(2(43)−5(17)=1⟹17−1≡−5≡38(mod43)). Multiplying both sides of ax≡b(modm) by a−1 gives its single solution modulo m, and cancelling a from a⋅u≡a⋅v(modm) leaves the modulus m unchanged.
When g>1 (shares a factor with the clock)
Do not look for a−1(modm), because multiples of a only land on multiples of g and never reach 1. To solve ax≡b(modm), check whether g divides the target b:
If g∤b, stop immediately: there are 0 solutions (4x≡3(mod10) has no solutions because gcd(4,10)=2∤3).
If g∣b, divide the step size, the target, and the clock size by g to get gax≡gb(modgm), solve for the single answer on the smaller clock (modgm), and add steps of gm to get all g solutions on the original clock (4x≡6(mod10)→2x≡3(mod5)→x≡4(mod5)→x=4,9(mod10)).
Likewise, cancelling c from c⋅a≡c⋅b(modm) divides the modulus by g=gcd(c,m) to give a≡b(modgm)(2⋅3≡2⋅8(mod10)⟹3≡8(mod5)).
7
Practice
1
Which numbers in {0,1,2,…,13} have a modular inverse modulo 14? Find the modular inverse of each one.
Check which numbers in {0,1,…,13} avoid the prime factors of 14, then pair them up so their product is 1 more than a multiple of 14.
A number a has an inverse modulo 14 if and only if gcd(a,14)=1. Since 14=2×7, we rule out all even numbers and 7. (Watch out for the slip of keeping 7 just because it is odd: gcd(7,14)=7=1, so 7 has no inverse modulo 14.) This leaves 1,3,5,9,11, and 13.
To find each inverse, we look for the multiplier that gives ax≡1(mod14) (be careful not to take 14−a, such as pairing 3 with 11 and 5 with 9, which gives a+x≡0(mod14) instead of ax≡1(mod14)):
1×1=1≡1(mod14), so 1−1≡1.
3×5=15=1(14)+1≡1(mod14), so 3−1≡5 and 5−1≡3.
9×11=99=7(14)+1≡1(mod14), so 9−1≡11 and 11−1≡9.
13×13=169=12(14)+1≡1(mod14), so 13−1≡13.
The numbers with inverses modulo 14 are 1,3,5,9,11,13, with 1−1≡1,3−1≡5,5−1≡3,9−1≡11,11−1≡9, and 13−1≡13.
2
Use the Euclidean algorithm and Bézout's Identity to find the modular inverse of 19 modulo 51, and use it to solve 19x≡5(mod51) for x in {0,1,…,50}.
Do not drop the minus sign on −8(19) and take 19−1≡8, which would give x≡8⋅5=40(mod51).Converting −8 to a positive clock number gives 19−1≡−8≡43(mod51).
Run the Euclidean algorithm on 51 and 19 down to a remainder of 1, back-substitute to write 1 as a combination of 51 and 19, and reduce modulo 51.
Running the Euclidean algorithm on 51 and 19 gives:
Reducing modulo 51 drops 3(51)≡0(mod51) and leaves 1≡−8⋅19(mod51). (Do not drop the minus sign on −8(19) and take 19−1≡8, which would give x≡8⋅5=40(mod51).) Converting −8 to a positive clock number gives 19−1≡−8≡43(mod51).
Multiplying 19x≡5(mod51) by −8 gives:
x≡(−8)⋅5=−40≡−40+51=11(mod51)
So 19−1≡43(mod51) and x=11.
3
Does the linear congruence 15x≡22(mod35) have any solutions? Explain how you can tell without testing values of x.
Find gcd(15,35) to see which hours a step size of 15 can visit on a 35-hour clock, then check whether the target 22 is one of them.
Check the greatest common factor of the step size 15 and the clock size 35:gcd(15,35)=5. (Be careful not to check gcd(15,22)=1 between the step size and the target, which would falsely suggest a solution exists.) Because gcd(15,35)=5, steps of size 15 on a 35-hour clock only ever land on multiples of 5. Since 22 is not divisible by 5, there are 0 solutions.
4
Find all solutions to 9x≡12(mod21) on a 21-hour clock (x in {0,1,…,20}).
Divide the step size, target, and clock size by gcd(9,21) first; after solving on the smaller clock, how many hours apart are the solutions on the 21-hour clock?
Since gcd(9,21)=3 and 3 divides 12, there are 3 solutions modulo 21. Dividing the step size, target, and clock size by 3 gives:
3x≡4(mod7)
(Watch out for the slip of dividing 9 and 12 by 3 while leaving the modulus at 21, which gives the unsolvable congruence 3x≡4(mod21).)
On a 7-hour clock, 3×5=15≡1(mod7), so 3−1≡5(mod7). Multiplying both sides by 5 gives:
x≡5⋅4=20≡6(mod7)
To get all three solutions on the 21-hour clock from x≡6(mod7), we add steps of 321=7 (do not stop at the single answer x=6, and do not add steps of gcd(9,21)=3, which would give 6,9,12):
x=6,6+7=13,13+7=20
5
Suppose a and b are integers. (a) If 7a≡7b(mod18), what congruence between a and b follows? (b) If 12a≡12b(mod18), what congruence between a and b follows? Give an example of two integers a and b that satisfy 12a≡12b(mod18) with a≡b(mod18).
Check gcd(c,18) for the multiplier c being cancelled in each part to see whether the modulus 18 stays the same or gets divided by gcd(c,18), then pick two numbers in part (b) that differ by the new modulus.
(a) Since gcd(7,18)=1, cancelling 7 keeps the modulus unchanged: a≡b(mod18).
(b) Since gcd(12,18)=6, cancelling 12 divides the modulus 18 by 6 (do not leave the modulus as 18, and notice that we divide 18 by gcd(12,18)=6, not by 12):
a≡b(mod618)⟹a≡b(mod3)
Picking two integers that are 3 apart, such as a=1 and b=4, gives 12(1)=12 and 12(4)=48≡12(mod18), so 12a≡12b(mod18) with 1≡4(mod18).
6
Prove that if gcd(a,m)=1, then the modular inverse of a modulo m is unique on an m-hour clock: if ax≡1(modm) and ay≡1(modm), explain why x≡y(modm).
Set the two left-hand sides congruent to each other modulo m, then use what gcd(a,m)=1 tells you about cancelling a.
Suppose ax≡1(modm) and ay≡1(modm). Then both ax and ay land on 1 on the m-hour clock, so:
ax≡ay(modm)
(Be careful not to write ax=ay as ordinary integers: ax and ay only agree modulo m, and cancelling a without changing the modulus requires using gcd(a,m)=1.) Because gcd(a,m)=1, cancelling the common factor a from both sides keeps the clock size m unchanged (equivalently, multiplying both sides by an inverse of a modulo m turns a into 1), which gives x≡y(modm). Therefore, the inverse of a is unique modulo m.