 So one of the things we need to be able to do in order to set up a good cryptographic system is to find a good prime number. And so this leads to the problem of primes. We need to find a good method of determining whether a number is prime. Unfortunately, the only certain way to guarantee that a number is prime is to determine whether it's divisible by any of the integers less than itself. On the other hand, we can determine rather easily whether a number is composite using the Euler Fermat theorem. So again, to restate that, if I have two numbers, A and P, that are relatively prime, if P is a prime number and A is some value smaller than P, then A to the power of P minus 1 is going to be congruent to 1 mod P. And so this sounds great because it seems to be a good way of distinguishing primes between non-primes. However, the important thing here is that the theorem does not allow us to conclude that P is prime. P is prime is the antecedent. It's what we're starting with. What we can conclude is A to the power of P minus 1 is congruent to 1 mod P. On the other hand, if we take a look at the contrapositive of the theorem, it will tell us how we can determine whether a number is composite. If A to the P minus 1 is not congruent to 1 mod P, then A is not prime. A is a composite number. Well, let's take a look at an example. So let's take the number n equals 493, and let's see if we can determine whether this number is prime. And again, what I could do is I can try trial division by everything less than 493, but let's evaluate the Euler for a mod theorem. And I'll evaluate A to the power of 493 minus 1 mod 493. Now I need to find a value of A that's relatively prime to the modulus. And what I could do is I could pick a number and then check using the Euclidean algorithm to see that it's relatively prime. But let's take the easy way out. I know this is an odd number, so A equals 2 will definitely be co-prime with 493. So I'll evaluate 2 to the 493 minus 1. So I'll use the fast-powering algorithm, find the powers of 2 mod 493, and select the ones that I need, multiply them together. And again, 2 to the power of 492 is congruent to 373. And because it's not congruent to 1, then 493, whatever it is, is not prime. Now I know it's composite, but I don't actually know what the factors of 493 are at this point. Well, how about 341? Well, again, I'll evaluate 2 to the power of 341 minus 1 mod 341. I'll use the fast-powering algorithm, and I'll select things that work. And I find 2 to the power of 340 is congruent to 1. However, remember, that tells us nothing about whether 341 is prime. The Euler-Fermat theorem tells us that if a number is prime, this congruence is going to hold. It doesn't tell us what happens if the congruence holds. In fact, 341 is a composite number. It's 11 times 31. Well, this suggests the following approach that we might be able to use. So I know that if it's not prime, then something to power 340 is not going to be congruent to 1. So what if I try a different base? Well, for example, if I try a equals 3, I find that 341 and 3 are relatively prime. So I'll evaluate 3 to the power of 341 minus 1. Again, same procedure. And I find that it's congruent to 256. And so what does this tell me? Well, this tells me that because 3 to the power of 340 is not congruent to 1, then 341 is not a prime number. So what this suggests is I might try the Euler-Fermat theorem for a couple of different bases, and if any of them give us something not congruent to 1, then we know that the number we're working with is going to be a composite number, and we don't have to worry about it anymore.