 Let's look at Euler's totion function and some of the characteristics we saw. So the totion by definition is the count of numbers less than n which are relatively prime with n. So you need an algorithm that if you have some value n that you look at the values from 1 up until n minus 1, check which of those are relatively prime with n and then count those numbers and you get your answer of the totion function. But there are some shortcuts. So as we saw in the example we had the totion of for example 24, you need to manually go through and count the numbers and look at them. If n is 1, the totion of 1 we always get 1, if n is a prime number, some prime number p then using this approach because we have a prime number p, its divisors are 1 and p, so all the numbers less than p, 1 up to p minus 1, will be relatively prime with it. So therefore the totion of any prime number is simply p minus 1. It's easy to calculate. If it's not a prime number, unless it matters some of our other criteria, it's generally hard to calculate. That is not only hard for you to calculate manually, it's hard for a computer to calculate. That is if n is a very large number, again we talk about hundreds of digits long, then it's hard for a computer to calculate what is the totion of n in some reasonable time that it takes forever. There are no known algorithms for calculating it unless we have one of these shortcuts and we'll see that that's used as one of the security features. Another shortcut is if n, the totion of n where n is made from multiplying two prime numbers p and q, then the totion of n is the totion of p multiplied by the totion of q and the totion of p, if p is a prime number, is p minus 1, so that's this part here, and the totion of q, if q is a prime number, is q minus 1. So another shortcut we have is if we know n is made up by multiplying two primes together, then we can quickly calculate the totion of n. So an example, let's just scroll back and see some of our prime numbers. So some of the prime numbers here, let's say we have 191 and 79, let's choose two prime numbers, 191 and 79, I choose two prime numbers, choose n is the multiplication of those numbers and I need my calculator, I have a calculator, what is it, 191 times 79, 15168, thank you, 15089. So in this case the totion of 15089, I challenge you in the exam to calculate it manually, that is look at all the numbers up to 15088 and determine which ones are relatively prime with 15089, it will take you a long time on a piece of paper, a computer can do it because it's not so large, but the shortcut is since we know n is the multiplication of two primes, the multiplication of two primes, in fact the answer is the totion of P multiplied by the totion of Q in this case, which is the totion of 191 multiplied by the totion of 79 and because they have prime numbers, it's 190 times 78, whichever whatever that value is we'll calculate in a moment. So if we do know that n is made up by multiplying two primes, we can calculate easily using this formula. Similarly if we know that n is a prime number, easy to calculate, otherwise hard to calculate and especially for very large numbers, impossible to calculate in a reasonable time, there are no known algorithms that we'll calculate within a reasonable time. So 190 by 78, 190 by 78, 14820, so there are some properties of the totion function that are in fact used in the encryption algorithms. Any questions on how to determine the totion of some number, Euler's totion, we've just got two theorems to present and then we're done. So they are the shortcuts so I call them that we are useful. We're going to present two theorems and again they are used in different ciphers. I'm not going to attempt to prove them or explain how they're derived, we're just going to present them. You see in an exam they are given I think in most cases, so present them and give some examples of how they're used. When we look at our ciphers after the midterm, we'll see where they become important, these theorems. Let's just introduce them. First one, Fermat's theorem and in fact it can be viewed in two different forms, we'll go through both. If we have a prime number P and some integer, some positive integer A that is not divisible by P, then Fermat showed that if we take A and raise it to the power of P 1 and mod by P, the answer is 1. That is we have a prime number 11 for example, P is 11 and some integer A which is not divisible by P, so we have some A being in simple case 4, then 4 to the power of 11 minus 1, 4 to the power of 10, mod 11 will be 1. It's all that tells us. It's not hard to rearrange that or to consider a variation of that which is sometimes useful. If P is prime and A is any positive integer, then it also turns out that A to the power of P equals A in mod P, so that is if P is a prime number. All we'll do is give an example to show, well not to prove it's true, but show one or two cases just to see how it's used. So an example, let's say for example we have in mod 7, so if the question is 5 to the power of 7, mod 7, what is the answer? You can manually calculate this. There are small numbers, you can use a calculator to calculate it. If there were big numbers, your calculator would not handle them. So in the exam if I give you much larger numbers, even if you have a calculator, it would not handle them. In this case, easy. But if you see that it matches or fits the format of Fermat's theorem, then you take advantage of that. So let's look at the Fermat's theorem which says in the second case, if P is a prime number then some integer to the power of that prime number, mod that prime number is simply that integer. A to the power of P, mod P equals A. That's what that tells us. A to the power of P is equivalent to A when we're using mod P as the arithmetic. And that's what we have in our example. We have A equal to 7, A equal to 5, P equal to 7. A is 5 in this case, if we match it to that theorem. P is 7. So we could write it in the format of, what do we get? A to the power of P. And according to Fermat's theorem, if we're using mod P, that should be equivalent to A. And when I write 5 to the power of 7 mod 7, then another way to write it is A to the power of 7. And in here brackets mod 7. So 5 to the power of 7 mod 7 will be, what's the answer? 5. We have 5 to the power of 7 is equivalent to 5 when we're using modular arithmetic mod 7. So we can use Fermat's theorem here if we have some problem that fits the format. So you can use it as a shortcut to find the answer. Of course, in this case you could have used your calculator and found what is 5 to the power of 7. You find it is, I've done it before, 5 to the power of 7 is 78,125. Then you mod by 7 and you get 5. But if it's in the format's theorem, then you immediately know it's 5 is the answer. This becomes useful again when we deal with large numbers. A large number, hundreds of digits long to the power of another large number, very hard to calculate and then do the modulus. Unless it's matching this structure, in which case we can immediately get the answer. So that's just an example of how we can apply Fermat's theorem. It has two formats and it depends upon which one's more convenient to use. They both hold. The last one is Euler's theorem and it makes use of Euler's totient function. For every a and n that are relatively prime, a to the power of the totient of n is equivalent to 1 in mod n. And another way to express that, and I think this is missing, still for positive integers a and n, they still need to be relatively prime. I don't know why I haven't said that. So still relatively prime but it's just another way to write this. a to the power of the totient of n plus 1 equals a in mod n. Again, no attempt to explain or to derive this. We will see it later when we look at RSA and public key cryptography or asymmetric cryptography and how it's used to provide the features of security in ciphers. One example, a couple of examples on that one we got. Let's say 1024 mod 11, a simple case. And you could solve this manually quite easily but we could use Euler's theorem here and note what do we have. 1024 is in fact 2 to the power of 10. So it's also 2 to the power of 10 mod 11. And also note that the totient of 11 equals 10. 11 is a prime number. The totient of that will be 10. So what we have is 2 to the power of the totient of 11 mod 11. And now compare that to Euler's theorem. 2 to the power of the totient of 11 mod 11 should be what? Just a simple example showing that if we can express our question or our problem in the format of either Fermat's theorem or Euler's theorem then we may be able to solve it faster than having to manually calculate the exponential and calculating the modulus. 2 to the power of the totient of 11 mod 11. Fermat's, Euler's theorem says a to the power of the totient of mod n is 1 if a and n are relatively prime. Is 2 relatively prime with 11? Yes it is because their greatest common divisor is 1. Therefore this fits the format of Euler's theorem. Therefore the answer is 1 because we, just as a reminder, Euler's theorem says a to the the totient of n equals 1 when we mod by n. Assuming a and n are relatively prime. You can use this to solve, as we've said, to solve large problems, exponentials and modulus. When we have larger numbers. The other form, one more example, using the second form here, a if we have a to the totient of n plus 1 if we mod by n again assuming a and n are relatively prime we should get a as an answer. Let's try one. 5 to the power of 9 mod 24. Let's calculate it first in the full approach. I'll use my calculator to calculate that and then we'll check whether it fits the format of Euler's theorem. So 5 to the power of 9 mod 24 using my calculator after the scale. So I can do modulus 5 to the power of 9 mod 24 according my calculator if it calculates manually is 5. 5 to the power of 9 is 1953125 and then if you mod by 24 the answer is 5. And we see that because it fits Euler's theorem, the second form. Because we see, recall that the totient of 24 we calculated before the break was 8. So in fact what we get is 5 to the power of the totient of 24 plus 1 mod 24 which fits the structure of Euler's theorem, the second form. a to the power of the totient of n plus 1 equals a in mod n assuming a is relatively prime with n. In this case 5 is relatively prime with 24. That was using this equation. So the point is you can use these theorems to solve some problems as opposed to manually calculating or fully calculating first the exponential and then the mod. You'll see in exams it's faster to use the theorem than to try your calculator. Especially if you've got a large number, large numbers here. You find your calculator will not be accurate or it will start to round once you get to 12 digits. When you've got a large number with a large exponent the result will be very large and your calculator may not handle it. And hence using one of the Euler's theorem or even Fermat's theorem can be useful. I'll talk about the exam in a moment. So yes I'll answer that. Let's finish on this topic so we can talk about the exam. Any questions on what we've gone through today? Not about the exam but what we've gone through in modular arithmetic. We went through the first four operations. We haven't gone through exponentiation and logarithms and we will not go through them in detail. Exponentiation is simple. It's just repeated multiplications. So the same rules apply as our normal arithmetic. Logarithms which are the inverse operations of exponentiation Again we need to do some... We had the multiplicative inverse, the additive inverse. We need to do some operations to calculate a logarithm. It's much more complex and we'll go through them after the midterm. We'll not be covered in the exam. It needs a bit more time and we need to go through some other examples beforehand. But we will cover those last two operations at a later date. So we're going to finish here. So we've gone through the operations for modular arithmetic up the division. And importantly we've introduced things like relatively prime Euler's totient function and two theorems were presented or given to you that may be useful. Any questions on this topic before we stop?