Advanced Mathematics

Public-Key Cryptography (RSA)

A way to let anyone lock a message that only one person can unlock, built on modular powers and the difficulty of factoring.

Needs a step first: 2

Choose two large primes p,qp, q, publish n=pqn = pq and an exponent ee, and encrypt a message mm as c=me mod nc = m^e \bmod n. Only someone who knows pp and qq can compute φ(n)=(p−1)(q−1)\varphi(n) = (p-1)(q-1) and the private exponent dd with ed≡1(modφ(n))ed \equiv 1 \pmod{\varphi(n)}, and then cd≡m(modn)c^d \equiv m \pmod n by Euler's theorem. Its safety rests on factoring being hard, which is why Shor's algorithm matters.

Where it shows up: Secure web connections and signed software updates have relied on RSA; Shor's algorithm on a large quantum computer would break it, which is why post-quantum cryptography is being adopted.

How to hold it: In your head

Explain why cd≡m(modn)c^d \equiv m \pmod n undoes the encryption and why knowing pp and qq is the whole secret; the modular powers themselves are the computer's job.

What knowing it looks like

  • Generate a toy RSA key from two small primes and find dd with the extended Euclidean algorithm.
  • Encrypt and decrypt a small number by hand, using repeated squaring for the powers.
  • Explain why publishing nn and ee does not reveal dd, and what would break the scheme.

Test yourself

With p=5p = 5, q=11q = 11 and public exponent e=3e = 3, find nn, φ(n)\varphi(n) and the private exponent dd. Then encrypt the message m=7m = 7.
Show the worked answer
n=55n = 55 and φ(n)=4×10=40\varphi(n) = 4 \times 10 = 40. We need 3d≡1(mod40)3d \equiv 1 \pmod{40}: 3×27=81=2×40+13 \times 27 = 81 = 2 \times 40 + 1, so d=27d = 27. Encrypt: c=73=343=6×55+13c = 7^3 = 343 = 6 \times 55 + 13, so c=13c = 13. To check, decrypting gives 1327≡7(mod55)13^{27} \equiv 7 \pmod{55}: modulo 5, 13≡313 \equiv 3 and 327≡33≡2≡73^{27} \equiv 3^3 \equiv 2 \equiv 7; modulo 11, 13≡213 \equiv 2 and 227≡27=128≡72^{27} \equiv 2^7 = 128 \equiv 7.

Needs a step first: 2

Learn it with an AI

Copy this prompt into any AI assistant. It will take you through step by step at your level and finish with the test above.

Be my maths tutor. I'm learning "Public-Key Cryptography (RSA)" (Undergraduate I tier): A way to let anyone lock a message that only one person can unlock, built on modular powers and the difficulty of factoring.
I already know: Modular Arithmetic and Primes.
Teach it Socratically: first ask what I already know; then explain the core idea with one concrete example and why it's true; then give me three problems, one at a time, easy to hard. Wait for my answer, check every step, and point out mistakes without giving the answer away.
Finish by testing me with this: With $p = 5$, $q = 11$ and public exponent $e = 3$, find $n$, $\varphi(n)$ and the private exponent $d$. Then encrypt the message $m = 7$.
Use LaTeX for formulas. When you say where it's used later (machine learning, quantum mechanics), be specific.

On the way to

Recommended