 What we've covered so far is block ciphers and stream ciphers. Both of them are using symmetric key cryptography, in that when we saw desks, when you saw it in your homework, same with AES, the Advanced Encryption Standard, even RC4, which is a stream cipher. In all of them, the sender has a key and the receiver to decrypt must have the same key. So by symmetric ciphers, we mean that the key is the same at both sides. There's one key and it must be kept secret. That's the most common form of cipher. It's been around for a long time. All the classical ciphers use that approach where you need to have some secret and decrypt, you need to know that secret. In the last 30 or 40 years, and maybe a bit older than that, but not so publicized, people come up with a new form of cryptography that avoided the need for both sides to have the same secret. The problem with requiring the same secret, that is at the encryptor and decryptor, is that somehow that secret, that key, needs to be distributed. So if I want to encrypt something and send to you using desks, I choose, for example, my desks key and somehow I need to get that desk key to the destination so that they'll be able to decrypt. How do I do that? How do I send my key to someone else? Assuming they're on the other side of the world. Okay, you know, we want to communicate across the internet. I want to encrypt a file using desks. I choose some random 64-bit key and encrypt. I can send the ciphertext, the encrypted file, to the destination via the internet, but for them to decrypt, they need to have the key. How do they get the key? Any ideas? A voice call over the internet, but the problem with that is that we're assuming that the internet is not secure. That's why I'm encrypting the information in the first place. So when I send, let's say, my email message, I want to encrypt it. Why would I want to encrypt an email message? Because I don't trust the internet service providers or someone in between my computer and the destination because possibly they can read my message. So picking up the phone or Skype or a online application to make a voice call, still we have to send that key via the internet. So that doesn't help because if someone listens in, listens into my Skype call or my message that I send and sees the key, then of course they can decrypt my file. Any other ways to send the key to someone? Okay, some physical device that generates some key, let's say based upon some timestamp or current time it generates the key. How do I get that device? I want it, with the internet we want to communicate instantly. I want to send an email to someone. For that approach to work that person I want to communicate with must have this same device that I have, not so convenient. Maybe I can post it to them, so maybe in a week's time they can read my email, but not so useful for real-time communications or at least normal internet communications. In the same way that maybe I could write on a piece of paper my key, put it inside an envelope and use the old snail mail, the post to send it. So long as I trust the post, maybe if it's very secret, maybe someone just read the letter at the receiver and see the key. So what else can I do? Fly there, expensive. Not very convenient. Anything else that I can do to send someone the key? If I send it across the internet, someone may be able to see the key. What could it be? Hidden message. Okay. Stegonography. There's one way. Hide that key inside some other message. Okay, there's one option. But I have to tell, for that to work, for the person to find the key from the hidden message, they must know the algorithm for how I hid it. So how do I tell them the algorithm for how to hide messages or how to unhide messages? It's the same problem. So it's getting this initial information to the receiver is possible, but quite inconvenient with the normal approaches we have. What about if we encrypt the key? Then how do we, if I encrypt the key, then I need another key to encrypt it, then how do I get that other key to the other person? It's the same problem. So using symmetric key encryption works, except there's a problem of key distribution. Asymmetric cryptography tries to overcome that problem. It provides encryption by using two different keys. Not the one same secret key, but a secret key and also a public key. A key that everyone can know, including the attacker or malicious user. And what we'll see, and we'll see it after the midterm, what we'll see is with asymmetric cryptography, what you do is you encrypt using your algorithm using a public key and you send the ciphertext to someone and only the person who has the corresponding private key can decrypt. So the idea is I want to send to someone, I encrypt, so every user has two keys, a public and a private key. So the destination has their own public and private key. If I want to send something to them, I encrypt it with their public key and the algorithms are designed such that only the person who has that corresponding private key can decrypt. And that's a way to avoid having to distribute the keys. We still need to distribute a public key, but by definition a public key we can just tell everyone. We don't have to keep it secret. Now we're not going to cover how that works until after the midterm, but some of the mathematics that it depends upon, the example algorithms we'll look at, requires some different or some things that you may not know, and that's what we're going to cover today. It's a very simple number theory. Some of it you'll already know and we'll just quickly go through to refresh your memories. Some of it will be new. So this topic on number theory is going to support the next topic on public key cryptography. Start simple and we'll go through some examples as we go if I have some. You know that a number has a number of divisors or sometimes we call the factors, a factors of any number we can find. Let me get organized here. So just some definitions of terminology. So you know this or at least most of this, but you may not have used the terminology. We can say some number, some b divides a. We're both b and a integers. If a is equal to some other integer m multiplied by b, that is two divides ten. The way we write it, two divides ten, for example, because ten equals five times two. So we can work out what the divisors are of some integer. So what are the divisors of the number ten? What divides ten? Ten, two, five, one. So they're the divisors of ten. So we're dealing with integers here. So that's simple. So sometimes you may see the notation written as, for example, a divisor b or ten, b is a divisor of a, so two divides ten, for example. That's nothing new, just some terminology. So the other way you think of it is a factor. So what are the integer factors of ten, one, two, five and ten? The numbers that can divide ten and give us an integer as an answer. And the other thing you probably know is that we can look at two numbers and find the greatest common divisor. So what's the greatest common divisor of ten and fifteen? Five. So we just look at the divisors of ten, one, two, five, ten. The divisors of fifteen, one, three, five, fifteen. And what's the greatest common number? Five in that case. So the greatest common divisor is something that we see sometimes. There are algorithms to find that. That is when we have large numbers to more efficiently determine the greatest common divisor of two integers. We're not going to cover the Euclidean algorithm, but there are ways to implement that. Something that you may not have heard of. We mentioned it in a previous topic, but we didn't really explain it. We can say that two integers are relatively prime if their greatest common divisor is one. So it's a concept which I think is new to most of you, relatively prime. So we compare two numbers. If their greatest common divisor is one, then we say they are relatively prime. So don't confuse it's a prime number, it's slightly different. The two integers are relatively prime if the divisor is one. Are ten and fifteen relatively prime? The integers ten and fifteen, are they relatively prime? No, the greatest common divisor of ten and fifteen is five. So those two numbers are not relatively prime. What is a number that is relatively prime with ten? So given the number ten, find another number which is relatively prime with it. And there may be multiple answers. Some people have said an answer, some have said a wrong answer. Again, a number which is relatively prime with ten. One, three, five is not because five and ten have a greatest common divisor greater than one. Two is not. So there are many, okay. So we look at the divisors of ten, one, two, five and ten. They cannot be relatively prime with ten and any numbers which are multiples of ten or of the divisors. So one is relatively prime with ten. Three is relatively prime with ten. Is four? Four is not because four and ten have a greatest common divisor of two. Six is not because since ten is an even number, it has a divisor of two. So any other even number will also have a divisor of two. So we can work out which integers are relatively prime with each other. We'll use that as we go through. Another thing that you know about, I'm sure you've seen, is prime numbers. So a prime number or an integer, an integer greater than one is a prime number if and only if its divisors are one in itself. So the definition of a prime number. And we can often, we can always factor any integer into divisors which are primes. Before we go into that definition, some example of prime numbers and you would have seen them is on the next slide. So this is a list of the prime numbers which are under 2,000. So all of these, for example the number 97 is a prime number because the divisors of 97 are one and 97. And that's it, there are no other divisors. So our prime numbers, prime numbers are used in a number of the ciphers that we look at with asymmetric cryptography. Any integer, doesn't have to be prime, any integer can be factored into prime numbers. So choose any number and we can find its factors or its divisors which are all combined of prime numbers. And sometimes we may write that, and let's give an example to show that. Note that there's a mistake in this equation here. Where a equals p2, p is a prime number. Instead of 2 it should be 1 here, this first p2 should be p1. So you can fix that in your notes. If we have prime numbers p, like the first prime number, the second prime number, the third prime number, p1, p2, p3, then any integer a, we can write as the multiplication of those prime numbers raised to some exponent. Let's give some examples. Let's write it on the board for these simple ones. Let's do it on the screen. What's the, write the number 18, for example, as, find the prime divisors of 18. The prime factors of 18, okay, 18. So 18, and we'll write them in a moment, you'll try another one, is 2 times 9, or 2 times 3 to the power of 3. 2 and 3 are prime numbers. So we can break 18 into the multiplication of multiple prime numbers. What about 22? Find the prime factors. And 24, okay, so we can write them. Let's see if I can write that, so it's a bit clearer. So some examples, what have we got? We can write 18 as 2 to the power of 1 multiplied by 3 to the power of 2, where 2 and 3 are prime numbers, p1 and p2, and some exponent. And similar, we can consider any integer. Another example is 22. What are the prime factors of 22? Remember, 2 is a prime number. It's, we can write it in as 2 to the power of 1 times by 3 to the power of 0. Let's list all the prime numbers up until the maximum one, sometimes useful. What else do we have? 7 and 11 to the power of 1. So one way to be complete is to look at the prime numbers in sequence. So the first five prime numbers are 2, 3, 5, 7 and 11. 22 is any integer is made up by multiplying prime numbers together, the prime factors. In this case, it's 2 to the power of 1. Well, we don't have a 3 in here. We can say 3 to the power of 0, which is just 1, multiplied by 1 by 1 by 1, multiplied by 11 to the power of 1. Or we could have, in shorthand, write 2 to the power of 1 times 11 to the power of 1. Sometimes we look at the exponents. And 22 is simply, if we write the prime numbers in order, 1, 0, 0, 0, 1, that's used in some forms. I don't think we'll see it in any other examples. So just a characteristic of all integers can be factored into prime numbers or have prime factors. And that will become important later. One more example, what is it? 24. What is 2 to the power of 3, which is 8, times by 3 to the power of 1, which is 3. So again, the exponents here are 3 and 1. So in theory, any integer can be broken into its prime factors. In practice, with large integers, finding the prime factors is very time consuming. That is, for very large integers, when we're talking about hundreds of digits, hundreds of digits long, finding the prime factors of a very large number is effectively impossible with the compute power we have. There are no known algorithms that can do it in reasonable time. We'll see that that's an important part of some security algorithms later. So simple stuff so far. We have prime numbers, we have divisors, we have a greatest common divisor, and maybe the only new thing to use two integers are relatively prime if their greatest common divisor is 1. Any questions? Nothing complex yet. Next thing. What are, when we do normal arithmetic, ignore modular arithmetic, when we do normal arithmetic, what are the operations that we know and we use all the time? Arithmetic, when you learn in primary school, what are the operations, the first operation you learn? Addition, second, subtraction, multiplication, division. Anymore? Anymore? Mod. Before mod, you probably learned some, maybe you learned exponentiation and logarithms, raise to the power of, and a logarithm, which is the inverse effectively. So how would I write it, but sometimes exponentiation, you see the hat character two to the power of three, like we saw in our prime numbers. And the other operation we sometimes see is logarithm. Note that they are related in some way, that in that is, for example, exponentiation raising a number to the power is just multiplying multiple times. So there's a relation between multiplication. So that's the operation that we have in normal arithmetic, and we can see that they go together, that is, we could think that subtraction is the opposite of addition. Three plus two equals five, five minus two equals three. So we can say that subtraction is the inverse operation of addition, inverse of addition. And similar division is the inverse of multiplication. Five times two is 10, 10 divided by two is five. Okay. And similar logarithm is the inverse of exponentiation. So those operations are related. You know them, your experts on them. What we're dealing with in a lot of the security algorithms is modular arithmetic. When we introduce in all of these operations the mod operation, sometimes written as percent, that is, we find the remainder. So let's look at modular arithmetic. So some definitions first. So what do we mean by mod? If we have some integer a and some positive integer n, then a mod n is the remainder when a is divided by n. That's what we know as mod. n is called the modulus. So a mod n, n we call the modulus. And the answer is the remainder. What we're going to deal with is modular arithmetic. We can say that two integers a and b are equivalent or more precisely congruent modulo n. If a mod n is the same as b mod n. So if a mod n equals b mod n, then we say that a and b are congruent modulo n. And we often write that is simply a is equivalent to b when we use mod n. So we often write now a is equivalent to b and then in brackets mod n. For example, 12 mod 10 is equivalent to 2 mod 10. Okay, so 12 is equivalent to 2 or congruent modulo in mod 10, they are equivalent. So 12 mod 10 equals 2 mod 10 or 12 equals 2 in mod 10 is another way to think of that. Note that the mod n operator mod by something, it takes the set of integers or possible integers and maps them into a finite set. From 0 up to n minus 1 and we often denote that set as z n. So when we mod by 10, any integer, the answer is always going to be between 0 and 9. Modular arithmetic performs our operations that we have for normal arithmetic but all in mod n. And within the confines of the set z n. So the answers will always be in z n when we use our modulate arithmetic. And in fact, effectively the inputs are all within the set as well. So we'll define that we can, when we do modulate arithmetic, we'll go through the six operations and see how they work when we use the mod form. Some are obvious, some are not so obvious. Because this form of arithmetic is used in some of the ciphers that we'll cover later. In fact, we've already seen it in some of our ciphers. We've seen it in the Caesar cipher. So the properties of modular arithmetic, some of them are similar to the properties of our normal high school primary school arithmetic. So some of them are defined here. So when we consider addition, subtraction and multiplication, then how we calculate them in normal arithmetic also applies with modular arithmetic. So some of the rules that we'll see, for example, a mod n plus b mod n, all mod n, is the same as a plus b mod n, similar with subtraction and multiplication. Let's go through some examples and then come back to these rules. Just to make sure everyone's on the same page, everyone knows what's going on. And the example is I'm going to do here in, we can do them in any, with any value of n, but I'll do them with mod at nine, just to keep things interesting. For example, let's assume everything that I write here is in mod nine. Our modular, modulus is nine, mod nine. So say, sometimes to save space, they will not write mod at nine. I'll just write the normal operation. So let's start simple. What is six mod nine? Well, you can tell me the answer very easy, but we can write it in the full form. The way that we think of module, mod is we have some number multiplied by nine plus a remainder equals six. So some integer times nine plus a remainder equals six, the answer of six mod nine is that, that remainder. So in this case, what do we get? Zero. Zero times nine plus six. So the answer is six. Okay. Just a very, very basic way to look at the modular operator, modulus. 23 mod nine. Well, we can do it the same way. Some integer multiplied by nine plus a remainder equals 23. What's the answer? Or what's this integer? Two times nine is 18 plus five is 23. So the answer here is five. Although we don't, we will not use it in most of our cryptography, but just for interest. What about minus 24 mod nine? Same approach. Some value times nine plus our remainder equals minus 24. What's the answer? Try. Some number, some integer times nine plus something equals minus 24. What is the first, what is the multiplier and what is the remainder? What about, and note that this multiplier can be negative. Okay. Try negative three. Minus three times nine is minus 27. Plus three is minus 24. So the answer is three. Okay. So minus 24 mod nine is three. Okay. I don't think we'll see the negative mod. We saw it in Caesar cipher and the ciphers earlier. I think you've seen it there, but I don't think we'll see it much later than that. That's easy. That's very basics of modular arithmetic. Some properties that hold when we do modular arithmetic, when we add two numbers in mod n, when we multiply numbers in mod n, similar rules or laws that we've seen in our normal arithmetic. For example, this one is w plus x mod n is the same as x plus w mod n. So that law still holds. Similar, w times x times y, all times y is the same as w times in brackets x plus y all mod n. So the order in which we add them and multiply doesn't matter. And that's the same in our normal arithmetic. Two times three or three times two, we get the same answer. That's all it's saying there, these rules. And we can expand, for example, w times x plus y in brackets is the same, all mod n is the same as w times x plus w times y mod n. So that's a law that you know as well. And we also have identities. That is zero plus some number in mod n gives us that number mod n. And that's in normal arithmetic. Zero plus five is five. Zero plus five mod eight is five mod eight, which is five. And also with multiplication, our identity is one. One times some number gives us that number. So this is normal information. Something that you know about but you probably do not call it. We also will define what's called the additive inverse. For every integer in our set, z n, where n is our modulus, there's some other value z, lowercase z here, such that we add those two numbers together, we get zero. This other value z, we'd call the additive inverse of w. So every integer has an additive inverse. That is when we add one number to its additive inverse, we get zero in mod n. That's the definition there. Some quick examples for the additive inverse. And for me, all right, so for the additive inverse, and we're still doing it in mod n, mod nine. So just make note, everything on the example so far is in mod nine. Keep it simple. An additive inverse, let's call it AI. What's the additive inverse of three? What is, try, write it down, work it out. What is the additive inverse of three? And for a hint, when we use mod nine, remember our set, z nine. We have the values from zero, one, two, up to what? They are the numbers we're dealing with when we do mod nine. Everything, every answer is going to be a number between zero and eight. In fact, every input we can think of simply is a number between zero and eight. We operate our addition, subtraction, and so on. All operates on values within this set. So again, what is the additive inverse of three? Six. And let's go through the full way. The additive inverse is, we have three plus some number, mod nine, give zero. That's our definition of additive inverse. When you add the two numbers together, you get zero. And the number will be six here. Three plus six mod nine is zero. So we say the additive inverse of three is six. What's the additive inverse of six? Three. Three, okay? It goes the other way as well. So you can't say negative three? No, not negative three. Because with modular arithmetic, mod n, or in this case mod nine, everything is within the numbers zero to eight. We don't have negative numbers here. Whereas with your normal arithmetic, yes. You'd say the additive inverse of three in our normal arithmetic is minus three. Okay, that's correct. But we've got a different form here. In normal arithmetic, you operate on an infinite set of numbers. Here we have a finite set defined as zero to eight. What's the additive inverse of eight? Easy. The number when we add with eight, we get zero, one. One plus eight is zero in mod nine. Okay. So we have additive inverse. Every number in our set z nine has an additive inverse. So of those eight numbers, zero through to eight, you can find the additive inverse. Always every number, every integer in our set has an additive inverse. So from our operations, we can do addition. Addition in modular arithmetic is the same as in normal arithmetic. Just add the numbers and then finally mod by n. Subtraction. How do we subtract? Now let's switch back. In your normal arithmetic, how do you subtract numbers? Well, we said before, we can think of the operation as the inverse of addition. So subtraction is the inverse of addition. So we said, someone said the inverse of three, the additive in, the additive inverse of three in our normal arithmetic is minus three. Okay. So three, some number minus three is the same as that number plus its additive inverse. We use the same operation in modular arithmetic. Let's try it for subtraction with some examples. That is, subtraction in modular arithmetic is simply we add the additive inverse. So all still in mod nine. Let's give some examples for subtraction and start simple. What's seven minus three in mod nine? Well, subtraction is the same as seven plus the additive inverse of three. Mod nine. And we know the additive inverse of three is that additive inverse of three is six. So we get seven plus six, 13, mod nine because although I haven't written it, all of these operations in mod nine, which is four. Seven minus three is four when we use mod nine. Okay. That's easy. Let's try another one then. Two minus eight in mod nine. Mod nine. What is two minus eight? Try and calculate. Remember in mod nine, all the numbers are between zero and eight. So it's the same as two plus the additive inverse of eight. And the additive inverse of eight in mod nine is one. The additive inverse of eight in mod nine is one because eight plus one mod nine equals zero. So the answer is simply three. Two minus eight equals three. Okay. So that's something that's the first thing people get confused with. Don't apply your normal operations of your normal arithmetic. Now we're limited in a set when we do modulate arithmetic. In this case, mod nine arithmetic. Same you saw in the Caesar cipher is the shifting by eight positions but going backwards when we subtract. Remember because we wrap around effectively. We go zero up to eight, zero up to eight. If we start at two and go backwards, then we end up at three. If we go backwards eight positions. If we're at two and we move back eight positions in our Caesar cipher. One, two, three, four, five, six, seven, eight. We end up with three. So two minus eight is three. So we saw that in the Caesar cipher and the subsequent ciphers based on the Caesar cipher. It's just expressed mathematically here. So we can now do addition in modulo arithmetic. It's the same as our normal arithmetic. We've defined the additive inverse. When we add a number with its additive inverse, we get zero in mod n. And we know the operation for subtraction. It's simply a minus b is a plus the additive inverse of b all in mod n. Next operation. Multiplication. Same as in our normal arithmetic. So effectively the same. You can multiply and just mod the answer by n. So in mod nine, two times four is eight mod nine, which is eight. Two times five mod nine is 10 mod nine, which is one. So multiplication is easy. It's just our normal arithmetic mod nine. So addition, subtraction, multiplication. And the same as to do subtraction. We use the additive inverse because we think of subtraction as the inverse operation of addition. The inverse operation of multiplication is division. So to do division, we multiply by the multiplicative inverse. So we've got a new concept. Numbers can have an additive inverse in modulo arithmetic. Some numbers can also have a multiplicative inverse. And that's defined on our next slide. That was that was additive inverse. All integers have an additive inverse. We can also define a multiplicative inverse. A is a multiplicative inverse of B if A times B equals one in mod n. And that's the same as in the same concept as in our normal multiplication and division. In what would you say is the multiplicative inverse of three in our normal arithmetic? In our normal arithmetic? One third. In our normal arithmetic, three times one third equals one. Four times by one over four equals one. So in our normal arithmetic, we have a multiplicative inverse which is just one over that number. In modulo arithmetic, same concept. The multiplicative inverse, if we multiply the two numbers together, we get one mod n. Let's try some. Get that out of the way. Come back. Gonna crash. It's my computer crashed. Software is crashed. Let's try it on the board. Some multiplicative inverse examples in mod nine. So still everything in mod nine. What would the in some in abbreviate multiplicative inverse of let's say one? What is the multiplicative inverse of one? By definition, you multiply one number by its inverse and you get one. So that one's simple because one times by some number mod nine equals one. What is that number? One in this case. One times one mod nine is one. The multiplicative inverse of one is one. That's easy. What is the multiplicative inverse of two? So two times by some number mod nine equals one. That's the definition. What is that number? So two times something mod nine equals one. So five. Two times five is ten. Mod nine is one. So the multiplicative inverse of two is five. Multiplicative inverse of five? Two, we can see. If two times five equals one, then five times two equals one. It goes the same in the opposite book. As four, three times 12, four. Four times something equals one. What is that something when we mod by nine? I think, so again four times by something. All mod nine equals one. Four times seven equals 28. 28 mod nine is one because three times nine is 27. Easy. Three, multiplicative inverse of three. We won't go through all of them. Find the multiplicative inverse of three. Well, I try and fix my computer. Anyone have an answer? There is no answer. There is no multiplicative inverse of three because there's no integer in our set. That when we multiply by three and mod by nine, we'll get one. We all we need to consider really is the numbers zero through to eight because they are the numbers we deal with when we mod nine. Three times zero, three times one, two, three, four, five, six, seven, eight. When you mod by nine, none of those values will give you one. So there's no answer. Well, we say that three does not have a multiplicative inverse. Not all integers have a multiplicative inverse. All integers have an additive inverse, but not all of them have a multiplicative inverse. And more precisely, some integer a will have a multiplicative inverse in mod n if a is relatively prime with n. So five is relatively prime with nine. Therefore, it has a multiplicative inverse. Four is relatively prime with nine. Therefore, it has a multiplicative inverse. Three is not relatively prime with nine. And therefore, it does not have a multiplicative inverse. So not all numbers will have a multiplicative inverse. One more attempt. So let's list out numbers. What do we have? Just for reference, we have one, two. I think the ones we just calculated that have an inverse four, five, one map had an inverse of one, two had an inverse of five, four had an inverse of seven, five an inverse of two, seven, four, not five. Any others that have a multiplicative inverse in mod nine? Eight is relatively prime with nine. Therefore, it should have a multiplicative inverse. What is the multiplicative inverse of eight? It's, in fact, remember, it can only be these numbers from this set. It's itself. If this is a, and this is the multiplicative inverse of a. Eight times eight is 64, mod nine is one. So they are the multiplicative inverses in the set Z nine when we mod by nine. So not all integers have the inverse. Zero, three and six do not. So now we can do division because division is simply a divided by b is a multiplied by the multiplicative inverse of b. In the same way that a minus b was a plus the additive inverse of b, a divided by b is a multiplied by the multiplicative inverse of b. Some quick examples, what have we got? What's four divided by two in mod nine? So to go precise, we have four divided by two is four times by the multiplicative inverse of two, mod nine, which is four times five, which is 20 mod nine, which is two. 20 mod nine is two. Four divided by two is two. That was easy. Try this one. Six divided by seven. Find the answer. Six divided by seven in mod nine. Everything's in mod nine in these examples. Just four, six. Anyone else want to guess? So go through the, what's the multiplicative inverse of seven? I've listed them up the top in fact, four. So six times four. So is six times four, which is 24. And 24 mod nine is six because two times nine is 18. So six divided by seven equals six when we use modular arithmetic with n equal to nine. So we can now do the four main operations. Addition, subtraction, multiplication, division. Exponentiation and logarithm are more complex, but in fact based upon multiplication and division. Any questions? You need to get outside of your normal arithmetic and just follow the basic principles. It's just that you've been doing normal arithmetic for so long, you immediately know the answer. Remember all of our answers when we mod nine, the values between zero and eight, the integers between zero and eight. We don't have fractions. We don't have negative, we don't have negative numbers or fractions or numbers greater than eight when we do mod nine arithmetic. Of course, I'm just using nine for an example where it can be mod anything. Same principles. The two key things that will come up later, we've seen the additive inverse. Every integer has an additive inverse. Not every integer has a multiplicative inverse. Only if that integer is relatively prime with n does it have a multiplicative inverse. And that will become important when we look at the ciphers and the way, for example, RSA works. So we've done division. We're not going to at the moment go through the other operators. Let's quickly look at a couple of theorems and then one new concept, the Euler's totient function. In fact, let's not go through Fermat's theorem until after the break. Let's go direct to Euler's totient function and define what that is. And later we'll see it's used in Euler's theorem. And it's very important when we look at the asymmetric ciphers. Written as phi of n. In short, we may say the totient of n returns some value. And the value, this function, it returns the number of positive integers that are less than n and relatively prime with n. So what we do if n equals 10, we look at the integers from 1 up until 9, the integers that are less than n. So if n is 10, 1 to 9, and which of those are relatively prime with n. And that's the answer. So the totient of some number, we look at how many of numbers are less than that, which are also relatively prime with that number n. We'll see some special cases, but let's go through some simple ones first and then we'll have a break. Let's try. What is the totient of 10? What is Euler's totient of n equals 10? So by definition, it's the number of numbers less than 10, which are relatively prime with 10. So go through and look at all of them. So the long way is to look at all the numbers from 1, so effectively from 1 up to 9 in this case. Let's list all the numbers first, I will, so everyone's clear. So the question is, of those nine numbers, which ones are relatively prime with 10? And to help, what are the divisors of 10? Just to go simple, the divisors of 10 are 1, 2, 5 and 10. And remember, relatively prime is the greatest common divisor of the two numbers is 1. So 1, the greatest common divisor of 1 and 10 is 1. So this is a number. 2 is 2 relatively prime with 10. No, because 2, and there's a divisor 2, so the greatest common divisor of 2 and 10 is not 1. So it will not count, it is not relatively prime. Is 3 relatively prime with 10? Yes, 4? No, 4 has a divisor which is 2, it's greater than 1. 5? No, because 10 has a divisor of 5. 6? No, because 6 has a divisor of 2, as does 10. 7, yes, 8, 9, yes. That is 1, 3, 7 and 9 are all relatively prime with 10. Therefore Euler's totion of 10 is 4. The count of numbers, 1, 2, 3, 4. So the totion is how many numbers are less than n and relatively prime with n? So we went through the long way to do that. You'll try a quick, what's the totion of 24? Try and calculate the totion of 24. And then one more, once you've done that, the totion say of 11. So for the totion of 24, look at the numbers from 1 to 23, which ones are relatively prime with 24? We will do it after the break. Anyone have an answer? So simply look at the divisors of 24. That may help. So with the totion of 24, you need to go through and look at those numbers and you see is 1 is a relatively prime. 2 is not, because it has a common divisor of 2. 3 is in fact a divisor of 24, so therefore it's not relatively prime. 4 is a divisor of 24. So if you find all the divisors of 24, those numbers will not be relatively prime, except for 1, and any of the multiples of those numbers will not be relatively prime with 24. Anyone get an answer? Totion of 24, what is the totion of 24? The totion is the number of numbers which are relatively prime with it. The answer is 8, and the totion of 11 is 10. For 24, you have to confirm for yourself why it's 8. For the totion of 11, that's a little bit easier. Note that 11 is a prime number. So what are the divisors of 11? 1 and 11, it's a prime number. The divisors of 11 are 1 and 11. So look at the numbers from 1 to 10, and see which ones have a greatest common divisor with 11. And you'll find all of them. All of the numbers less than 11 are relatively prime with 11. That is 1, 2, 3, 4, 5, 6, 7, 8, 9, 10. And that applies for all prime numbers. The totion of a prime equals that prime number minus 1, and that's on the previous slide. So that's a shortcut. But if n is a prime number, then immediately you can find the totion. It's just that prime number minus 1. Because the divisors of 11 are 1 and 11. So we compare them between the numbers from 1 up to 10. And of course none of them will have a common divisor of 11. They'll all have a greatest common divisor of 1. 1 and 1, 2 and 1, 3 and 1 and so on. The greatest common divisor will be 1. So if n is a prime number, we can determine the totion simply. The prime number minus 1. If n is not prime, if it's composite, then you need to calculate or count them. And that's what's here. All right, this is some special cases. The totion of 1 is always 1. The totion of a prime is p minus 1. Where p is the prime. And we'll give an example after break. Another useful property. If n is the multiplication of two prime numbers, then the totion of n is the totion of the multiplication of p multiplied by the totion of q. So there are some shortcuts. But if our n isn't a prime number, or is not made up as multiplying two prime numbers, then you need to manually calculate it. And again, this will be very important in our asymmetric ciphers because when we deal with big numbers, hundreds of digits, then manually determining the totion is practically impossible. Unless that n is a prime number. Let's have a break. And then when we come back after the break, we'll give a few more examples of the totion, and then we'll come back to Fermat's theorem and Euler's theorem. And then we'll, I think, we'll look at some hints for the exam.