 Suppose we have some number m, exponent e, and modulus n. In general, we can find m to power e mod n easily. However, solving the congruence x to power e congruent to c mod n is considered very difficult, and this allows us to use it as a basis of a cryptographic system as long as the authorized user can solve the congruence. Well, let's think about how we might solve such a congruence. So let's try to solve 2 to power x congruent to 1 mod 11. Now, if you compare notes carefully, you'll see that this is not quite the problem we started out to solve, but it turns out it's related. And we'll tie all the pieces together later. Now, since 2 to the n mod 11 can only have one of 11 values, we'll find the first 11 powers of 2 mod n. So we'll find the 2 to the first, 2 to the second, 2 to the third, and so on. And the first couple of powers don't exceed n, so they're just the actual values. 2 to the fourth is 16 as the actual number, and we can reduce that to 5 mod n. 2 to the fifth, well, that's 2 to the fourth times 2, and we know that 2 to the fourth is congruent to 5, and so 2 to the fifth is congruent to 10. 2 to the sixth, well, that's 2 to the fifth times 2, and remember working mod n means you can always work with numbers that are smaller than n. And we know that 2 to the 5 is congruent to 10, so we'll use that. We find 2 to the seventh, 2 to the eighth, 2 to the ninth, and finally 2 to the tenth, which allows us to solve this congruence. Now in the 17th century, the French mathematician Pierre de Fermat noticed a relationship we would now state as follows. If p is prime and not a factor of a, then a to the power p minus 1 is congruent to 1 mod p. Moreover, the least positive x for which a to the power x is congruent to 1 mod p is a divisor of p minus 1. And this allows us to solve some congruences very easily. For example, let's find the least positive solution, 7 to the power x, congruent to 1 mod 43. Now, Fermat's theorem does require us to work with primes, and we're in luck. Since 43 is prime, we know that 7 to the power 42, unless, is congruent to 1 mod 43. Now, I would verify that this is true for two reasons. One, don't believe everything you see on the internet, but the other is that this is good practice using the fast-powering algorithm, and we're going to need to use it a lot of times. Now, Fermat's theorem also claims that if there is a smaller solution, it will be a divisor of 42. And so it must be 1 of, and we'll try them out. It can't be 1 because 7 to the power 1 is just going to be 7, but we'll try 7 to the second and find, 7 to the third, 7 to the sixth, and so we know the least positive solution is x equal to 6. Or we could find the least positive solution to 2 to the power x, congruent to 1 mod 83. And again, we know that 83 is prime, so we're guaranteed that 2 to the power 82 is congruent to 1 mod 83. And we know the smallest solution must be a divisor of 82. So the only possibilities are 1, 2, or 41. So 2 to the first is not going to be congruent to 1. 2 to the second, again, not congruent to 1. 2 to the 41st, not congruent to 1. And again, our only solutions are things that divide 82. If it's not 1, if it's not 2, if it's not 41, we know that 82 works, and so x equals 82 is the smallest positive solution. And this is actually very important for us. If p is a prime number and x equal to p minus 1 is the least positive solution to a to the power x, congruent to 1 mod p, we say that a is a primitive root mod n. And the reason we say that it's a primitive root is because the powers of a mod p will be all numbers between 1 and p minus 1. And for a variety of reasons, it turns out to be very useful to find primitive roots. So let's find a primitive value mod 47. And so we want a number whose least power, congruent to 1, is going to be 46. So we'll try out different values of a and find the least x for which a to the power x is congruent to 1 mod 47. So again, if a to the power x is congruent to 1 mod 47, then x must be a divisor of 47 minus 1, 46. So x has to be 1 of... And if we want to have a primitive root, we just have to make sure that the least power is not 1, 2, or 23. So let's try a equal to 2, and we need to find the second and the 23rd power. So we'll use our fast-powering algorithm. Our second power is not equal to 1, and our 23rd power is. Since the first number we tried didn't work, we need to try a different number. For example, we might try 3, and again, we'll apply our fast-powering algorithm. 3 to the second isn't. But 3 to the 23rd is congruent to 1. So we tried 2, 3, we could try 4. But since 4 is equal to 2 squared, we'd have 4 to the 23rd. Well, that's really 2 squared to the 23rd, or switch around our exponents, 2 to the 23rd squared. But we already know 2 to the 23rd is congruent to 1, and so we know that 4 to the 23rd will also be congruent to 1. So we won't bother with 4. And so we can try 5 and find. And here we know that 5 to the 2nd is not 1, 5 to the 23rd is not 1, and that means that 5 to the 46th must be the least positive solution to 5 to the power x congruent to 1 mod 47. And so 5 is primitive.