Applied and computational mathematics
Cryptography
Using number theory and algebra to secure information, from RSA to modern encryption schemes.
IntuitionLocking a Message So Only the Right Person Can Open It
Imagine a padlock that anyone can snap shut, but that only one specific key can open. If everyone publishes their own padlock (but keeps their key secret), then anyone can lock a message for you, yet only you can read it back — no meeting in advance, no secret handshake needed. This is the core idea of public-key cryptography: the "locking" operation is easy to compute in one direction and, without the secret key, computationally infeasible to undo, even though the padlock design itself is public.
SchoolModular Arithmetic: The Building Block
Definition: Congruence and modular exponentiation
Two integers and are congruent modulo , written , when : their difference is an exact multiple of . Modular exponentiation is repeatedly multiplying a base by itself modulo , which is exactly the operation cryptographic schemes like RSA and Diffie-Hellman are built on, because it is fast to compute forward but hard to invert.
Here means divides exactly, so is really a statement about remainders: and leave the same remainder when divided by . Euler's theorem below extends Fermat's little theorem and is the engine behind why RSA decryption recovers the original message.
| Scheme | Hard problem it relies on | Typical key size (2026) |
|---|---|---|
| RSA | Factoring into primes | 2048-4096 bits |
| Diffie-Hellman | Discrete logarithm modulo a prime | 2048-3072 bits |
| Elliptic-curve cryptography (ECC) | Discrete logarithm on an elliptic curve group | 256-384 bits |
UndergraduateWhy RSA Works, and How Diffie-Hellman Creates a Shared Secret
Let be a product of two distinct primes, and let and satisfy . Then for every message with , encrypting with and decrypting with recovers the original message: .
Why is it true?
This is the theorem that makes RSA actually usable: it guarantees that whatever the sender encrypts with the public exponent, the holder of the private exponent can always decrypt, for every possible message, not just most of them — the proof has to handle the edge case where a message accidentally shares a factor with the modulus.
Proof
Since , by definition of modular congruence there is a non-negative integer with .
Case 1: . Euler's theorem gives , so raising both sides to the power and multiplying by gives .
Case 2: . Since , this means divides or divides (not both, since is smaller than ). Working modulo : if divides then both and are congruent to modulo ; otherwise and Fermat's little theorem gives , and since divides the same computation as Case 1 shows . The identical argument modulo shows .
By the Chinese Remainder Theorem, a congruence that holds modulo and modulo separately also holds modulo their product , so holds for every message , not just those coprime to .
Fix a prime and a base . If Alice picks a secret and sends , and Bob picks a secret and sends , then computing and both yield the same value , even though neither nor was ever transmitted.
Why is it true?
This is what lets two parties agree on a secret key over a public channel that an eavesdropper is watching: the eavesdropper sees the base, the modulus, and both public values, but recovering the shared secret from these requires solving a discrete logarithm, believed to be computationally hard for well-chosen parameters.
Proof
By definition and are the results of modular exponentiation, so Bob receives and computes , while Alice receives and computes .
Modular exponentiation obeys the same law of exponents as ordinary exponentiation, because repeated multiplication modulo composes exactly like repeated multiplication of integers, only reduced modulo at each step: as exponents of , and this equality survives reduction modulo at every stage.
Therefore : Alice and Bob independently compute the same quantity from their own secret exponent and the other party's public value, without either secret or ever appearing on the channel.
The security argument is separate from this correctness argument: correctness only shows both parties land on the same number; hardness of computing from , , and (the discrete logarithm problem) is what keeps that shared number secret from an observer.
UndergraduateReal-World Applications and Worked Examples
Every HTTPS connection, secure messaging app, and cryptocurrency wallet relies on the theorems above: TLS handshakes use Diffie-Hellman (or its elliptic-curve variant) to agree on a session key, banking systems and software updates use RSA or ECDSA signatures to guarantee authenticity, and blockchain wallets use elliptic-curve discrete logarithms to make a private key computationally infeasible to derive from a public address. The two worked examples below carry out RSA and Diffie-Hellman by hand on small numbers so every step is checkable.
Example: RSA by hand with small primes
Using primes and , with public exponent and message , find the ciphertext and verify that decryption recovers the message.
Solution
Step 1: Compute the modulus and .
Step 2: Check , so is a valid public exponent.
Step 3: Find the private exponent with . Testing gives , so works.
Step 4: Encrypt : the ciphertext is .
Step 5: Decrypt by computing . Using repeated squaring modulo 55: , , , . Since , multiply , which reduces step by step to .
Step 6: The decrypted value is , exactly the original message, confirming the RSA correctness theorem on this concrete instance.
Example: Diffie-Hellman key exchange by hand
With prime and base , Alice picks secret and Bob picks secret . Compute the shared secret both ways and verify they match.
Solution
Step 1: Alice computes . Stepping through powers of 5 mod 23: , , , , . So .
Step 2: Bob computes . Using from above, , and . So .
Step 3: Alice computes the shared secret as . Since , , and , so this equals .
Step 4: Bob computes the shared secret as . Writing gives ; since (a direct check: ), and , this reduces to .
Step 5: Both computations give , confirming Alice and Bob agree on the same shared secret without ever transmitting or over the channel.
In RSA with , , and public exponent , which value of satisfies ?
What underlying computational problem does the security of Diffie-Hellman key exchange rest on?
If , Euler's theorem states that where counts which of the following?
A bank wants to sign software updates so customers can verify they truly came from the bank and were not tampered with. Which cryptographic tool directly provides this guarantee?
References
- Alfred J. Menezes, Paul C. van Oorschot, Scott A. Vanstone (1996). Handbook of Applied Cryptography
- Peter W. Shor (1994). Algorithms for Quantum Computation: Discrete Logarithms and Factoring · arXiv:quant-ph/9508027
- National Institute of Standards and Technology (2024). Module-Lattice-Based Key-Encapsulation Mechanism Standard (FIPS 203)