Almost every smart card, website and software update today relies on one of two families of public-key algorithms. What are they, and why do they work?
Two families
Public-key cryptography needs a mathematical problem that's easy in one direction and very hard to reverse, as lesson 1.4 explained. Two such problems dominate today:
- RSA, published in 1977, relies on how hard it is to factor a very large number back into the two primes that were multiplied to make it.
- Elliptic-curve cryptography (ECC), proposed in 1985 and widely used since the 2000s, relies on how hard it is to reverse "multiplication" of a point on an elliptic curve, known as the elliptic-curve discrete logarithm problem.
Both can be used for signatures, and both underpin key establishment: RSA through encryption of a key, ECC through key agreement such as ECDH.
How RSA works, with small numbers
An RSA key pair starts with two secret prime numbers. Here's the classic textbook example, with primes far too small to be secure:
- Pick two primes: p = 61 and q = 53. Multiply them: n = 3233. The number n is part of the public key.
- Pick a public exponent e = 17. The public key is the pair (n, e) = (3233, 17).
- Knowing p and q lets the key generator compute a valid private exponent, here d = 2753, chosen so that raising to e and then to d returns the original number. This example uses (p − 1)(q − 1); RSA can also use the least common multiple of p − 1 and q − 1. For an ordinary two-prime RSA key, recovering a valid d from the public key is computationally equivalent to factoring n.
Now, for a whole number m from 0 to n − 1, anyone can turn m into c = me mod n with the public key, and only the holder of d can turn it back with m = cd mod n. For m = 65, the public key gives c = 2790, and the private key turns 2790 back into 65.
With numbers this small, anyone can factor 3233 in a moment. Real RSA keys use an n of 2048 bits or more, more than 600 decimal digits, which no known method on today's computers can factor in any practical time.
Try it: toy RSA
Using the textbook key above (n = 3233, e = 17, d = 2753), pick a number and see the public key and private key undo each other. These numbers are tiny on purpose, and real RSA also adds padding, so this is for understanding only. Real RSA-PSS verification doesn't recover the message: it checks the supplied message against the signature and returns valid or invalid.
- Encrypt with the public key: m17 mod 3233
- 2790
- Decrypt with the private key: c2753 mod 3233
- 65
- Textbook RSA signature arithmetic (private key): m2753 mod 3233
- 588
- Textbook check (public key): s17 mod 3233, which should give m back
- 65
How ECC works, in pictures
One common form of elliptic curve is the set of points that satisfy y2 = x3 + ax + b, with the parameters a and b chosen so the curve is nonsingular: it has no sharp points or self-crossings. There's a way to "add" two points on the curve to get a third, by drawing a line through them, finding where it crosses the curve again and reflecting that point. Adding k copies of a point together is called scalar multiplication.
In ECC, the private key is a large random number k, and the public key is the point kG: the sum of k copies of a fixed starting point G. Going forward from k to kG is fast. Going back, from kG to k, is the hard problem. Real curves, such as P-256, work with whole numbers modulo a large prime rather than a smooth line, but the idea is the same.
RSA and ECC side by side
| Security strength | RSA modulus length | ECC subgroup-order length |
|---|---|---|
| About 112 bits | 2048 bits | 224 bits |
| About 128 bits | 3072 bits | 256 bits (for example P-256) |
| About 192 bits | 7680 bits | 384 bits |
These lengths aren't the sizes of encoded keys: an uncompressed P-256 public key, like the ones in lesson 1.4's demo, occupies 65 bytes. Still, for similar strength, ECC keys and signatures are much smaller, and key generation and signing are usually faster. Performance depends on the operation and the hardware, though: RSA verification with a small public exponent can be faster than ECDSA verification. ECC's small sizes make it attractive for smart cards, where memory, power and time at the door are limited. RSA remains widespread, and many cards and systems support both.
Both families share one weakness: a large enough quantum computer, running Shor's algorithm, could solve both the factoring problem and the elliptic-curve problem. No such machine exists today, but it's why new, quantum-resistant algorithms have been standardised. Module 6 covers that transition.
Go deeperOptional technical detail for readers who want more
Where d comes from
In the example, (p − 1)(q − 1) = 60 × 52 = 3120, and d is a number that satisfies e × d = 1 mod 3120: here 17 × 2753 = 46801 = 15 × 3120 + 1. RSA can also use the least common multiple of p − 1 and q − 1 (here 780), which can give a smaller valid d; both work. The key generator can do this because it knows p and q. For an ordinary two-prime key, finding a valid d from the public key alone is computationally equivalent to factoring n. A separate question, whether decrypting one particular ciphertext without d is as hard as factoring, has not been proved, although no general method faster than factoring is known.
Why real RSA needs padding
"Textbook" RSA, as in the demo, is deterministic and has algebraic weaknesses: the same message always gives the same ciphertext, and signatures can be combined. Real systems use padding schemes: OAEP for encryption and PSS for signatures, or the older PKCS #1 v1.5 forms that remain widely deployed.
Choosing curves
Not every elliptic curve is safe, so systems use standard, well-studied curves. NIST SP 800-186 specifies the curves NIST recommends, including P-256 and P-384, as well as Edwards curves used with EdDSA.
Strength figures
The table follows NIST SP 800-57 Part 1 Rev. 5. For applying new cryptographic protection, such as creating a new signature or encrypting new data, that guidance treats 112 bits of security as acceptable through 2030 and calls for at least 128 bits after that. Processing data that was protected earlier, such as verifying an older signature, falls under separate legacy-use guidance.
Sources
Draft lesson, awaiting technical review · Last updated 19 November 2026