https://samnot.es/rsa/mod-arithmetic-truths/

Part of my series explaining the RSA Algorithm Modular arithmetic is an important area of Number Theory. Here we’ll cover 4 important but slightly contrived laws of modular arithmetic, useful to understand when tackling other mathematical ideas which use modular arithmetic proofs, as we see in our exploration of Carmichael’s Function. Notes: The | symbol means “divides without remainder”. So x|y is another way of writing y % x = 0.

Sam

# rsa / Modular Arithmetic: 4 Important Truths - Number Theory

Part of my series explaining the RSA Algorithm

Modular arithmetic is an important area of Number Theory. Here we’ll cover 4 important but slightly contrived laws of modular arithmetic, useful to understand when tackling other mathematical ideas which use modular arithmetic proofs, as we see in our exploration of Carmichael’s Function.

Notes:

  • The | symbol means “divides without remainder”. So x|y is another way of writing y % x = 0.

  • The greatest common divisor or GCD(x, y) is the largest number into which all provided integers divide without remainder.

  • Two numbers which are coprime share no common divisors larger than 1. They are prime with respect to one another.

Rule 1

  • IF GCD(a, b) = 1, i.e. a & b are coprime

  • AND a|bc (remember this means bc % a = 0 )

  • THEN a|c

Proof

Remember Bézout’s Identity, which we covered while discussing the Euclidean Algorithm? It states that for any 2 coprimes , a & b there must be values x & y that satisfy:

ax + by = 1

Therefore:

> multiply by `c`
acx + bcy = c

> acx divides by a
a|acx

> and because we stated that
a|bc

> so bcy must divide by a
a|bcy

> therefore divide both sides of the statement by `a`
acx/a + bcy/a = c/a
  • Because a|acx, we know that acx/a is an integer.

  • Because a|bcy we know that bcy/a is an integer.

So their sum, c/a, must also be an integer. Otherwise put, a|c. This is a logical extension of Euclid’s Lemma.

Rule 2

  • IF GCD(a, n) = 1 (ie. coprimes)

  • AND ax ≡ ay (mod n)

  • THEN x ≡ y (mod n)

Proof

> IF
ax ≡ ay (mod n)

> THEN
(ax — ay) % n = 0

> Factor out `a`
a(x-y) % n = 0

> Put differently
n|a(x-y)

> Remember that `a` & `n` are coprime
> So applying Rule 1 from above
n|(x-y)

> Meaning that
x ≡ y (mod n)

This rule is known as the rule of cancellation in modular arithmetic.

Rule 3

  • IF a & n are coprime

  • THEN there is a positive integer k such that aᵏ≡ 1 (mod n)

Proof

There are a finite number of coprimes of n, less than n. Let’s assign this value to the letter t. So there are t coprimes of n which are less than n.

Given the list of numbers:

a¹, a², ..., aᵗ, aᵗ⁺¹ (each mod n)

We know a few things about the list.

  • There only t + 1 numbers in the list.

  • They are all coprime to n, because a is coprime to n, and no new factors have been introduced.

  • They are all smaller than n, because each is mod n.

If there are only t coprimes to n less than n, and we have t + 1 coprimes less than n in this list, then we know at least two of the numbers in this list will clash – they will result in the same value. The list is not unique.

So we know there are two integers h & j, h < j, such that:

aʰ ≡ aʲ (mod n)

If k = j - h then:

> substitute out j
aʰ ≡ aʰ⁺ᵏ (mod n)

> separating exponents
aʰ ≡ aʰaᵏ (mod n)

We know already know that aʰ is a coprime of n. We can apply Rule #2 from above.

aʰ ≡ aʰaᵏ (mod n)

> cancel aʰ
1 ≡ aᵏ (mod n)

…proving that there must be some positive integer, k for any coprime of n, a such that aᵏ % n = 0.

Rule 4

  • IF aᵏ ≡ 1 (mod n)

  • AND r is a multiple of k

  • aʳ≡ 1 (mod n)

Proof

Because r is a multiple of k there is some integer s where r/k = s.

aʳ = aᵏˢ = (aᵏ)ˢ

> We know that
aᵏ ≡ 1 (mod n)

> So
aʳ ≡ (aᵏ)ˢ ≡ (1)ˢ ≡ 1 (mod n)

In Summary

We’ve just shown the following:

  1. If a & b are coprime, AND a|bc, THEN a|c

  2. If a & b are coprime, AND ax ≡ ay (mod n), THEN x ≡ y (mod n)

  3. If a & b are coprime, THEN there is a positive integer, k such that aᵏ≡ 1 (mod n)

  4. If aᵏ ≡ 1 (mod n) AND r is a multiple of k THEN aʳ≡ 1 (mod n)

The first rule is not specific to modular arithmetic, although its use in proving the other rules makes it helpful to derive. These truths arise frequently when tackling proofs in number theory. They are a strong foundation for approaching any modular arithmetic problem.

You can see them applied to such a problem when we take a look at Carmichael’s Function.

ARCHIVE

