Asymmetric encryption
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version.
Two keys instead of one
- Symmetric encryption has a problem: you must somehow share the secret key first.
- Asymmetric encryption uses a pair of keys: a public key and a private key.
The padlock idea
- Your public key is like an open padlock you hand out to everyone.
- Anyone can lock a message shut with it — but only your private key can open it.
- So people send you secrets safely without ever sharing a secret key. That is the breakthrough.
A tiny RSA
- RSA is real asymmetric encryption. With tiny numbers you can see it work:
n, e, d = 33, 3, 7 # public key (e, n), private key (d, n)
cipher = (7 ** e) % n # lock 7 with the public key
print((cipher ** d) % n) # unlock with the private key -> 7
- Encrypting and decrypting use different keys, yet the message comes back.
Where you use it daily
- It also works in reverse for digital signatures (next lessons).
- Every time you see HTTPS, asymmetric encryption is quietly setting up a secure connection.
Covers: IGCSE 2.3 (asymmetric, public/private keys), A-Level 17.1, AP CSP.
Here is a tiny RSA with public key (e, n) and private key (d, n). Encrypt message with the public key (cipher = message**e % n), then decrypt with the private key (plain = cipher**d % n). Print plain — it should return to the original.
Click Run to see the output here.