The idea in plain English: Imagine you have an open lock box that anyone can close and lock — but only you can open. You leave the open box in a public square. Anyone who wants to send you a message drops it in, closes the lid, and the lock snaps shut. Now nobody, not even the sender, can open it — except you with your secret key. RSA is math that makes this possible: a public key everyone knows (the open box), and a private key only you have (the special key). The magic ingredient? Multiplying two huge prime numbers is easy, but trying to figure out which two primes were multiplied is astronomically hard.
Why this really exists: Before RSA (1977), sending a secret message meant both parties had to agree on a secret key in advance — like meeting in a dark alley to swap codebooks. RSA eliminated that. It made secure communication with strangers possible for the first time. Every time you visit an HTTPS website, use SSH to log into a server, or verify a PGP email signature, RSA (or its elliptic-curve successor) is working behind the scenes. It's the engine of modern internet security.
Let's walk through a complete RSA key generation and message exchange using tiny primes so we can do the math by hand. Real RSA uses primes hundreds of digits long — but the procedure is exactly the same.
Given a ciphertext integer c, the private key exponent d, and the modulus n from the puzzle:
1. Compute m = cd mod n using fast modular exponentiation
2. Convert the resulting integer m back to text (usually ASCII bytes, sometimes hex)
3. If the conversion produces garbage, check the byte order (big-endian vs little-endian)
4. Some puzzles give you p and q directly — compute d yourself with d = pow(e, -1, (p-1)*(q-1))
💡 Use pow(base, exp, mod) in Python,
not base ** exp % mod. The latter tries to compute the full exponent
before taking the modulus, which will use astronomical memory for large exponents.
RSA security relies entirely on the size of n. Here's how the factoring difficulty grows with key size. Modern standards require at least 2048 bits.
| n size (bits) | n size (decimal digits) | Security Level | Factoring Time (classical) | Status |
|---|---|---|---|---|
| 512 | ~155 | very weak | hours on a single machine | broken |
| 1024 | ~309 | weak | ~2 years on academic clusters | deprecated |
| 2048 | ~617 | strong | ~300 billion years (today's tech) | secure |
| 4096 | ~1,233 | very strong | far beyond universe's age | secure |
Note: Shor's algorithm on a sufficiently large quantum computer would break RSA instantly at any key size. That's why post-quantum cryptography (like lattice-based schemes) is being standardized right now.
What's shown above is "textbook RSA" — the pure math. Real RSA in the wild adds padding (OAEP or PKCS#1 v1.5) to prevent attacks:
💡 Puzzle RSA is almost always textbook RSA (no padding) so you can solve it with raw modular exponentiation. Don't use textbook RSA for real security!
apt-get install, the package signature is verified with RSA.