Public-Key Cryptography
Learning objectives
- Describe the RSA key-generation procedure
- Encrypt and decrypt a small RSA example by hand
- Explain why RSA decryption recovers the plaintext, using Euler’s theorem
- Identify the computational asymmetry that protects the private key
Public-key cryptography is the single most consequential application of elementary number theory in the history of human communication. Before 1976, secret communication required both parties to share a secret key in advance — meaning either a courier or a leaked tape would lose the war. Diffie and Hellman, then Rivest, Shamir, and Adleman, showed that you can publish your public key in a newspaper and still receive secret messages from anyone, without ever exchanging a private secret in advance. Every HTTPS handshake, every signed software update, every encrypted message you send today is built on this trick — and the math underneath is exactly Euler’s theorem from the previous section.
The RSA cryptosystem
RSA, named for Rivest, Shamir, Adleman (1977), turns Euler’s theorem into a working encryption scheme. The recipient generates a key pair:
- Pick two large distinct primes (each typically bits in production).
- Compute the modulus and the totient .
- Pick a public exponent with and . (In practice, .)
- Compute the private exponent via the extended Euclidean algorithm.
The public key is — published openly. The private key is — kept secret.
Encryption and decryption
To encrypt a message with : compute . To decrypt: compute .
Why decryption recovers . Because , write for some integer . Then, when , Euler’s theorem gives:
The remaining case (meaning or ) is handled separately using the Chinese Remainder Theorem and Fermat’s little theorem; the answer is still .
Worked example
Take , so and . Pick (coprime to ). Compute : , so (verify: ). Public key , private key . Encrypt : . Decrypt : . Using repeated squaring inside , this reduces to .
Why RSA is secure
An attacker who sees wants the private . To compute they need . To compute they need the factorisation . Factoring a 2048-bit semiprime is believed to take longer than the age of the universe on any classical computer. Multiplying two primes is fast (polynomial time); factoring their product is, as far as anyone knows, hard. This one-way trapdoor — easy forward, hard backward — is the foundation of every public-key system that descends from RSA.
Pause and think: What would go wrong if Alice published her public key but accidentally also leaked ? Show that an attacker who knows and can recover and (and hence ) by solving a quadratic equation. The leak is total.
Try it
- Set up a toy RSA system with . Compute , , and find a valid pair. Encrypt and verify the ciphertext.
- Predict before computing: with , what is the ciphertext of ? (Hint: ; reduce mod .)
- Explain in your own words why must be coprime to . (Hint: otherwise no inverts mod .)
- Two-step puzzle: an attacker intercepts the same plaintext encrypted with two different public moduli using a small exponent like . Look up the “Hastad broadcast attack” and explain why small plus low padding is dangerous.
A trap to watch for
Textbook RSA — encrypting with no further processing — is dangerous in practice. Reasons: (1) encrypting the same twice produces the same ciphertext, so an attacker can match repeated messages; (2) small messages with small exponents () can be recovered by taking ordinary integer cube roots, no factoring needed; (3) homomorphic structure () lets an attacker manipulate ciphertexts. Production RSA always uses a padding scheme like OAEP that randomises the encoded message before exponentiation. The number-theoretic core in this section is correct — but real deployments wrap it carefully.
What you now know
You can generate an RSA key pair, encrypt and decrypt by hand on small primes, justify correctness via Euler’s theorem, and articulate the factoring-hardness assumption that protects the private exponent. You have now traversed the entire arc from (§7.1) to a working encryption scheme — the journey is short, the destination is the modern internet. Velleman’s Chapter 8 turns to infinite sets and cardinality, where similar number-theoretic intuition will guide your first encounters with versus .
References
- Rivest, R. L., Shamir, A., Adleman, L. (1978). “A Method for Obtaining Digital Signatures and Public-Key Cryptosystems.” Communications of the ACM, 21(2), 120–126.
- Diffie, W., Hellman, M. E. (1976). “New Directions in Cryptography.” IEEE Transactions on Information Theory, 22(6), 644–654.
- Velleman, D. J. (2019). How to Prove It: A Structured Approach (3rd ed.). Cambridge University Press, §7.5.
- Stinson, D. R., Paterson, M. B. (2018). Cryptography: Theory and Practice (4th ed.). CRC Press, ch. 5–6.
- Koblitz, N. (1994). A Course in Number Theory and Cryptography (2nd ed.). Springer, ch. 4.