26 Apr 2026 London Marathon: One Year On 15 Apr 2026 A Little Humanity 13 Apr 2026 Hamlet - William Shakespeare 13 Apr 2026 The Rise and Fall of the Third Reich - William L. Shirer 13 Apr 2026 The Secret History - Donna Tartt 11 Apr 2026 A Year of Living Simply - Kate Humble 08 Apr 2026 40 Before 40 08 Apr 2026 Montaigne - Stefan Zweig 04 Apr 2026 William Shakespeare: A Very Short Introduction - Stanley Wells 19 Mar 2026 Unreasonable Hospitality - Will Guidara 15 Mar 2026 Hitler's Secret - Rory Clements 15 Mar 2026 Nemesis - Rory Clements 08 Mar 2026 HRV & Me: Taming a messy stressy mind 02 Mar 2026 Nucleus - Rory Clements 19 Feb 2026 Corpus - Rory Clements 08 Feb 2026 Resonance 16 Jan 2026 A Night to Remember: Sinking of the Titanic - Walter Lord 01 Jan 2026 Everything I've read in 2026 (so far) 15 Dec 2025 Someone from the Past (British Library Crime Classics) - Margot Bennett 01 Dec 2025 Death in Ambush (British Library Crime Classics) - Susan Gilruth 23 Nov 2025 A Cold Wind From Moscow - Rory Clements 10 Nov 2025 The Boleyn Traitor - Philippa Gregory 24 Oct 2025 Death Makes a Prophet (British Library Crime Classics) - John Bude 13 Oct 2025 The Cheltenham Square Murder (British Library Crime Classics) - John Bude 04 Oct 2025 Sussex Downs Murders (British Library Crime Classics) - John Bude 22 Sep 2025 The Lake District Murder (British Library Crime Classics) - John Bude 15 Sep 2025 The Mayor of Casterbridge - Thomas Hardy 10 Sep 2025 The Murder of Roger Ackroyd - Agatha Christie 30 Aug 2025 Marble Hall Murders - Anthony Horowitz 25 Jul 2025 Where Angels Fear to Tread -- EM Forster 10 Jul 2025 Steve Jobs -- Walter Isaacson 10 Jul 2025 The Fifth Risk -- Michael Lewis 10 Jul 2025 The Ride of a Lifetime -- Bob Iger 03 Jul 2025 James -- Percival Everett 01 Jul 2025 Great Expectations -- Charles Dickens 23 Jun 2025 Hillbilly Elegy -- JD Vance 10 Jun 2025 Principles 09 Jun 2025 Revenge of the Tipping Point -- Malcolm Gladwell 06 Jun 2025 The Grand Babylon Hotel -- Arnold Bennett 04 Jun 2025 The Seven Husbands of Evelyn Hugo -- Taylor Jenkins Reid 03 Jun 2025 Rebecca -- Daphne du Maurier 29 May 2025 A Promised Land - Barack Obama 29 May 2025 Less - Andrew Sean Greer 13 May 2025 Careless People - Sarah Wynn-Williams 07 May 2025 Looking Glass War - John Le Carre 04 May 2025 A Murder of Quality - John Le Carre 01 May 2025 London Marathon 2025: Training Retrospective 29 Apr 2025 The Human Factor - Graham Greene 28 Apr 2025 London Marathon 2025: Race Review 27 Apr 2025 Photos: London Marathon 2025 27 Apr 2025 Spectating the London Marathon 2025 [Sunday 27th April] 26 Apr 2025 London Marathon 2025: Week 16 23 Apr 2025 Call for the Dead - John Le Carre 21 Apr 2025 London Marathon 2025: Week 15 16 Apr 2025 The Manchurian Candidate - Richard Condon 13 Apr 2025 London Marathon 2025: Week 14 05 Apr 2025 London Marathon 2025: Week 13 30 Mar 2025 London Marathon 2025: Week 12 26 Mar 2025 Effortless - Greg Mckeown 23 Mar 2025 London Marathon 2025: Week 11 16 Mar 2025 London Marathon 2025: Week 10 09 Mar 2025 London Marathon 2025: Week 9 02 Mar 2025 London Marathon 2025: Week 8 22 Feb 2025 London Marathon 2025: Week 7 16 Feb 2025 London Marathon 2025: Week 6 16 Feb 2025 Problems & [Meta] Problem Solving 14 Feb 2025 Little Dribbling - Bill Bryson 10 Feb 2025 Bring Up the Bodies - Hilary Mantel 09 Feb 2025 London Marathon 2025: Week 5 09 Feb 2025 Three Zero 03 Feb 2025 The iPad mini has genuinely changed my life [no hyperbole] 02 Feb 2025 London Marathon 2025: Week 4 28 Jan 2025 Coming AI: Valuing Humans in a world where they have no economic value 28 Jan 2025 Value & Price 27 Jan 2025 The Vegetarian - Han Kang 27 Jan 2025 Wolf Hall - Hilary Mantel 26 Jan 2025 London Marathon 2025: Week 3 19 Jan 2025 Deriving my own proof for Unitary matrices 19 Jan 2025 London Marathon 2025: Week 2 17 Jan 2025 David Copperfield - Charles Dickens 12 Jan 2025 London Marathon 2025: Week 1 09 Jan 2025 NYC & DC '24 08 Jan 2025 Linear Algebra Playground 07 Jan 2025 Configuring an IKEA wireless light switch: Saving you the pain 07 Jan 2025 Goals & Goal-setting 06 Jan 2025 Digital Feeds 05 Jan 2025 London Marathon 2025: Training Begins 01 Jan 2025 Everything I've read in 2025