By A.Xu ma OS

1. Introduction

Every time you log in to online banking or buy something online, your data is protected by mathematics. One of the most famous systems for doing this is RSA, named after Ron Rivest, Adi Shamir and Leonard Adleman, who published it in 1978.

RSA is a public-key cryptographic system whose security relies on prime numbers and modular arithmetic. Unlike symmetric encryption, RSA uses two keys: a public key, which can be shared openly, and a private key, which must remain secret.

Its central idea is the construction of a trapdoor function: an operation that is easy to perform but computationally infeasible to reverse without additional information, known as the trapdoor.

2. Constructing RSA

RSA starts with two distinct prime numbers, pp and qq, which are multiplied to produce the modulus n=pqn=pq. The prime factors are kept secret, whilst their product nn becomes public.

Then it uses Euler’s totient function, φ(n)\varphi(n), which counts the positive integers up to nn that are co-prime to nn. Since pp and qq are distinct primes,

φ(n)=(p−1)(q−1).\varphi(n)=(p-1)(q-1).

An integer ee is then chosen such that 1<e<φ(n)1<e<\varphi(n) and gcd⁡(e,φ(n))=1\gcd(e,\varphi(n))=1. In practice, e=65537e=65537 is almost always used. To reverse the process, we find an integer dd satisfying

ed≡1(modφ(n)).\boxed{ed\equiv1\pmod{\varphi(n)}}.

Therefore, dd is the multiplicative inverse of ee modulo φ(n)\varphi(n), and can be calculated efficiently using the Extended Euclidean Algorithm.

The public key is (n,e)(n,e), and dd forms an essential part of the private key.

A message is first converted into an integer mm with 0≤m<n0\leq m<n. Encryption and decryption are then defined by

c≡me(modn)andm′≡cd(modn),\boxed{c\equiv m^e\pmod n} \qquad\text{and}\qquad \boxed{m’\equiv c^d\pmod n},

respectively, where mm is the original message and cc is the ciphertext.

2.1 A Worked Example

Take the small primes p=61p=61 and q=53q=53. Then

n=61×53=3233andφ(n)=60×52=3120.n=61\times53=3233 \qquad\text{and}\qquad \varphi(n)=60\times52=3120.

Choosing e=17e=17, which is co-prime to 3120, the Extended Euclidean Algorithm gives d=2753d=2753, since

17×2753=46801=15×3120+1.17\times2753=46801=15\times3120+1.

To encrypt the message m=65m=65, we calculate c≡6517≡2790(mod3233)c\equiv65^{17}\equiv2790\pmod{3233}. To decrypt, we calculate 27902753≡65(mod3233)2790^{2753}\equiv65\pmod{3233}, and the original message is recovered. Real RSA works in exactly the same way, but with primes hundreds of digits long.

3. Why Does RSA Work?

The correctness of RSA follows from Euler’s theorem, which states that

gcd⁡(a,n)=1⟹aφ(n)≡1(modn).\gcd(a,n)=1 \quad\Longrightarrow\quad a^{\varphi(n)}\equiv1\pmod n.

Since ed≡1(modφ(n))ed\equiv1\pmod{\varphi(n)}, we can write ed=1+kφ(n)ed=1+k\varphi(n) for some integer kk.

Substituting the encryption equation into the decryption equation gives

m′≡(me)d≡med≡m1+kφ(n)≡m(mφ(n))k(modn).\begin{aligned} m’&\equiv(m^e)^d\equiv m^{ed}\\ &\equiv m^{1+k\varphi(n)}\\ &\equiv m\left(m^{\varphi(n)}\right)^k \pmod n. \end{aligned}

By Euler’s theorem, m′≡m(modn)m’\equiv m\pmod n. Since both mm and m′m’ lie between 00 and n−1n-1, this means m′=mm’=m, and the original message is recovered.

There is, however, a subtlety: Euler’s theorem requires gcd⁡(m,n)=1\gcd(m,n)=1. RSA must also work when the message shares a factor with nn.

This can be established using the Chinese Remainder Theorem. Since n=pqn=pq, it is sufficient to prove that

med≡m(modp)andmed≡m(modq).m^{ed}\equiv m\pmod p \qquad\text{and}\qquad m^{ed}\equiv m\pmod q.

Consider the congruence modulo pp. If p|mp\mid m, the result is immediate. Otherwise, Fermat’s Little Theorem gives mp−1≡1(modp)m^{p-1}\equiv1\pmod p. Since ed−1=kφ(n)=k(p−1)(q−1)ed-1=k\varphi(n)=k(p-1)(q-1), p−1p-1 divides ed−1ed-1, and it follows that

med=m(mp−1)r≡m(modp)m^{ed}=m(m^{p-1})^r \equiv m\pmod p

for some integer rr. The same argument applies modulo qq. The Chinese Remainder Theorem therefore gives

