ALICEEVE1p, q = 61, 532n = p * q3e = 174phi = (p - 1) * (q - 1)5d = pow(e, -1, phi)6m = 657c = pow(m, e, n)8back = pow(c, d, n)BOBPUBLICBOB'S KEYn (public)?e (public)?d (private)?MESSAGEm (Alice)?c (sent)?back (Bob)?27902790AES key
Back row: Alice, Bob, the open network and Eve listening on itFront row: the Python code and the numbers it computesTokens: a shared key, the public key, the ciphertext, a locked AES keyAt the back, Alice and Bob talk over an open network while Eve copies everything that crosses it. Bob's key pair is toy RSA: the public key (n = 3233, e = 17) locks, the private key (d = 2753) unlocks. Alice locks 65 into 2790; Eve copies 2790 but cannot undo it; Bob's private key turns it back into 65. This is "textbook RSA": the bare maths with no padding. Real RSA encryption adds random OAEP padding (RFC 8017, NIST SP 800-56B), so the same message gives a different ciphertext each time.

The key-sharing problem

  1. Symmetric encryption needs both sides to share one secret key first. If Alice just sends that key across the network, an eavesdropper, Eve, can copy it on the way. Then Eve can read everything they encrypt.

A toy RSA key pair

Locking and unlocking

Using it safely

What happens

;; step 1/12 · problem
symmetric key   one key both locks and unlocks
problem         Alice and Bob must share it first
sent in clear   Eve copies it on the network
result          every message is readable by Eve

The numbers are deliberately tiny (n = 3233) so you can check them by hand or in Python. Real RSA keys are at least 2048 bits long and are made by a vetted library, never by hand. This is "textbook RSA": the bare maths with no padding. Real RSA encryption adds random OAEP padding (RFC 8017, NIST SP 800-56B), so the same message gives a different ciphertext each time.