p & q prime n = pq ed = 1 mod (p-1)(q-1) c = m**e mod n # encode m = c**d mod n # decode public key = (e,n) private key = (d,n) The "mod n" insures that the message m and code c are always less than a given number of bits, namely the number of bits in n. Since we need to store numbers m*m before dividing by n to get the remainder, to do this we need to be able to do arithmetic on integers of that size. The main calculation we need to perform is a**b mod c where a,b,c are all pretty large numbers. But it turns out there's a trick to do this without ever really needing to know a**b or storing that number of bits. The trick is called "binary square and multiply", and works by representing b in binary. Then what we have will have this form: a**( 1*16 + 0*8 + 1*4 + 1*2 + 0*1) mod c for b= 10111 base 2. The trick is to bit-shift b to the right, setting "a" to its square each time, and then adding that into a runnning total if the right-most bit of b is 1. We take mod c at each step. The most storage we ever need is (a**2 mod c) which amounts to 2*(bits to store c) To do this in a realistic secure way, p and q need to have hundreds of decimal digits. And then the size of each message block is also hundreds of characters. We just need to be able to do mod arithmetic on numbers like 10**1000 ...