Discrete MathematicsModular Arithmetic and Cryptography1 of 6
Modular Arithmetic and Cryptography · 1
Congruence mod n and Clock Arithmetic
When a calculation only depends on where a repeating cycle lands, like finding the time of day hundreds of hours from now, carrying every full cycle through the arithmetic is wasted work.
1
Wrapping the Number Line Around a Wheel
To find what spot a large number lands on in a repeating cycle, we throw away all the full laps and keep only the leftover steps.
Wrapping the Number Line Around a Wheel
Text solution:
Split off full laps of 12: Divide 250 hours into 20 full laps of 12 hours plus the leftover hours.
250=full laps20×12+leftover10
Advance by the leftover steps: Since 20 full laps bring the hand right back to 10 o'clock, move forward just 10 hours to land on 8 o'clock.
10 o’clock+10 hours⟶8 o’clock
Winding the number line clockwise through positive integers and counter-clockwise through negative integers groups all integers into 5 infinite stacks on the wheel, with −1 landing on spot 4,−2 on spot 3, and −5 on spot 0.
Wrapping the number line around a 5-spot wheel sorts all positive and negative integers into 5 stacks, with each number in a stack one full lap of 5 from the next.
2
Congruence and the Two Ways to Check It
We now need a symbol to say that two numbers sit in the same stack on a wheel of size n, along with a fast way to test whether any two numbers belong to the same stack.
Congruence and the Two Ways to Check It
To write that 7 and 17 land on the same spot on a wheel of size 5, we add a third bar to the equals sign:
7lands on thesame spot as≡17on a wheel of size 5(mod 5)
The (mod 5) at the end does not apply only to 17; it tells us the wheel size for the whole statement.
We can check whether two numbers a and b sit in the same stack on a wheel of size n in two ways:
Remainder View (where they land): Divide both numbers by n and check that they leave the same remainder.
17=3×5+2and7=1×5+2
Jump View (the gap between them): Subtract the two numbers and check that the distance between them is made of exact full laps of n.
a≡b(modn)meansa−b is amultiple of nn∣(a−b)
Text solution:
Subtract to find the gap: To check whether 83≡23(mod5) without dividing each number by 5, find the distance between them.
83−23=60=12×5
Because they are separated by 12 exact laps of 5,83 and 23 land on the same spot on a 5-wheel, so 83≡23(mod5).
3
Swapping Numbers in a Stack
When we add, subtract, or multiply numbers on a wheel of size n, we want to find the final spot without multiplying huge numbers together first.
Swapping Numbers in a Stack
17×23≡?(mod5)
Text solution:
Swap with remainders mod 5: In 17×23(mod5), replace 17 with 2 and 23 with 3 from their stacks before multiplying, then wrap the result around 5.
17×23≡2×3(mod5)=6≡1(mod5)
Swap with a negative step mod 50: In 49×49(mod50), since 49 sits one step behind 0 on a 50-wheel (49−(−1)=50), swap each 49 with −1.
49×49≡(−1)×(−1)(mod50)≡1(mod50)
Swapping either factor for another positive or negative number in its stack changes how many full laps of 5 we throw away, while the product still lands on the exact same spot on the wheel.
Swapping either factor for another positive or negative number on the same spoke changes how many full laps get thrown away, but never where the product lands.
4
Large Powers on the Wheel
Now suppose we want the remainder when a huge power like 3100 is divided by 7, where the number itself is far too large to write out.
Large Powers on the Wheel
Text solution:
Walk small powers of 3 to hit 1 or −1: Multiply by one 3 at a time on a 7-wheel, swapping as soon as a result passes 7 or lands one step behind 0.
313233≡3(mod7)=9≡2(mod7)≡2×3=6≡−1(mod7)
Bundle the exponent by 3s: Rewrite the exponent 100 in groups of 3 using 100=3×33+1, then swap 33 with −1.
3100=(33)33×31≡(−1)33×3(mod7)=−1×3=−3(mod7)
Add one lap for the standard remainder: Add 7 to move from −3 to the standard positive spot in {0,1,2,3,4,5,6}.
−3+7=4
So 3100 leaves a remainder of 4 when divided by 7.
5
Writing Proofs with a=b+kn
Swapping numbers on a wheel makes calculations fast, but to prove why a rule like swapping works for every modulus n, we need a way to turn the three-bar symbol ≡ back into an ordinary equals sign.
Writing Proofs with a = b + kn
aa≡b(modn)=?
From the Jump View, saying a≡b(modn) means a is just b plus some integer number of full laps of n:
⟺a≡b(modn)a=b+k full laps of nfor some integer kkn
Text solution:
Claim: For all integers a,b,c,d and any positive integer n, if a≡b(modn) and c≡d(modn), then ac≡bd(modn).
Rewrite each congruence as an equation with laps of n: Use a different integer letter for each congruence because the two pairs do not have to be the same number of laps apart.
a=b+kn for some integer k,c=d+mn for some integer m
Multiply and factor out n: Expand the product ac and pull n out of every term after bd.
Since bm+dk+kmn is an integer, ac equals bd plus full laps of n, which means ac≡bd(modn).
6
Proof by Cases on a Wheel
Next, suppose we want to prove a divisibility statement for every integer n, or show that an equation has no integer solutions. Instead of plugging in 3k,3k+1, and 3k+2 and multiplying out parentheses with k, we can test the finitely many spots on the wheel directly.
Proof by Cases on a Wheel
Prove that 3∣(n3−n)
for every integer n.
Saying an integer is divisible by 3 is the same as saying it lands on spot 0 on a 3-wheel:
3∣(n3−n)⟺n3−n≡0(mod3)
Text solution:
Prove that n3−n is divisible by 3 for every integer n: Every integer n belongs to one of the 3 stacks on a 3-wheel (0,1, or 2≡−1), so we swap n in each case.
Because squaring any spot on a 4-wheel only ever lands on 0 or 1, no integer square can leave a remainder of 2 or 3 when divided by 4.
7
Why You Cannot Always Cancel in Mod n
Because addition, subtraction, and multiplication all let us work across ≡ just like an ordinary equals sign, it is tempting to divide or cancel a common factor on both sides of a congruence. However, canceling can turn a true congruence into a false statement.
Why You Cannot Always Cancel in Mod n
On a wheel of size 6, multiplying 1 by 2 and multiplying 4 by 2 both land on spot 2, even though 1 and 4 sit on opposite sides of the wheel:
2×11≡2×4(mod6)(both land on spot 2)≡4(mod6)(canceling 2 givesa false statement)
When the step size shares a common factor with the wheel size 6, repeated jumps loop back to 0 early and visit the same spots multiple times, which is why two different multiples land on the exact same spot.
On a 6-spot wheel, any step size that shares a common factor with 6 loops back to 0 early and lands different jumps on the same spot.
Key concepts
On a wheel of size n, two integers are congruent, written a≡b(modn), when they land on the same spot, either because they leave the same remainder when divided by n, or because the gap between them is made of exact full laps of n(a−b=kn for some integer k). When checking whether two numbers like −24 and 11 belong to the same stack mod 7, subtract them (11−(−24)=35=5×7) rather than dividing negative numbers by 7.
Before adding, subtracting, or multiplying mod n, swap each number for a small number in its stack. If a number is already small and positive, no swap is needed; if it sits just below a multiple of n, swap it with a negative step (49≡−1(mod50)). For a huge power like 3100(mod7), walk small powers one step at a time until a power hits 1 or −1(33≡6≡−1(mod7)), then bundle the exponent (3100=(33)33×31).
For proofs, pick your approach based on whether the modulus n is a variable or a fixed number: to prove a general rule starting from a≡b(modn) for any modulus n, rewrite the congruence as an equation a=b+kn and factor n out at the end; to prove a divisibility or remainder claim for all integers around a fixed number like 3 or 4, leave k out completely and check the finitely many spots 0,1,…,n−1 on the wheel. Finally, never cancel a common multiplier across ≡(2×1≡2×4(mod6), yet 1≡4(mod6)).
8
Practice
1
Which of the integers −24,−18,39, and 52 lie on the same spot as 11 on a wheel of size 7 (that is, are congruent to 11(mod7)), and what is that spot's standard label in {0,1,2,3,4,5,6}?
Use the Jump View: subtract each number from 11 and check whether the gap is a multiple of 7.
Check the gap from 11 for each number
11−(−24)11−(−18)39−1152−11=35=5×7(yes)=29(not a multiple of 7)=28=4×7(yes)=41(not a multiple of 7)
(Watch out for the double negative in 11−(−24): dropping a minus sign gives 11−24=−13, which falsely rules out −24. Likewise, if you divide −24 by 7 directly, −24=−3×7−3 is 3 steps behind 0, which is spot 7−3=4, not 3.)
Find the standard spot label
11=1×7+4≡4(mod7)
Thus −24 and 39 lie on the same spot as 11, and that spot's standard label is 4.
2
Find the remainder when 29×27−64 is divided by 30 by swapping each number with a small positive or negative number from its stack mod 30.
Do not stop at −1 or drop the minus sign to answer 1: a remainder when dividing by 30 must be in {0,1,…,29}, and 1 step behind 0 on a 30-wheel is spot 29.
Compare 29 and 27 to 30, and compare 64 to 2×30=60.
Swap each number with a small number from its stack mod 30
29≡−1(mod30),27≡−3(mod30),64=2×30+4≡4(mod30)
Multiply and subtract
29×27−64≡(−1)(−3)−4(mod30)=3−4=−1(mod30)
Convert to a standard remainder in {0,…,29}
−1+30=29
(Do not stop at −1 or drop the minus sign to answer 1: a remainder when dividing by 30 must be in {0,1,…,29}, and 1 step behind 0 on a 30-wheel is spot 29.) The remainder is 29.
3
What is the remainder when 2125 is divided by 9?
Be careful with the odd exponent 41 and with the leftover power: treating (−1)41 as +1 or dropping the negative sign on −4 gives the wrong answer 4.
Walk small powers of 2 on a 9-wheel until a power lands one step behind 9.
Walk powers of 2 mod 9 to hit −1
21≡2,22≡4,23=8≡−1(mod9)
Bundle the exponent 125 into groups of 3Since 125=3×41+2,
2125=(23)41×22≡(−1)41×4(mod9)=−1×4=−4(mod9)
(Be careful with the odd exponent 41 and with the leftover power: treating (−1)41 as +1 or dropping the negative sign on −4 gives the wrong answer 4.)
Add one lap of 9 for the standard remainder
−4+9=5
The remainder is 5.
4
Using the algebraic definition of congruence (a=b+kn for some integer k), prove that for all integers a,b,c,d and any positive integer n, if a≡b(modn) and c≡d(modn), then a+c≡b+d(modn) and a−c≡b−d(modn).
Rewrite each congruence as an equation with its own integer number of laps, then add and subtract the two equations.
Rewrite each congruence as an equationSuppose a≡b(modn) and c≡d(modn). Then
a=b+kn for some integer k,c=d+mn for some integer m
(Do not use the same letter k in both equations: writing c=d+kn assumes c−d has the exact same number of laps as a−b, which makes the subtraction step collapse to (a−c)−(b−d)=0 instead of proving it for all pairs.)
(When substituting n≡−2 into n5−n, put −2 in parentheses for both terms: writing −32−2=−34≡1(mod5) misses the double negative in −(−2).) Because n5−n≡0(mod5) in all 5 cases, n5−n is divisible by 5 for every integer n.
6
Find all spots x in {0,1,2,3,4,5,6,7,8,9} on a wheel of size 10 that satisfy 4x≡4×2(mod10), and explain how your answer disproves the claim that you can always cancel a non-zero multiplier in mod 10.
Test which spots x on the 10-wheel make 4x end in the digit 8 (so 4x≡8(mod10)) rather than canceling the 4.
Check all 10 spots on the 10-wheel for 4x≡8(mod10)
4×2=8≡8(mod10)and4×7=28=2×10+8≡8(mod10)
None of the other spots in {0,1,…,9} give a multiple of 4 ending in 8, so the solutions are x=2 and x=7.(Canceling the 4 on both sides right away gives only x=2 and misses x=7.)
Why this disproves canceling mod 10Because 4 and 10 share a common factor of 2, jumping by 4s on a 10-wheel repeats its loop every 5 steps, making 4×7≡4×2(mod10) true even though canceling 4 gives the false congruence 7≡2(mod10).
7
By checking all possible spots on a wheel of size 4, prove that there are no integers x and y such that x2+y2=1003.
Find all possible spots that a square can land on mod 4, then check all sums of two such spots against the spot where 1003 lands mod 4.
Find all possible squares mod 4Every integer is congruent to 0,1,2, or 3≡−1(mod4), so its square is congruent to:
02≡0,12≡1,22=4≡0,(−1)2≡1(mod4)
Thus x2 and y2 can each only be 0 or 1(mod4).
Check all possible sums x2+y2(mod4)
0+0=0,0+1=1,1+1=2(mod4)
(Be sure to include the mixed case 0+1=1(mod4):x and y do not have to sit in the same stack mod 4.)
Compare with 1003(mod4)
1003=4×250+3≡3(mod4)
Since x2+y2 can only land on 0,1, or 2(mod4) and 1003 lands on 3(mod4), there are no integers x and y such that x2+y2=1003.