 In the next couple of videos, we'll go through the entire process of setting up a RSA encryption system from soup to nuts. So remember that the setup of an RSA system goes something like this. First, Alice chooses two or more primes whose product gives her public modulus n. Alice also chooses a public exponent e, which is relatively prime to phi of n. Alice then determines the private exponent d, which satisfies e d is equivalent to one mod phi of n. Now once this system is set up, Bob chooses message m to send to Alice. Bob evaluates the ciphertext c, which is going to be congruent to m to power e mod n, and communicates this. Finally, Alice evaluates m equivalent to c to power d mod n, and recovers Bob's message. So the classic description of RSA relies on two primes. And while we could use a RSA system involving three or more primes, we'll go classic and choose two primes. How about p equals 83 and q equals 263. Now choosing the primes for an RSA system is something of an art. There are good primes to choose and bad primes to choose. And in this case we chose these two primes, 83 and 263, and we'll see why these are good choices. Our first step is to multiply these two to get the public modulus. Now we also need phi of n. Since 83 and 263 are distinct primes, we can use a theorem that says if two numbers are relatively prime, then phi of the product is the product of the phi values. So we know that phi of 83 times 2 is 63 is phi of 83 times phi of 263. Of course we need to find phi of 83 and phi of 263, and since 83 and 263 are in fact prime, then we have a theorem that says if p is prime, then phi of p is just p minus 1. And so phi of 83 is going to be 82, and phi of 263 is going to be 262, and their product will be, which gives us phi of n. Now to choose that encryption exponent, it's important to remember that in order for e to have an inverse, we require that the greatest common divisor of e and phi of n, 21, 484, has to be equal to 1. So here it's useful to remember that we found 21, 484 by multiplying 82 by 262, and both 82 and 262 have a factor of 2, and both 41 and 131 are prime. So as long as we don't pick 2, 41, 131, or any multiple, we'll have an inverse. One practical constraint here to remember is that if our power of m is not greater than or equal to our modulus, we're not really working mod n. Since the smallest number we're going to be sending is 2, and 2 to power 15 is 32768, which is going to be the first power that's greater than n, we'll choose our encryption exponent to be greater than or equal to 15. And since we like the number 37, we'll choose e equal to 37. So now we want to find the decryption exponent, so we need to solve ed congruent to 1 mod phi of n. Remember we chose e to be 37. We found phi of n to be 21, 484, and so the congruence we're trying to solve is 37d congruent to 1 mod 24, 484. So we'll try to solve this congruence through our diafontine method. So this congruence requires 37d minus 1 to be a multiple of 2144. Rearranging things, then solving for d gives us... Now in order for d to be an integer, we require 24k plus 1 over 37 must also be an integer. So we have that as our next equation. Rearranging things, then solving for k gives us... which is our next equation. Again, we want 13x minus 1 over 24 to be a whole number, so we'll make that our next variable. Solving gives us our next equation. Again, we want 11y plus 1 over 13 to be a whole number, so we'll call that z and solve for y, giving us another equation. We want 2z minus 1 over 11 to be a whole number, so we'll let that be w, then we'll solve for z. Finally, we want w plus 1 over 2 to be a whole number, so we'll let that be t and solve for w, and that gives us a system of equations that we can work back to find our decryption exponent. So we'll start with the last equation. We'll pick a value of t. How about t equals 1? And that tells us that w is going to be 1. Since we know w equals 1, we can find z, which will have to be 6. Now that we know z, we can find y. Now that we know y, we can find x. Now that we know x, we can find k. And now that we know k, we can find d. And so now we're ready to announce our public key cryptosystem. Alice announces the public modulus, n equals 21829, and the public encryption key, e equals 37. What she keeps secret, she tells no one. Is that 21829 is the product 83 times 263, and that the decryption exponent is 11613. Next, we'll see how Alice can use this to decrypt a message sent to her from Bob.