med≡m(modn)\boxed{m^{ed}\equiv m\pmod n}

for every message mm.

4. Euler’s Function and Carmichael’s Function

Although Euler’s totient function is sufficient for constructing RSA keys, φ(n)\varphi(n) is not the smallest exponent that guarantees the required result.

A more precise function is Carmichael’s function, λ(n)\lambda(n), defined as the smallest positive integer such that aλ(n)≡1(modn)a^{\lambda(n)}\equiv1\pmod n for every aa co-prime to nn.

For an RSA modulus consisting of two distinct primes, λ(n)=lcm⁡(p−1,q−1)\lambda(n)=\operatorname{lcm}(p-1,q-1). Using the identity lcm⁡(a,b)=abgcd⁡(a,b)\operatorname{lcm}(a,b)=\frac{ab}{\gcd(a,b)}, we obtain

λ(n)=(p−1)(q−1)gcd⁡(p−1,q−1).\boxed{ \lambda(n)= \frac{(p-1)(q-1)} {\gcd(p-1,q-1)} }.

Therefore, λ(n)|φ(n)\lambda(n)\mid\varphi(n).

The distinction is important: φ(n)\varphi(n) counts the integers relatively prime to nn, whereas λ(n)\lambda(n) describes the smallest universal exponent for which Euler’s theorem holds.

Instead of requiring ed≡1(modφ(n))ed\equiv1\pmod{\varphi(n)}, RSA can therefore use the weaker condition

ed≡1(modλ(n)).\boxed{ed\equiv1\pmod{\lambda(n)}}.

This is sufficient for correct decryption because Carmichael’s function guarantees that mλ(n)≡1(modn)m^{\lambda(n)}\equiv1\pmod n whenever gcd⁡(m,n)=1\gcd(m,n)=1. When mm shares a factor with nn, the argument from Section 3 still works modulo pp and modulo qq, since p−1p-1 and q−1q-1 both divide λ(n)\lambda(n).

In modern implementations, Carmichael’s function is preferred because it gives the smallest valid private exponent dd, and modern standards for generating RSA keys specify it. In our example, λ(3233)=lcm⁡(60,52)=780\lambda(3233)=\operatorname{lcm}(60,52)=780, which gives d=413d=413 instead of 27532753, since 17×413=7021=9×780+117\times413=7021=9\times780+1.

5. The Trapdoor

The security of RSA comes from the difference between performing an operation and reversing it.

Calculating c≡me(modn)c\equiv m^e\pmod n is computationally trivial, even for very large values of nn. However, reversing it without the private key is believed to be infeasible. The trapdoor is knowing the primes pp and qq: with them, anyone can calculate φ(n)\varphi(n) and then dd, but nobody knows an efficient way to find dd from nn and ee alone. In fact, knowing φ(n)\varphi(n) is enough to factorise nn, so finding dd this way is as hard as factorising.

RSA therefore exploits the difficulty of factorising sufficiently large integers into primes. In practice, these primes are usually 1024 bits long, a decimal order of magnitude around 1030810^{308}, so the modulus nn is a 2048-bit number of around 1061710^{617}. The largest RSA challenge number factorised so far has only 896 bits, a record set in September 2026, and factorising a 2048-bit modulus with known methods is far beyond the reach of any existing computer. However, a large enough quantum computer could factorise such numbers efficiently using Shor’s algorithm, which is why new “post-quantum” cryptographic systems are being developed.

The version of RSA described here, known as “textbook RSA”, always encrypts the same message to the same ciphertext, which makes it insecure on its own. Real implementations therefore always use padding schemes such as RSA-OAEP, which add randomness to the message before it is encrypted. For highly classified data, the bit length can also be increased, for example to 4096 bits.

6. Conclusion

RSA demonstrates a fascinating paradox: mathematical operations can be easy to perform but extraordinarily difficult to reverse. By turning number theory into the foundation of digital privacy, it shows that maths is not just about finding solutions, but also about exploiting the limits of computation.

References

“Carmichael Function.” Wolfram MathWorld. https://mathworld.wolfram.com/CarmichaelFunction.html.

Rivest, Ronald L., Adi Shamir, and Leonard Adleman. “A Method for Obtaining Digital Signatures and Public-Key Cryptosystems.” Communications of the ACM, vol. 21, no. 2, 1978, pp. 120–126. https://doi.org/10.1145/359340.359342.

“RSA.” Stanford University Applied Cryptography Group. https://crypto.stanford.edu/pbc/notes/crypto/rsa.html.

“RSA Factoring Challenge.” Wikipedia, Wikimedia Foundation. https://en.wikipedia.org/wiki/RSA_Factoring_Challenge.

“Totient Function.” Wolfram MathWorld. https://mathworld.wolfram.com/TotientFunction.html.


Leave a Reply

Trending