The Daily Reckoning
How Can One Exponent Lock a Message and Another Unlock It?
Euler’s theorem explains the arithmetic hinge inside RSA: choose two exponents whose product is one full modular cycle plus one step.
Arithmetic Behind Secure Messages · Part 3 of 3
- Difficulty
- Intermediate
- Area
- Numbers and algebra
- Reading time
- 10 minutes
- Prerequisites
- Modular arithmetic and congruence · Prime numbers · Fermat’s little theorem · Greatest common divisors
Can you publish a rule that anyone may use to scramble a message, yet keep a different rule that reverses the scrambling?
The Rivest–Shamir–Adleman cryptosystem, usually called RSA, answers yes with two exponents. A public exponent sends a message around a modular clock. A private exponent completes enough additional laps to return the message to its starting point. The lock and the key are both powers.
This lesson finishes the three-part Arithmetic Behind Secure Messages series. Part one introduced modular clocks. Part two used Fermat’s little theorem to guarantee a loop when the modulus is prime. RSA needs a composite modulus, so one more counting function enters the story.
Count the numbers that can multiply backward
Two positive integers are coprime when their greatest common divisor is . For example, and are coprime even though neither number is prime. The only positive integer dividing both is .
Euler’s totient function counts the positive integers below a chosen modulus that are coprime to it. The notation is
Here is a positive integer, ranges over the integers from through , is the greatest common divisor of and , and the symbol means “the number of members in the set.”
For , the eligible integers are
so .
When and are two different primes, the product has a useful count:
To see why, inspect the integers from through . There are integers in total. Exactly of them are multiples of , and exactly are multiples of . The number appeared in both rejected groups, so add it back once after subtracting twice:
Every integer left by that count is coprime to .
Euler extends the prime loop
Euler’s theorem states:
Let be a positive integer, and let be an integer with . Then
The theorem says that raising a number coprime to to the power completes a modular loop.
A modern proof extends the rearrangement used in part two. List every nonzero remainder that is coprime to . Multiplication by cannot create a collision among those remainders, and each product remains coprime to . Multiplication by therefore rearranges the entries.
Let be the product of every entry in the original list. Multiplying each entry by inserts factors of , while rearrangement leaves the product congruent to . Thus
Every factor of is coprime to , so has a multiplicative inverse modulo . Multiply both sides by that inverse to cancel and obtain .
Fermat’s little theorem is the prime case. If is prime, every integer from through is coprime to , so .
Build a lock from two small primes
Real RSA keys use enormous integers and carefully specified encoding rules. The following numbers are deliberately tiny so every operation can be inspected.
Choose two primes:
Their product is the modulus
and the totient count is
Choose the public exponent . Next, choose a private exponent so that leaves remainder after division by . The value works because
The public key is the pair . The private exponent is .
Represent a message by an integer from through . Encryption produces a ciphertext by
Decryption raises that ciphertext to the private exponent:
If is coprime to , Euler’s theorem gives . Therefore
The extra “plus one” in is the whole trick. Eighty powers make two complete loops; the final power restores the original message.
The diagram below runs this toy system. Move the message slider and watch both exponentiations. The fact cards identify whether Euler’s theorem supplies the shortest proof for the selected message.
Toy RSA workbench
One public turn, one private return
Public (e, n) = (3, 55) · Private d = 27
12³ ≡ 23 (mod 55), then 23²⁷ ≡ 12 (mod 55).
- Greatest common divisor
- gcd(12, 55) = 1
- Shortest proof available
- Euler’s theorem
- Round trip
- 12 → 23 → 12
Worked example: lock and recover 12
Take . Because , Euler’s theorem applies.
Encrypt by cubing modulo :
The ciphertext is .
Now decrypt by computing modulo . Repeated squaring keeps the numbers small:
Write . Then
Decryption recovers .
What if the message shares a factor with 55?
Euler’s theorem requires , but the toy RSA round trip also succeeds for , , and the other non-coprime messages. Prove the claim separately modulo and modulo . If a prime divides , then both and are modulo that prime. If the prime does not divide , Fermat’s little theorem reduces the exponent. The two prime-by-prime conclusions combine to give . This last combination is an instance of the Chinese remainder theorem.
Try the arithmetic hinge
Problem 1
Let and . Find and .
Reveal the solution
The modulus is
Because and are different primes,
Therefore and .
Problem 2
For the modulus from Problem 1, suppose the public exponent is . Find a positive integer such that .
Reveal the solution
We need to be one more than a multiple of . Try multiples of until adding produces a multiple of :
Thus
One valid private exponent is .
From an academy theorem to public and secret cryptography
Leonhard Euler developed the composite-modulus theorem over many years. The Euler Archive dates Theoremata arithmetica nova methodo demonstrata to 1758 and its publication in the St Petersburg Academy’s journal to 1763. The archive record also notes presentations to the Berlin Academy in 1758 and the St Petersburg Academy in 1759. Euler’s route from Fermat’s prime theorem to a count of integers coprime to a composite modulus supplied the mathematical cycle used here.
Two centuries later, electronic communication created a different problem: how could people exchange encrypted messages without first transporting a shared secret key? Ronald Rivest, Adi Shamir, and Leonard Adleman answered with the system now named from their initials. Their 1978 paper explicitly targets electronic mail and electronic funds transfer, defines encryption and decryption as modular powers, and proves the round trip for a modulus made from two primes. The paper also records support from the U.S. National Science Foundation and Office of Naval Research. A theorem that grew inside eighteenth-century European academies became infrastructure research shaped by twentieth-century computer networks, commerce, and military funding.
The public history has a classified parallel. James Ellis and Clifford Cocks developed comparable public-key ideas at Britain’s Government Communications Headquarters; Cocks produced an RSA-like construction in 1973. The intelligence agency kept the work secret, and it did not shape the open development of RSA. GCHQ disclosed the earlier work in 1997. Steven Levy’s detailed history of the episode shows how classification delayed both recognition and public use. The same mathematical possibility emerged in two institutions, but secrecy determined which discovery could circulate, be tested, and become a standard.
What the toy lock leaves out
Encryption and signatures. The current Internet Engineering Task Force specification, RFC 8017, defines RSA primitives for encryption, decryption, signing, and verification. It also defines encoding schemes such as Optimal Asymmetric Encryption Padding (OAEP) and Probabilistic Signature Scheme (PSS). Raw textbook RSA—the deterministic calculation in this lesson—is not a safe encryption protocol.
The trapdoor. Multiplying the secret primes and is easy. Recovering them from a suitably large public modulus is believed to be hard for conventional computers. Anyone who knows the factorization can compute and derive the private exponent. Euler’s theorem explains why decryption works; the presumed difficulty of factorization helps explain why the private exponent can remain private.
Future pressure. A sufficiently capable quantum computer would threaten RSA and other current public-key systems. This is not a claim that such a machine exists today. The U.S. National Institute of Standards and Technology finalized its first post-quantum standards in August 2024 and urged organizations to begin migrating. The arithmetic in RSA remains beautiful even as security engineering prepares to rely on different hard problems.
One idea to remember
Choose exponents and so that is a whole number of Euler cycles plus . The cycles disappear modulo ; the extra returns the message.
Revisit the modular clock or the prime rearrangement behind Fermat’s little theorem. A natural next step is the Chinese remainder theorem, which explains how separate conclusions modulo two primes combine into one conclusion modulo their product.
Sources
- Leonhard Euler, Theoremata arithmetica nova methodo demonstrata (Demonstration of a New Method in the Theory of Arithmetic), written 1758 and published 1763; catalogued by the Euler Archive at the University of the Pacific.
- Ronald L. Rivest, Adi Shamir, and Leonard Adleman, “A Method for Obtaining Digital Signatures and Public-Key Cryptosystems”, Communications of the ACM, February 1978.
- Steven Levy, “The Open Secret”, Wired, April 1999, on the classified public-key work of James Ellis, Clifford Cocks, and Malcolm Williamson at Government Communications Headquarters.
- Kathleen Moriarty et al., RFC 8017: PKCS #1: RSA Cryptography Specifications Version 2.2, Internet Engineering Task Force, November 2016.
- National Institute of Standards and Technology, “NIST Releases First 3 Finalized Post-Quantum Encryption Standards”, August 13, 2024; updated August 29, 2025.