Building a public-key and private-key: Select two prime numbers: >>> p = 97 >>> q = 233 Compute n and r: >>> n = p * q >>> n 22601 >>> r = (p-1)*(q-1) >>> r 22272 Find e such that e and r are relatively prime (share no common factors): >>> e = 2 >>> while (r % e == 0): ... e = e + 1 ... >>> e 5 Find d such that (e*d)%r equals 1: >>> d = 1 >>> while (e * d) % r != 1: ... d = d + 1 ... >>> d 8909 Our public-key is (e,n): (5, 22601) Our private-key is (d,n): (8909, 22601) Someone encodes message M for us using our public key: >>> M = 15110 >>> M**e % n 3082 (Message is 15110, they send 3082 to us) We decode the coded message C using our private key: >>> C = 3082 >>> C**d % n 15110 We don't tell anyone our private key so if someone intercepts the transmitted message (3082), they won't know how to decode it without knowing d. To discover d, one would have to determine how to factor n into its two primes. When p and q are hundreds of digits long, this process of factoring n is computationally hard to do which makes this hard to crack.