 Up until now, we've covered symmetric key cryptography. That's all we've looked at. The classical ciphers in the encryptor and decryptor, they both need to have a shared secret key. With desks, AES, triple desks, those block ciphers, they all require both sides to have the same secret key. And then last lecture we looked at random numbers and one role of random numbers is in stream ciphers. A stream cipher really is take a random number, XOR it with our plain text. And the decryptor uses the same pseudo-random sequence and XORs with the ciphertext. But again, stream ciphers still are symmetric key systems in that both the source and destination must have the same shared secret key. This is called symmetric key cryptography and it's still widely used and it's especially for data encryption. But there's another form of cryptography called public key cryptography where the source and destination or the encryptor and decryptor use different keys. One key is used to encrypt, a different key is used to decrypt. But there's some relationship between those keys. So that's the next topic that we need to look at is public key cryptography. And it will take some time to go through it. But to understand some aspects of public key cryptography we need to review some number theory, some very basic mathematics. So what we'll start today, you probably know half of it. Maybe you forgot it but you've learnt it at some stage. So very simple. But we'll see it will lead to some concepts that we will use when we look at public key cryptography. So we need to know them now. So we'll go through, I'll introduce some concepts or refresh on some concepts, give a few very simple examples today and maybe even a little bit next week. Some different aspects of, we'll just mention about divisibility and some aspects of prime numbers and then modular arithmetic. Divisibility, we often, we want to care about finding the divisors of a number. Given a number, what can we divide it by and to get integer results? So we may say that B divides A if there's some number which we multiply by B that gives A where all those values are integers. So B divides A if M is an integer where we can multiply M by B to get A. So we talk about a divisor. We can say B is a divisor of A. So this is nothing new. The other word we will use is a factor. We say B is a factor of A. And we sometimes care about the greatest common divisor. So given two numbers, A and B, what is the greatest common divisor of those two numbers? So find the divisors of A and B and then of that set, the two sets find the one which is the greatest and it's in both of those sets. So GCD is just the abbreviation of greatest common divisor. There are actually some algorithms to find that for us. We will do it for a few simple examples, small numbers, but when you have large numbers and later when we look at public key cryptography we're dealing with some large numbers of hundreds of digits, then you need some algorithm to go through and find greatest common divisors and there are some algorithms that will do it quite efficiently. We can say, maybe this is new, we can say that two integers A and B are relatively prime if their greatest common divisor is one. This is not prime. This is a different thing, relatively prime. So any two integers, if their greatest common divisor is one then we can say those two integers are relatively prime with each other. We'll see that in use shortly. Just to be simple, you can help me out. What are the divisors of 15? One, three and five. And 15. One, three and five and 15 can all divide. 15 we can divide by those four numbers so we can say they are the divisors. I will not write them down, that's easy. Usually we, actually we can write them down just to be complete. We can say the divisors are one, three, five and 15. We can also write that number 15 as a multiple of some of its divisors. And a multiple of its prime divisors. So we can say 15 is equal to three times five. And in fact any number we can do that. We'll see some examples. Maybe it goes straight to it. What's the greatest common divisor? 15 and 16, for example. The greatest common divisor of those two numbers. Write it down, you find the answer. And someone in the, looking at the TVs, in the back rows, tell me the answer. Greatest common divisor of 15 and 16. You can use your phone if you want to calculate. Someone can help him. One. Okay, in this case it's one. So the divisors are 15, a one, three, five and 15. The divisors are 16, two, three we cannot pour, eight, 16. They're the divisors. So the greatest common divisor amongst those two sets is one. So another thing we can say is 15 and 16 are relatively prime. Any two numbers which have the greatest common divisor of one, we say they're relatively prime. Any more examples needed for that? I think you can find divisors easy. Of course, if the greatest common divisor is not one, it's greater than one, then they're not relatively prime. They either are relatively prime or not. What's next? Let's look at prime numbers then. What's a prime number? Divided by one and itself. So any integer p is a prime number if and only if its only divisors are one and itself. We know about prime numbers. And another thing we know already is that any integer, prime or not, can be factored or written as the multiplication of a set of prime numbers. In the formal way, some integer a can be written as a mistake here. This should be p1. This subscript of the first one should be p1 to the power of a1. p2 to the power of a2. p3 to the power of a3. Up to pt to the power of at. In general, we can write any integer as multiplying a set of primes together. And that's probably best illustrated by an example. And we've done it already for 15. 15 can be written as 3 to the power of 1 times 5 to the power of 1. We do it for all primes. 15 is actually 2 to the power of 0 times 3 to the power of 1 times 5 to the power of 1 times 7 to the power of 0. So in general, we can say that consider all primes and any number is made up of multiplying all those primes together raised to some power. But of course, when it's raised to the power of 0, it's just 1. 16 is the prime 3 to the power of 1 times 5 to the power of 1. 16, how would we write it as multiplying primes together? Times, no. 2 to the power of 4 quite simply here. So 2 is the prime, raised to the power of 4 gives us 16. So 2 times 2 times 2 times 2. Any integer can be written like that. Multiplying primes together. And in the reverse, then we can say that any integer can be factored into its primes. That is, given 15 we can find that 15 is made up of multiplying prime 3 times prime 5. So the prime factors of 15 are 3 and 5. The prime factors of 16 is 2. So we can find the prime factors of some integer. Let's try it for a few others Prime factors of 22 find that. Don't all yell out at the same time. It can be divided by prime 2 and the other prime is 11. 145 5 to the power of someone's told me 3 I don't think it's 3. What do you get? 29 5 times 29 29 is a prime, correct? Okay, so it's 5 times 29. So all we're saying is that any integer we can, in theory, break it into prime factors. That is the divisors of that integer where those divisors are all prime. In practice it's very hard to do with large numbers. And that will come up later as a security mechanism. Given a very large number not 145 but maybe a number which is 45 digits long given that find the prime factors is a problem that's considered too hard to solve with computers assuming that the number is large enough and that will be a principle that's used in securing some systems in public key cryptography. Finding the prime factors is hard when we have large numbers. By hard means it would take your computer forever to do it given the current known approaches. So we know about prime numbers this just lists the first prime numbers under 2000. You'll start to remember some of the first ones up to the first 10 or 15 if you don't already. Finding the value of pi is hard. Pi is the exact value is it? There are infinite number of digits, isn't there? Maybe that's a different definition of hard. Right. Finding the value of a number which has an infinite number of digits is hard in that we cannot compute it in any time. But it's of no benefit for us really from a security point of view. Because no one can find it. But what we'll see with primes and prime factors a security mechanism will be that if you know 5 and 29 it's easy to find 145. Just multiply them together. So if you know the two primes it's easy to find some large number. But if you just know that large number it's hard to find the two primes. That's a principle or an idea that will take advantage of. Going in one direction is easy going in the other direction is hard. But we'll see that later on public key cryptography. What else? Well that's it about the first thing. Dividing numbers, prime numbers. Just remember some of them. Now we'll look at modular arithmetic. What is modular arithmetic? Finding the remainder. Mod we know is finding the remainder and divide by something. So you know about mod. Modular arithmetic is doing arithmetic. Additions, subtraction, division, multiplication, exponentiation, logarithm are our main six operations. Doing arithmetic applying those operations where everything is mod by some number N. That's all. That's what we mean by modular arithmetic. Adding up numbers where we always add numbers. And a lot of the concepts follow from our normal arithmetic. So when I say normal arithmetic the way that you add numbers and subtract numbers. It's quite simple in most cases. But there are a few things that will be introduced which are useful later. So just define if we have some integer A and some positive integer remainder when A is divided by N. So mod we know is the remainder. A divided by N then A mod N equals the remainder when we divide A by N. A is, sorry N is called the modulus. So we talk about the modulus. We can say two integers A and B are really equivalent or more precise congruent modulo N if A mod N equals B mod N. And sometimes we'll write it like this. A and this equivalence sign or the three equals sign B in brackets mod N. Meaning A and B are the same when we mod them both by the same number N. We define so what mod N does mod N is an operator that takes the maps all integers into the set of integers to find a ZN. That is mod N as an operator as the input we can have any integer. And the result will always be an integer from 0 up into N minus 1. If N is 10 for example mod 10 means that any number mod 10 the result will be always between 0 and 9. Okay? And that's defined as the set ZN. So the result of mod N is always a positive number between 0 and N minus 1. We don't have negatives. In some interpretations of mod you can have a negative value. So some programming languages may deal with a variation where you can have a negative value. In here it's all positive results. Arithmetic performs arithmetic operations. So addition, subtraction multiplication, division exponentiation raise something to the power and logarithm those six operations are all performed within the confines of that set ZN which means that the answer is in that set ZN. So we'll go through those operations. Some are very easy. The normal arithmetic just mod by N. Let's go through examples to illustrate the arithmetic. Let's say start simple answer. Let's get through this quick. So one thing we can write is we can say 13 is congruent modulo 3 or equivalent to 3 when we mod them both by 10. It's a notation that we'll sometimes see. When we mod numbers by 10 then the answers are in the set Z10. The answers are between 0 and 9. That's all what we mean by Z10. So let's stay with Z10 that is in everything mod 10 and I will not write it mod 10. Let's just keep the examples. We're using Z10 in this set. Answer Answer 1 In this case we're using modulo modulo 10. Z10 means that everything is mod 10. In addition it's easy. We just do normal addition and then mod by N. In normal arithmetic we have addition In modular arithmetic addition is just the same as the answer and mod by modulus N. Addition is easy. What about subtraction? Another operation. We'll do it in a different view. Over here the normal arithmetic. The normal approach. What's 7 minus 3? Not in Z10 but in our normal arithmetic. 7 minus 3 Easy How do we calculate subtraction with normal arithmetic? Can we convert it to addition? Well subtraction is just addition of a negative number. So in normal arithmetic 7 minus 3 is really the same as 7 plus minus 3. So subtraction is just addition where the number that we add is the negative subtracting and that more precisely is called the additive inverse. Negative 3 is the additive inverse of plus 3 positive 3. The additive inverse is when we add two numbers together and we get 0 then those numbers are called the additive inverse of each other. So sticking so far with normal arithmetic we can say alright plus 3 additive inverse of minus 3 and vice versa. Minus 3 is the additive inverse of plus 3. Why? Because plus 3 when we add them together we get 0. When you add two numbers together and you get 0 then we say those two numbers are the inverse or the additive inverse and subtraction the operation of subtraction is really the operation of addition but we add the additive inverse of the number that we're subtracting. So 7 minus 3 is the same as 7 plus the additive inverse of 3 which is minus 3. That's in our normal arithmetic not modular arithmetic but in fact the same applies in modular arithmetic. Subtraction is just addition of the additive inverse and then we mod by n. What's the additive inverse of 5? Minus 5. Minus 5 in normal arithmetic. It's the negative that's easy. Now let's convert back to modular arithmetic and in Z10 in our example and I'll write it as additive inverse Ai I don't have to write it all. What's the additive inverse of 3 in modular arithmetic in mod 10? Using the same definition of the additive inverse in our normal arithmetic additive inverse is the when we add the two numbers together we get 0 3 plus minus 3 is 0. Now apply that definition for modular arithmetic. The additive inverse of a number is the number that when we add to 3 gives us 0 but in mod 10 in this case. 7. Remember we're doing it in mod 10 in this set of examples. Z10. So if everything is mod 10 3 plus 7 is 0. So we say the additive inverse of 3 is 7 in mod 10. Any questions so far? This is maybe new or a new way to think about some things. You know additive inverse already. You just don't think about it any questions? No answer means okay. So slightly different now we treat subtraction as addition of the additive inverse in the same way as our normal arithmetic subtraction is the addition of the additive additive inverse. So let's try some what is 4 minus 7 in Z10 in mod 10 calculate 4 minus 7 your calculator won't help much 4 minus 7 where we find the additive inverse instead of treating it as subtraction treat it as 4 plus that sorry the additive inverse of 7 4 minus 7 is the same as 4 plus the additive inverse of 7 what is the additive inverse of 7? Well in fact we found it here the additive inverse of 3 in mod 10 is 7 because 3 plus 7 is 0 so similar the additive inverse of 7 in mod 10 is 3 so it becomes 4 plus 3 equals 7 and I will not write up but this is all in mod 10 4 minus 7 equals 7 sounds strange but remember all in mod 10 of course the other way to think of it is wrapping around remember the Caesar Cypher that we implemented the wrap around feature as a mod and it's the same 4 minus 7 go back 7 spots where do you get to? you come back around to 7 if we have a sequence from 0 to 9 Z10 sequence from 0 to 9 if we start at 4 and we go to the back by 7 positions where do you end up? at 7 find the answer of these two 2 minus 6 is 2 plus the additive inverse of 6 what's the number that we add to 6 and we get 0 in mod 10 4 so additive inverse of 6 is 4 so 2 plus is 6 and just for brevity I omit writing the mod 10 in all this so it's all mod 10 5 plus the additive inverse of 3 and we've found that before at 7 5 plus 7 is 12 and again I am lazy I don't write the mod 10 does every integer have an additive inverse? let's try remember we're still in Z10 that is the values from 0 to 9 find the additive inverses the number that we add to A such that when we mod by 10 we get 0 inverse 0 0 plus 0 mod 10 is 0 the inverse of 1 that's an easy one and it turns out for any modulus N every number has an additive inverse we can always add 2 numbers together and get 0 in mod N every number has an additive inverse which means we can subtract any number from any other number so they are easy addition, subtraction, let's move on to multiplication and division the next operations remembering that multiplication is just addition multiple times multiplication we just add numbers together multiple times let's let's change our modulus to be more fun tends too easy let's do everything in maybe something different modulus let's do Z8 that is everything is mod 8 from now on just for something different let's do multiplication multiplication in modular arithmetic is the same as in normal arithmetic 3 times 2 in detail we say 3 times 2 mod 8 so multiplication is easy same as normal multiplication just multiply and then mod by modulus N 8 in this case 3 times 4 3 times 4 is 4 3 times 4 is 12 12 mod 8 we get 4 so you can do multiplication in normal arithmetic division is more fun division division is just multiplication but we multiply by the inverse in normal arithmetic that's how we do it again we'll just switch back in normal arithmetic we can say 8 divided by 3 is the same as 8 times 1 over 3 where 1 divided by the fraction 1 over 3 is the inverse of 3 but this is called the multiplicative inverse let's see if I can write it multiplicative inverse out of space the multiplicative inverse in normal arithmetic is that when we multiply two numbers together and we get 1 we say they are the multiplicative inverse of each other 3 times 1 over 3 equals 1 5 times 1 over 5 equals 1 so it's easy in our normal arithmetic and division is simply multiplication by the multiplicative inverse 8 divided by 3 is the same as 8 times the multiplicative inverse of 3 the multiplicative inverse of 3 is 1 over 3 so 8 divided by 3 is the same as 8 times 1 over 3 let's apply that same concept for modular arithmetic to do division 5 divided by 3 what's 5 divided by 3 in mod 8 division is the same as multiplying by the multiplicative inverse dividing by 3 is the same as multiplying by the inverse of 3 what is the inverse of 3 in mod 8 well the multiplicative inverse is defined as the number that we multiply by such that the answer is 1 and that's the same in modular arithmetic multiply two numbers together you get 1 they are the inverse the multiplicative inverse of each other so 5 divided by 3 is 5 times the multiplicative inverse of 3 am I alright what is the multiplicative inverse of 3 3 times something mod 8 equals 1 the multiplicative multiplicative inverse is this something well it's also 3 3 times 3 is 9 mod 8 leaves us 1 so the multiplicative inverse of 3 turns out to be 3 in this case 5 times 3 mod 8 15 mod 8 is 7 5 divided by 3 is 7 in mod 8 confusing yet any questions same concepts that we've known since primary school adding numbers dividing numbers but now we just formalize some aspects of it we talk about an additive inverse add two numbers you get 0 multiplicative inverse multiply two numbers you get 1 division is the same as multiplying by the multiplicative inverse but now we just do all of that mod n mod 8 in our examples 5 divided by 3 is 5 times the multiplicative inverse of 3 what is that 3 times something mod 8 equals 1 well 3 times 3 mod 8 equals 1 so in fact it's its own multiplicative inverse 5 times 3 all mod 8 gives us 7 try that one 6 divided by 4 mod 8 it's not 0 so go through the steps what do we need to find 4 times something equals 1 that is we need to find the multiplicative inverse of 4 to do division 6 times what is the multiplicative inverse of 4 well it's a number such that 4 times that number mod 8 equals 1 what is this number 9 there is no such number in this case you will not find one you cannot multiply 4 by any integer and mod by 8 to get 1 therefore there is no multiplicative inverse of 4 so we cannot do it there is no answer so in this case we cannot divide we cannot do 6 divided by 4 in mod 8 there is no answer not every integer has a multiplicative inverse we said that every integer has an additive inverse but it doesn't apply for a multiplicative inverse let's check them again we are still in mod 8 or z8 the set is 0 to 7 so the numbers that we can deal with as input is 0 to 7 let's find the multiplicative inverse of those numbers what's the multiplicative inverse of 0 there is no number that we multiply by 0 and get 1 when we mod by 8 so there is none 1 1 times something mod 8 equals 1 1 times 1 1 1 times 1 mod 8 equals 1 inverse of 2 there is none 3 we've done before 4 there is none 5 6 6 times something mod 8 equals 1 because 6 is even we mod by an even number we will not get 1 as an answer here 7 first point not every number has a multiplicative inverse in mod n that's the first point and it becomes important later but in this case z8 we see that the numbers are multiplicative inverses of themselves let's see if that applies for all modulus let's try something else maybe back to what do we have z10 find the multiplicative inverses 0 doesn't have 1 1 will always be itself 2 find it for the remaining numbers 2 times something mod 10 equals 1 again we have 2 even numbers we will not be able to get an odd number 1 as the output in that case 3 3 times something mod 10 equals 1 3 times 7 is 21 mod 10 is 1 4 no even number won't work in this case 5 5 times something mod 10 will never leave us a remainder of 1 6 no even 7 will be 3 they are the inverses of each other so it goes in both directions 9 9 times 9 is 81 so this is just in a different modulus we see the multiplicative inverses it's not always true that they are the inverse of each other that's the point here 3 is the inverse of 7 so in z8 each number that had an inverse was the inverse of itself but that's not always true that was a special case so not all numbers have a multiplicative inverse which means we cannot divide by just any number if we try to divide by a number that doesn't have a multiplicative inverse we will get no answer we just don't define the answer any questions so far we can do addition, subtraction subtraction is just adding the additive inverse we can do multiplication and division division is just multiplying by the multiplicative inverse what's left that we commonly use raise to the power so a to the power of b for example exponentiation and the inverse of exponentiation is logarithm so really exponentiation is just multiplication multiple times 2 to the power of 3 is 2 times 2 times 2 so exponentiation is quite easy we can calculate just do it in calculate in normal arithmetic and mod by n for example we're still in z8 5 to the power of 2 just use normal arithmetic 5 to the power of 2 is 25 mod by 8 and you get 1 so exponentiation is easy logarithm really exponentiation is multiple times logarithm follows from that the inverse of exponentiation in the same way that we not every number has a multiplicative inverse we cannot find the logarithm of any we cannot find the logarithm in modular arithmetic of every possible value we will not go to logarithms yet they're a little bit harder to learn to them later let's go back to our slides and see what we've said modular arithmetic is just performing arithmetic operations within that set zn where we mod by n we'll make use of it in public key cryptography and other techniques some of the properties of our normal arithmetic also apply so the laws for normal arithmetic which you use every day you don't remember them but also apply for modular arithmetic and actually it makes life easier in terms of implementing different algorithms for example a mod n plus b mod n all mod n is the same as a plus b mod n similar for subtraction and especially for multiplication a times b mod n is the same as a mod n times b mod n all mod n those rules apply and some of the others listed down there additive inverse distributive law associative law and so on but this one is useful it's useful in solving calculating the mod of large numbers that is a times b mod n if a and b are large numbers we multiply them together we get a very large number and then try and find mod n a simpler way is to if you know a and b first find a mod n then find b mod n and you get smaller numbers when you mod by n you can get smaller numbers and then multiply them together in terms of implementation that can make algorithms faster to finding the mod of a large number an example let's apply that in an example let's find by hand that is without a calculator a couple of examples first try to use that rule to find 160 mod 8 you could find it directly if the numbers are small enough but try and use that rule and think well some number if we can break it into its divisors we have 160 treat 160 as a times b find some a and b which gives us 160 and then simply mod those numbers by n first there are different divisors but I'll try 160 is 10 times 16 and following our rule that's the same as 10 mod 8 times 16 mod 8 all mod 8 10 mod 8 easy 16 mod 8 0 all mod 8 0 mod 8 returns a 0 find out when we divide 160 by 8 is 0 with small numbers you don't need to apply that rule but when you have larger numbers even with implementing software to do this for us using such properties can make implementations much faster one more 11 to the power of 7 mod 13 no calculator I've done this in quizzes solve it the power of 7 mod 13 remembering raising something to the power exponentiation is simply just multiplying multiple times what can we do the idea is to break instead of 11 to the power of 7 break that into smaller numbers multiplied together and then mod them by 13 so we get small numbers because if you calculate 11 to the power of 7 you get a large number not too large but larger than we can easily do in our head or quickly do well we can think in different ways but one way is to say our properties of exponentiation still apply here it's just so this is 11 multiplied by itself 7 times we can split it into 4 times 1 4 plus 2 plus 1 is 7 move over here let's do parts of them at least 11 to the power of 4 my brain cannot do that let's treat it as 11 squared squared I should put brackets there 11 to the power of 4 is 11 squared all squared 11 squared we can do that if it's 121 mod 13 simply 11 11 squared so it's actually 121 squared mod 13 times keep the brackets here 121 mod 13 we need to do that in our brain what do you get a remainder of 4 9 times 13 is 117 remainder 4 slowly and 121 mod 13 is 4 we just got that 121 squared mod 13 is the same as 121 mod 13 times 121 mod 13 which is the same as 4 times 4 mod 13 and I forgot my mod 13 121 mod 13 all mod 13 is 4 times 4 all mod 13 or 4 squared mod 13 16 mod 13 we still got 4 and 11 16 mod 13 well you can actually solve it there 12 times 11 132 so 13 times 10 remainder will be 2 so we can take this wasn't a very large number but 11 to the power of 7 something we cannot easily quickly do in our head 11 to the power of 7 mod 13 applying the rules of expanding the multiplication we can step through and find the final answer now the point isn't that you need to do this all the time the point is that when we have very large numbers a large number raised to the power of another large number and then mod by some large number calculating that directly is quite slow but steps like this can be implemented in an algorithm that will reduce those large numbers down that's what we're doing instead of 11 to the power of 7 mod 13 we bring it down to the smaller numbers which can be calculated faster so algorithms will apply these techniques to make the calculation feasible in a computer and again by very large numbers I mean maybe hundreds of digits not two or one digit let's introduce a new concept so there are different properties that are used and I don't normally require you to use them much maybe once or twice in a quiz that's all but that one at least but the others don't solve modular arithmetic by hand much it's just illustrating concepts division we'll return to ah maybe we've missed something here in division let's return to it in division we said we can divide when we have a multiplicative inverse and we found that not every number has a multiplicative inverse in z8 we found 1, 3, 5 and 7 they were inverses of themselves in z10 for example we found 1 and 1 3 and 7 are inverses and 9 is its own inverse the inverse is when we multiply those two numbers and mod by n we get 1 you can show that for a number to have an inverse it needs to be relatively prime with n a number a has a multiplicative inverse in mod n if a is relatively prime with n that is the greatest common divisor of a and the modulus is 1 so that's one location where we use relatively prime let's just check if that was the case here n is 8 in this case so is 1 relatively prime with 8 greatest common divisor of 1 and 8 is 1 so 1 and 8 are relatively prime 2 and 8 are not relatively prime the greatest common divisor of 2 and 8 is 2 they are not relatively prime therefore 2 does not have a multiplicative inverse in mod 8 3 and 8 are relatively prime greatest common divisor is 1 to have a multiplicative inverse for z10 for example 2 and 10 the greatest common divisor is 2 therefore 2 and 10 are not relatively prime therefore 2 does not have a multiplicative inverse for a number to have a multiplicative inverse that number must be relatively prime with the modulus n 3 and 10 are relatively prime 7 and 10 are relatively prime 9 and 10 are relatively prime so they have multiplicative inverses so if we want to have a number that has a multiplicative inverse then we choose a number that is relatively prime with the modulus n and that will become useful later when we use this in our security mechanisms let's finish with one more concept as an example what numbers less than 4 are relatively prime with 4 let's do the long way relatively prime means the greatest common divisor of that number and of those two numbers is 1 greatest common divisor of 1 and 4 1 greatest common divisor of 2 and 4 2 and 3 and 4 and also 1 so which numbers less than 4 are relatively prime with 4 1 is relatively prime with 4 2 is not relatively prime with 4 3 is so in this case 2 numbers which are less than 4 are p relatively prime with 4 in this example 4 let's find the numbers less than that number and count how many are relatively prime with it in this case 2 is the answer because there are 2 numbers this is called the totion or Euler's totion we write it as this Euler's totion function counts the number of numbers less than 4 which are relatively prime with 4 the answer is 2 in this case there are 2 numbers less than 4 which are relatively prime with 4 that's the definition of Euler's totion function try it with some others what's the totion of 9 find the totion of 9 that is for numbers 1 up until 8 check whether they are relatively prime with 9 if they are, count how many are let's do it the long way so the numbers 1 up until 9 so 1, I'll list them is 1 relatively prime with 9 greatest common divisor of 1 and 9 yes is 2 relatively prime with 9 yes 3 and 9 no, they have a divisor of 3 4 and 9 5 and 9 6 and 9 they have a divisor of 3 7 and 9 8 and 9 what's the answer? 6 there are 6 numbers less than 9 which are relatively prime with 9 the totion of 7 1 and 7 yes 2 and 7 3 and 7 4 and 7 5 and 7 relatively prime with 7 why? 7 is prime that is the only divisors of 7 are 1 in itself so the greatest common divisor of some number and 7 when that number is less than 7 will always be 1 so when we have a prime number it's quite easy to calculate here it's actually the number minus 1 because it's the number is less than 7 6 in this case the totion of 13 is 12 13 is prime therefore the numbers 1 up until 12 12 numbers are relatively prime with 13 the totion of a prime p is quite simply p minus 1 so if the number is prime then it's easy if it's not prime, if it's composite then we need some way to calculate the totion then it turns out when we have a very large number a very large composite number not prime calculating the totion of that is very hard it takes a lot of time so very large number the totion is very hard to calculate we're not finished yet last one on the totion totion of 5 totion of 35 is 35 prime it's 7 times 5 okay, why do I do that because I know that actually the totion of 2 prime numbers multiplied together is the same as the totion of those primes multiplied together and we know the totion of 7 is 6 and the totion of 5 is 4 so the answer is 24 calculating the totion of a large number is very hard, it takes a long time except under certain conditions if we have a large number and if we can break it into its prime factors we broke 35 into 7 and 5 the prime factors of 35 then a property of the totion is that the totion of 2 primes multiplied together is the same as the totion of each prime and then multiply of a prime is just that prime minus 1 this is easy to calculate we didn't have to go through 1 to 34 and that concept is used again in cryptography one way if you know the factors calculating the totion is easy if we know 7 and 5 it's easy to find 24 but if we don't know the prime factors of this number it is hard and in fact that's a key part of RSA public key cryptography we will stop there we will see some other properties on arithmetic modular arithmetic next week have a look at your assignment some encryption that you need to do with some software over the next week and ask me any questions on Tuesday