So in summary, we have a public key encryption algorithm. Remember public key encryption. Encrypt with one key, decrypt with another. So we don't have a shared secret. We have one secret key and one public key. And there are different algorithms to do public key encryption. RSA is one of them. The encryption is easy. The encryption is conceptually easy. Take your message, raise it to the power of some number e, mod by n and you get your ciphertext. Where m is an integer, less than n. So that's the condition there so far. So you treat your message as an integer. So you need to somehow map it to a number. And m must be less than n. Decryption is that we take the ciphertext, raise it to some power d and mod by the same n. And we need to get the same m back as we started with the input. The key generation steps are such that there's two reasons. One is we must choose the keys which really are the values of e, n and d. We must choose them such that we do get the same m back. It's no good if we encrypt, decrypt and get the wrong plaintext. So the key generation steps are chosen such that we will get the same m back. No matter what the value of the original plaintext. And the other reason they're chosen is so that attacks will be not possible in practice. So that's why the key generation steps are these three steps. So what we got to yesterday is we're trying to explain why we'll always get the same m back. So this was from yesterday, from Tuesday. If we start with some, these are the two equations for encryption and decryption. If we look at the decryption equation, when someone decrypts some ciphertext, the m that they get must be the same as the original plaintext. So what I've done is said, okay, if we take c, our ciphertext, raise to the power of d mod n, the answer will be some m prime. We need this m prime to be the same as the original m where c was obtained by taking the original m and raising to the power of e mod by n. So I substitute c with this part of the equation and we put m to the power of e mod n inside the brackets, raise to the power of d mod n and then we solve for this side as much as we can. And one of the characteristics of modular arithmetic with multiplication and therefore exponentiation is we can, and you can check, you can do the full expansion into multiplication. m to the power of e mod n all to the power of d is the same as m to the power of e to the power of d mod n and same with your normal arithmetic, m to the power of e to the power of d is m to the power of e times d. So that was the step I did from here to here. m to the power of e d mod n mod n, same. And as you should know with mod, when you mod a number and then you mod this, that answer with the same modulus, you'll get the original number back. So some number mod n mod n is the same as that number mod n once. Modding again doesn't change the value. 23 mod 10 is 13 or that's a bad example. 13 mod 10 is 3, mod 10 again we get 3, mod 10 again we get 3 and so on. So modding multiple times is the same as modding once. So that's why we effectively cancel out this mod n, we remove it. So what we get, the decrypted plaintext m prime will equal the original plaintext m raised to the power of e d mod n. What we need is values of e, d and n such that m equals m prime because our requirement is that the received plaintext m prime must be the same as the original plaintext m. So then we ask ourselves, what values of e, d and n can we choose such that m prime will always be the same as m? And that's when we take advantage of Fermat's theorem, is that right? Where we said Euler's theorem, correct. Euler's theorem, back in the number theory lecture notes said one form said, looking here, some integer to the power of some, actually this one. Euler's theorem says some integer a to the power of the totion of n plus 1 mod n is always equal to a. That's Euler's theorem. That's given, we know that. So if we have some integer, raised to the power of the totion of the modulus and plus 1, we'll get that integer back as the answer. We use that to satisfy the conditions for our RSA decryption because we see the RSA or this equation here has a similar structure. We want m prime and m to be the same. So the question is what values of e, d and n such that they will always be the same? Well, if we can write this equation, I'll just replace m prime with a, m with a and compare these two. We know this one's true. We've got an equation in this form. So that means if we set e, d to the totion of n plus 1 we get our equation in the form of Euler's theorem. In other words, if e, d equals the totion of n plus 1 then this equation would be m prime equals m to the totion of n plus 1 mod n which is in the format of Euler's theorem which tells us m will always be equal to m prime which is what we require. So this is leading us to the conditions for choosing the keys, the key generation steps. So the current state is we say e times d must equal the totion of n plus 1. The other way to think of that, if we take e, d and divide by the totion of n the remainder should be 1 because if we divide both sides by the totion of n this one will give us 1, this will give us e to the d divided by n or we think of it as a modulus. Let's consider that and continue with our equation. We rushed that last week. Why is this true? e times d, let's have an example just to the right. Let's say we have 21, if 21 equals 20 plus 1 we can think of that as 21 mod 20 equals 1. Mod 20, remember we effectively divide and what's the remainder? If we have 20 plus 1, if we mod this by 20 the remainder will always be this plus part. So if 20 plus 1 mod by 20 the remainder would be 1. So that's the concept we're using there. e to the d, no e times d equals the totion of n plus 1 so if we mod this by the totion of n the remainder will always be 1. So we can write it e times d mod the totion of n equals 1. So that's the condition so far for key generation. The next step is choose an e, d and n such that that is true. Choose e, d and n such that this equation is always true. Well to find an answer this says e and d are multiplicative inverses when you times them together and you get 1 as the answer.  The same concept. When does a number have a multiplicative inverse coming back to our number theory a number has a multiplicative inverse when that number is relatively prime with the totion of n. So we need to choose some number say e which will have a multiplicative inverse d and the conditions is choose an e. So let's say we choose any e. Not all values have a multiplicative inverse in the totion of n. The values that we know do are those that are relatively prime with the totion of n. So choose an e such that I will note here at rp relatively prime e and the totion of n are relatively prime. In other words the greatest common divisor of these two values is 1 equals 1. If we want to be able to find a multiplicative inverse we need to choose an e which is relatively prime with the totion of n or has a greatest common divisor with the totion of n of 1. And there are multiple values there. And if we can choose an e which meets that requirement then we can find a d and then we have values that make sure that RSA decryption will always work. Once we can choose an e we can calculate a d. There are algorithms to do that reasonably efficiently. To calculate the multiplicative inverse there are algorithms that would do it for us when we have large numbers. What we've done is shown for RSA to work we must choose an e which is relatively prime with the totion of n or the greatest common divisor of e and the totion of n equals 1. If you go back to your lecture notes that's what we did this step too. We chose an e where the greatest common divisor of the totion of n and e is 1. So that's why we did this step to make sure that the decryption will always work. We can calculate d, that's step 3 and therefore RSA always is successful if we choose our numbers according to this key generation steps. The first step, why did we choose two primes finding the totion of n for a large n is hard unless n is the multiplication of two primes that we know of. That's why we chose the first step. So calculating the totion of n for an arbitrary n we can not always do. We can only do it quickly if n is the multiplication of two primes that we know and that leads us to the first step. So, should be able to prove RSA in the exam in next year. Prove that RSA works is something you should be able to do in an exam. Let's attack RSA which you should be able to do in an exam as well or let's look at the avenues for attack. What can an attacker do to A, try and find the plaintext and B, try and find the private key and then we'll look at why is RSA secure? Let's have a look what we require for RSA. What we just went through is the first one. We said for RSA to be able to decrypt we must be able to find values of E, D and N really the key values such that m to the power of E, D, mod n is equal to m for all m less than n. And that's true when we choose them according to that key generation step. The other requirement is that the normal user when they encrypt something it should be easy to calculate m to the power of E, mod n. And when they decrypt something it should be easy to decrypt. When I say easy it means it needs to be fast to do it with computer when we use large numbers. So that's the requirement to make it practical. If it takes 10 years to encrypt a file with RSA then it's not very practical. So we need it in the order of milliseconds, for example. So it should be practical to use that step two. Step one is saying it always decrypts successfully. Step three is saying that the attacker should not be able to find the secret values. Should not be able to find D given E and N. Let's see what the attacker can try and do. Has everyone got the lecture notes in the copy centre? I put them in on Tuesday after someone reminded me in the lecture. They're still not there? Okay, so you've got blank paper. Yes, so someone reminded me there's the new batch of lecture notes which cover these topics are in the... Well, I put them in the copy centre on Tuesday. Choose the afternoon after the lecture. Has anyone checked today? Yes, they're online as well. But the new handout should be in the copy centre. Yes, bound. As the instructions I gave them, it should be bound but maybe it's taking a long time to copy. Sorry about that. You have to survive for today at least. Let's attack RSA. Let's find our example. We had an example. A simple example we went through on Tuesday. We said that to generate the key we choose two prime numbers, P and Q. I chose 17 and 11. Okay, the small numbers so I can calculate. I calculated N, just multiply the values together. I get 187. And then I calculate the totion of N and I use this property that the totion of some number which is where we know the two prime factors. We know the prime factors of N. They are 17 and 11. Then the totion of that number is the totion of those two prime numbers multiplied together. So we can simply calculate the totion of N to be 160. Totion of 17 times the totion of 11. 16 times 10. So this is what I do to generate my keys. I selected some E, some integer which is relatively prime with 160. I chose 7. There are multiple answers I could have chose. I could have chose 3, 7, 9, 11. I chose 7. Okay, so you need to choose one. We'll talk about which one's appropriate later. Once I choose E then I calculate D such that E times D mod 160 equals 1. And we go through and you find quite quickly that 7 times 23 is 161. 161 mod 160 is 1. It gives us our key pair. The public key of B, some user B who generated this key. We think of E is 7, N is 187. And the private key of B, D is 23, N is 187. The same value as the public value. So in fact the private value is D. By private we must not tell anyone what the value of D is. E and N we tell everyone. It's public but D must be kept secret. Turns out also P and Q should be kept secret. Don't tell anyone P and Q. So we'll look at what the attacker can do. One last step we did. We encrypted something last lecture. We took some message, 88. We used the encryption algorithm, 88 to the power of E mod 187 using the calculator 11. And then we sent the ciphertext 11 to B and B decrypted 11 to the power of the secret value D mod 187 and with our calculator we found it was correctly 88 original M. Let's attack and see what the attacker can try. First we'll try if they have the ciphertext only. So A sent a message to B and the attacker intercepted. But what was the message? Well it was C equals 11 in our case. The attacker intercepts. What can they do? Well we look at what the attacker knows. The values that they know. The known information to the attacker. The algorithm is known. That's common. We assume the attacker knows what algorithm is used. RSA. So they know all the steps of the algorithm. What else do they know? They know C equals 11. They've just intercepted the ciphertext. What other information does the attacker know at the start? Any other values? E and N. So they effectively, well they know the public key. By definition it's public. The attacker can know it. The public key of B which was E equal to 7 and N 187. So that's known to the attacker. This public key is known. They don't know the private key. In particular they don't know D. Currently they don't know M. How do they find M? Find the message. Try and find M given those values in the algorithm. Well remember we know the algorithm. So M. What does B do to get M? B takes C to the power of D mod N. That's what B does. So the attacker knows these values. The equation for decrypting is you take the ciphertext raised to the power of D mod N and you get M. That's no good for the attacker. Not yet at least. Because look at the values that they know. There are too many unknowns. They know N. That's good. They know C. They want to find M. They're missing D. You cannot solve that equation. If there are two unknowns and four variables you cannot solve it without other information. So what can the attacker do now? They want to find M. To find M they'll need these three variables. They know C and N. C is 11. N is 187. Therefore they need to find D. If the attacker can find D they'll easy to find the message. They'll make 11 to the power of whatever value D is. Mod by 187 and they'll get the message. So the challenge now for the attacker is to find D. But let's make it a little bit easier for the attacker. We'll come back to we'll see some approaches to find D in a moment or how they can do it. Let's go through them now and then we'll make it easier. What about brute force? Brute force is if to find D try all possible values. So, remember the message in practice would have some meaning. So a brute force could be take your ciphertext, raise to the power of 1, mod N.  If not raise to the power of 2, 3, 4, 5 and keep going until we get a message that has some meaning. So a brute force try all possible values of D. So that's the brute force in this case. How do we stop a brute force? Make D large. Make it large enough even if you have to try all possible values it would take forever to do so. So that will be one requirement that D should be large. We know normally 100 bits or more if it's 100 bits long it should be long enough because it will require 2 to the power of 100 operations which would take too long to calculate. So brute force will not help if we make D large enough but let's make it easier for the attacker. Let's say they have obtained a message from prior communications and the corresponding ciphertext. So let's give them some more information to give you a value. Okay? Let's go through. I was going to make it easier but let's go for the full way. Alright? How do we find D? Well, you're right that in the key generation step the attacker knows these steps. They know that the user created their key this way. So they want to find D. Well, how do they find D? They know that D times E mod the totion of N equals 1. Let's write that down. The other thing that we know is that E times D mod the totion of N is 1. And we know E is 7. So we know that 7 times D mod the totion of N and we know N is 187 equals 1. So this is known to the attacker. So now from the attacker's perspective if they can find D here they will break RSA. What do you need to do as the attacker now? What's your next step? No brute force. Let's be smarter. Correct but go slower. From this equation what do we do now? What's the totion of 187? Because I gave the answer last lecture. Let's look at the steps that we need to take. We need to know the totion of 187. How do we do that? Let's say I ask you to do it manually. You take 1, is it relatively prime with 187? 2, 3? That's like a brute force attack. Try all possible values of 1 up until N-1. But you know there's a faster way. How do you quickly find the totion of 187? Find the primes. That is factor 187 into its primes. So that will quickly find us the answer. What are the primes? The prime factors of 187. So you know because we went through the answer last week because that's what we did with generating the key. But the attacker's challenge is given N, remember this is N to find the totion of N we've got two approaches. One is to factor it into its primes. Once we factor it into its primes then we can quickly calculate the totion of N because it's just the prime 1 minus 1 times prime 2 minus 1, p minus 1 times q minus 1 in our setup. What's the other approach? Really brute force of simply for all values of N have an algorithm to find let's say how can we describe it? The totion of N is generally check whether the numbers are relatively prime 1 and 187 2 and 187 relatively prime between 2 and 187 3 and 187 up to 186 and 187 187 So two ways to find the totion of some number. One is the slow way take every number up until that number one less and check if it's relatively prime with that. 1 and 187 are they relatively prime? 2 and 187 3 and 187 up to 186 and 187 count them and you have the totion. The other way which is a little bit easier is to factor that number N into its primes and then we can immediately calculate the totion of N. Okay in the exam I could say here's 187 find the answer, find the totion you can. The problem is we can't do either if N is large enough if N is very big factoring N into its primes is considered a problem that's too hard to solve it takes too long and the other way of trying 1 up to N minus 1 again is if N is very big there's no known algorithm that can do that in reasonable time. So although we can do it with 187 if we chose bigger values instead of 187 a 4000 bit value factoring or doing the direct solving of the totion is impossible. Let's see the lecture notes that describe that and this was also mentioned in one of the last slides in the number theory lecture notes you'll see in the last slide there there's something about the computational complexity there are three problems we listed which are hard that is take too long if we have large numbers factor N into its two prime factors that was one we just saw and determined the totion of N directly so the brute force on the totion of N that's the attacks and I'll go back to the number theory let's find it we've said that integer factorization take N break it into p times q is too hard to solve if N is large enough I'll give you some more statistics later but we mentioned that N which was about 230 digits long took 2000 years to solve of computer power was done in parallel nowadays N is typically 2000 bits 4000 bits long solving Euler's totion given some N without factoring N to into its primes is also considered hard in fact harder than factorization so if it took you 1000 years to do the factorization it would take you longer to do the totion solving directly so no use trying that and this is where the security of RSA comes in if we choose large enough numbers we can't solve these problems with 187 it's easy but choose a 4000 bit number for N factoring it can't be done in reasonable time calculating the totion by looking at the numbers relatively prime with N can't be done with reasonable time so we can't do that as long as we have large numbers so any other ways to find D if we can't do that so if we can't find the totion of N then we don't know what we mod by and therefore so this is an unknown and D is an unknown and we cannot solve that equation we've got two unknowns so if we can't find the totion of N we can't find D if we can't find D we cannot decrypt and RSA so far is secure any other attacks you can try how else in the exam are you going to break RSA how are you going to try and break it let's give you and now let's make it easier for you that is the attacker and give you some more information we said in this case the attacker knew the ciphertext and the public key their aim to find M the original message and to find M you need to find D so in fact if you find the private key you can find M easily so the aim really is to find D and we said that if we try to do it by getting the totion of N we cannot do that but let's give the attacker more information let's give them a known pair of ciphertext and plaintext let me give you a value so what does the attacker know from before we knew some ciphertext 11 we knew E was 7 N was 187 and let's say we've somehow captured a message of plaintext M and the corresponding ciphertext which was created using the same keys we've captured as the attacker M1 equals some other value 17 and the corresponding ciphertext when we encrypt M1 using the same key is 85 a known pair of plaintext ciphertext for the attacker again the challenge find D if you can find D you can find M how do you find D so this is easier for the attacker because we also give them a known plaintext ciphertext pair that is M1 17 was encrypted using the key and we got the plaintext 85 so we know a value of M well let's look at our equations and see what we can do we know that we want to find D we know that M equals C to the power of D mod N so what does the attacker know in this equation they know the M they know C they know N they don't know D we're trying to find D we have an equation here four variables three known one unknown easy to solve how do we solve that so you have an equation four variables three of them are known one is unknown you should be able to solve the equation write what do you do to solve the equation that is find D if you know MCNN in terms of what operation do you need to do to get D log we know C to the power of something mod N equals something what's the inverse we want to find the exponent and that's what a logarithm does a logarithm gives us the exponent in this case and we call it a discrete log when we have a modulus going back to the way to write it the discrete log of in base C with mod N of M equals D I'll write D at the front so I know C as the attacker I know M I know M we have those values above we have M is 17 C is 85 we know those three variables so all we do is solve the discrete logarithm and that's another hard problem if the values are large enough yes, yes there is we'll talk about some typical values but yes we can roughly know the size of D it's about the size of N so it's about maybe 2,000 bits long so yes we can know approximately the size of D and maybe even exactly the size but we don't know the value if it's 2,000 bits long you've got 2 to the power of 2,000 possible values so brute forcing D trying all possible values of D won't help here so we need to solve the discrete logarithm coming back to our number theory our last slide we said another problem which is hard is solving discrete logarithms so solving a discrete log takes longer or comparable time to integer factorisation so if it takes you 2 million years to factor the integers it's going to take about 2 million years to solve the discrete log and a bit longer to solve Euler's Totion so therefore we can't break RSA as long as we have the numbers large enough and that are the main attacks or the avenues for attacks and that leads to the reason why RSA is secure in general because even though mathematically we can find Euler's Totion factor numbers, discrete logarithms in practice we can't do it in reasonable time so RSA's security depends upon these mathematical problems that is no one knows any algorithm to solve the mathematical problems for breaking RSA if you can come up with an algorithm for factoring some large number into its primes you'll rule the world that is you can break into banks steal money do what you like but no one at this stage there's no known algorithm for doing so any questions so far on RSA so we've saw three avenues one is to break, let's go back one was the two different approaches to solving the Totion the brute force approach takes too long factor the N into its primes and then the Totion is easy but factoring into primes takes too long so those two won't work if N is large enough and then the third one was in fact we can easily know that RSA and plaintext solve a discrete logarithm again if our numbers are large enough too long so RSA is considered secure what have we got next of these three problems integer factorization solving oil as Totion discrete logarithms it's generally considered that the easiest of the three is integer factorization that it's if you're going to do an attack on RSA try and factor N into its primes because that will be the fastest of the three approaches but still if N is large enough faster still means impossible so the measurement of the security of RSA is usually measured in terms of how long it takes to factor some number into its primes let's go back to the RSA lecture notes here's some values that reported and getting old so there was a competition people have tried in the past given some large N factor into its two primes and in 1991 the largest value that was done was around 100 digits 330 bits 330 bits are about 100 decimal digits but then people come up with better algorithms and with faster computers in 2009 someone reported that they could factor a 232 digit number into its primes it took 2,000 years on a single core computer at that stage so of course they had many computers but equivalent to using one computer for 2,000 years and they could factor this number into its primes and that's with N so this is in fact the length of N in RSA 768 bits at that stage of course computers got faster about every two years they get double the speed the recommended values for N in RSA the typical values are 1,024 2048 4096 bits of N and recommended today is usually 2048 or 4096 most new applications would be 2048 bits so 768 bits took a lot of effort even though it's five years ago increasing the bits one extra bit effectively doubles the effort remember so from 768 up to 1,000 is another 250 bits so the amount of effort is 2 to the power of 250 times larger so still considered impossible so the attacks on RSA one is brute force D try all possible values of D how do you stop a brute force? make D large enough if D is larger than hundreds of bits then brute force is not possible and in fact the way to use RSA is make sure D is large enough of course the larger D is the slower the implementation is and we'll see some results on that shortly so brute force is not considered possible and then the mathematical attacks that we looked at factor N into its primes determine the totion directly without factoring or calculate the discrete log to determine D all considered impossible with large enough values there are some other attacks which are very specific attacks in certain circumstances timing attacks in particular operations turns out some of them are possible but there are counter measures that are not too hard to implement that make it secure against such attacks maybe at some performance penalty slows down the encryption but still makes it secure anyone who survived through RSA today and is still interested tomorrow lunchtime midday I'll give a presentation about one of the latest timing attacks so if you want to come let me know and I'll let you know the room at the end of the lecture today what have we missed we've gone through RSA how long does it take to encrypt with RSA everyone's done their homework most people have been doing I've seen about half of the submissions that's encrypt with RSA let's use our speed test you've used openSSL to do some encryption with different symmetric block ciphers it also supports RSA I have to remember that I'm sure everyone had similar problems with max and speed correct so my computer is doing some RSA encryptions don't worry too much about the private RSA and so on we'll give the summary results at the end it takes a bit of time it tries different lengths of keys a 512 bit think of the value of n now it's doing 1024 bits it does it slightly different from block ciphers and symmetric ciphers we'll see later that they are used differently than symmetric ciphers like AES but once we get to the end summary statistics now it's trying 2048 bits the longer the length of n the longer it takes to encrypt but it does 10 seconds for each I hope it just does 2048 and stops let's do 4096 another 20 seconds we'll get there everyone's done this in the homework but using different algorithms and you get different output with your algorithms you can print some output of what version of open SSL it used and then it gives a summary down the bottom for different length keys or different lengths of n from 512 up to 4096 bits we'll come back to why sign and verify but let's try and look at the fastest with 1000 start with the easy one 512 bits the fastest value the number of think of the number of encryptions per second 189,000 or about 190,000 encryptions per second you can do that that's in fact using the public key E so this operation is using some value raised to the power of E mod n the other one's sign is using D the private key which is much slower anyone want to guess why some number to the some random number to the power of E mod n sign is using some random number to the power of D mod n power of D mod n is much, much slower 15,000 versus 190,000 10 times slower anyone want to guess why so you remember you don't have them in front of you M to the power of E mod n results here and we're not going to explain why but this is the verify column and the other operation M equals C to the power of D mod n same N is the sign operation and what OpenSSL does is tries random values and tries to encrypt them we see sign is about 10 times slower less than, more than 10 times slower than the verify same mathematical operations number raised to the power of E mod n the difference in practice is that E is usually small small value and D is big large and as you may expect taking some number and raising it to a small value is faster than taking a number and raising it to a large value so signing uses the D value the private value 15,000 decryptions per second anyone remember their results of using AES, triple desks, camellia blowfish from your homework some people decrypted I think you probably get around and it's measured differently about 100 up to several hundred million megabytes per second 100 megabytes per second 100 million bytes per second it's hard to compare directly but 100 million 128 million bytes per second if your block is 128 bits gives us 8 million encryptions per second so with AES and those similar ciphers we're getting millions of encryptions per second with RSA we're getting about 15,000 per second in the worst case here so it's much much slower than a symmetric block cipher like maybe a thousand times slower so that's a problem with RSA it's very slow you increase your value of N but in 12 bits up to the much much more secure 4096 bits fine 86 encryptions per second from 15,000 down to 86 so very very slow with a larger value so this is the tradeoff increasing security by having a larger N decreases performance so you need to choose an appropriate tradeoff so you don't just choose but just key possible you make a consideration of also the performance now we will not go into details here but it turns out RSA is slow in terms of implementation people have made some optimizations that try and speed up the implementation and in fact OpenSSL uses some optimizations and the common optimization is instead of taking C and raising it to power of D you do an exponentiation with a large D that's very slow what they do is that they create two intermediate values instead of getting D they find there's Dp and Dq and they do a module I expect exponentiation with the two smaller values C to the power of Dp and then C to the power of Dq and it turns out it's not so much interest today but it turns out that it's much faster about four times faster instead of doing one number raised to a very very large number you do that number raised to a number half of that size twice so instead of raising to D you raise to a number of about half the length of D and then do it again it's about four times faster so there are ways to improve the implementation same calculations, same results at the end though same security level and it means that normally to improve the speed you don't just store N, E and D you store some intermediate values you store N, E and D you store P and Q and also some other intermediate values are often stored sorry, this is from the person who generates their key this is the step this is not from the attack this is going back where are we normally we generate when I generate my keys I get we've said E and N are my public key D and N are my private keys so I really need three values to store and use for later E, D and N but to speed up the implementation the algorithm uses some intermediate values and in fact when you generate your own key you have N, E and D but you also store the initial primes so when I generate my key I know P and Q because I chose them I store them and I know these intermediate values because I calculated them so in practice when you have your own key pair there are two public values N and E, you can tell anyone your values of N and E and the private values which are usually stored on your computer for yourself and must be kept secure of course the N and E which are made public but also D, P, Q and these intermediate values and they use just to speed up the implementation to make it faster when you generate your own key and you do it in another homework after the midterm you generate your key and you'll see these values so you can generate your key and see the actual values I'll see if I can find an example I've got an example key that I'll show to see those values and I've generated a key from a previous time so this is I use OpenSSL to generate my own key pair and I made that the public information available to others so this is my private key information and we can look at the values P key input is my key and let's output into text this is my private key and it's encoded there not encrypted encoded but later it shows me the actual values my modulus N 2048 bits of course it's not shown in binary it's shown in hexadecimal here but you can count the digits 2048 bits that's N E we say the public exponent it's the exponent and it's one made public that's E here's the decimal value 65,537 and that's very common most implementations of RSA will use the same value of E and it's public so it doesn't matter if everyone in the world has the same value and it turns out that this value is good for implementation purposes it's considered secure and also fast other values the larger it gets the poorer the performance so E is usually known or fixed then the private exponent which is my D my value of D is the same length of N there's my D you need to guess that value if you don't know it and then the following values are also private to me remember with the key generation we choose two primes prime 1 and prime 2 OpenSSL chose them for me and these are the prime numbers they're about a thousand bits long so one thousand the prime multiplied by another gives us our 2048 bit value of N so a thousand and twenty four bits a thousand and twenty four bits for the two primes again these must be kept private the primes must be kept private secret and then the exponent 1 and the other values exponent 2R and the coefficient they are these intermediate values which are used to speed up the implementation so that's where in a private key we store all these values I don't show anyone my values the values of N and E I put in another file and make them available to everyone on a website and an email or however and then you can use my public key some final points about the performance of RSA how fast it is to implement again, generally it's very slow so there are some optimizations to try and speed it up we've seen a couple we're using modular arithmetic so in fact we take one number, raise it to the power of some other large number that can be very slow so there are some properties of modular arithmetic that can speed that up choosing E typically you choose a fixed value so there are some popular values nowadays 65,537 is the default in most cases doesn't make it any less secure but it makes the performance faster usually if it's too small E there are some special attacks but you can usually overcome them by adding some counter measures so nothing practical choosing D of course it cannot be too small the larger D is the slower the encryption using D is but there are some algorithms to make it reasonable using even a large D so there are some algorithms that speed up the implementation the Chinese remainder theorem and Fermat's theorem can help with the implementation choosing P and Q choose two large prime numbers is not easy even for a computer so what they usually do is you choose two large random numbers a thousand bits long and apply some tests to see if they are in fact prime and the tests may not be 100% they may even give some probability of confidence that they are indeed primes finding large primes is a slow task so usually they choose large numbers and then test if it is prime so the generation of P and Q may take a little bit of time when you generate your keys with OpenSSL you can actually see it takes in some cases maybe a second or so to generate them and that brings us to the end of RSA it's a very important algorithm it's the main public key algorithm used and it's still used widely even though there are some special attacks it's still considered secure in the general case so it's important to know how it works when we come towards the end of the course we'll see when you connect to a website and using HTTPS you often see that secure icon in your browser to show you've got a secure connection one part of that is you get a certificate from the web server trying to confirm this is in fact the right web server it's not something pretending to be that web server those certificates make use of RSA commonly so we'll see them come up in practice later let's stop there for today we still have one remaining lecture before the midterm Thursday so you're going to have a long new year break but come back Thursday and Thursday there are a few slides I skipped over before here we will not go on any further so we'll stop there but there are a few slides that we need to recover that we skipped over we'll go back to them and then maybe have some examples and talk about the exam on the lecture on Thursday


This is the story of the Pacific and its people. Of the peaceful sea and the lands and lives it touches, and their meaning to us and to the generations to come. The Pacific Story, presented by the National Broadcasting Company as a public service, and dedicated to a fuller understanding of the vast Pacific Basin. This broadcast series comes to you as another feature of the NBC Inter-American University of the Air, with drama of the past and present, and commentary by Owen Lattermore, authority on the Pacific, and director of the School of International Relations, Johns Hopkins University. World War I in the Pacific. World War I gave Japan its great opportunity. While Britain and France were engaged with Germany and Europe, Japan seized the opportunity to expand its empire. For nearly a month after the assassination at Salahevo, Tokyo and London debated the terms on which Japan should join the allies. Then, late in August 1914, Japanese forces landed 100 miles north of Singdao in Shandong Province, China, in a move to occupy this Germany's territory. Although China has declared its neutrality, the Japanese are taking a reason far more extensive than the German lethal. Japanese troops are swinging around to the rear of Singdao, and Japanese Admiral Kato Tomasaburo is weaving up mines and maintaining a tight blockade of the fortified harbor of Singdao. With overpowering might, the Japanese broke through the defenses of the stronghold, and in November, after two months of campaigning, triumphantly paraded into the city of Singdao. Quite a surreal Japanese amazement of this, Admiral Tomasaburo. It is a great victory for the allies. I don't know about the allies, Admiral. We have driven the Germans out of Singdao and saved you, British, from coming out here to the Far East to do it. We have to celebrate. Yeah. It is the first stroke for the allies in the Pacific. For the allies? Yes. Japan sent an ultimatum to Germany, you know, to turn over this lethal in Shandong with view of its eventual restoration to China. And the Germany ignored it. Does the Japan plan to restore Shandong to China? We are at war now, as you, Britishers, should know. Germany was negotiating with China to restore Shandong to China. Germany was willing to evacuate Shandong, give it back to China, when Japan attacked. Japan came into the war in compliance with our treaty with you. We have done, Briton, a great service. Didn't London urge Tokyo not to offer to generous a hand in the Pacific? Japan acted to fulfill her obligations. So Japan came into the war on her own terms. Our count Okuma clarified our position in his cable to the United States. You mean about Japan having no territorial ambition and hoping to stand as protector of peace in the Orient? That is our policy. Here, you see, look at this. This contingent of your colonials carrying the British corolles, marching in with our troops, that symbolizes the alliance of Japan and the Allies. Yes, Admiral Thomas de Bureau. We'll probably remember this triumphal march into Fingdao for a long time. It is an important day. This day will remind us that Japan came into the war in spite of Britain, rather than because of us. Based in the harbor of Fingdao, with the strong German squadrons on device admirals on speed. The Japanese made no effort to watch it during the tenth month of July 1914, when she under the Anglo-Japanese Treaty was on a verge of coming into the war as an ally of Britain. Weeks before the Japanese clamped their blockade on Fingdao, the German squadrons slipped out and disappeared in the broad Pacific. The Japanese had permitted speed squadrons to slip through their fingers. The Japanese are not interested in German ships. While speed was escaping, the Japanese were moving in on Fingdao and the Germans south the island. You realize what this means? We had been better off as Japan had not come into the war at all. It means that speed squadron is now free to raid our ships all over the Pacific. Vice-admove on speed-strong German squadron has been joined by two light cruisers and is now harvesting our lines of communication. Speed squadron has moved down on another allied outpost in the Pacific to cut cables and smash shore installations. Squadron has captured two more allied merchantmen. Squadron has destroyed the squadron of the admiral's clinic at Coronel off the coast of Chile. There is only one cause open to us, gentlemen. We must find and destroy speed squadrons. We can count on no help from the Japanese, sir. As our allies, they should help in the hunt. So far, they have been indifferent to all our efforts to run down speed squadrons. Japan is making little more than gestures, sir. Japan has sent some ships. Oh, they might as well have sent wind jammers. He's right, sir. They've sent some old hoaxes and Kamamura squadron and a captured Russian battleship that was torpedoed at Port Arthur. He's keeping our feet close to home waters, sir. If we must do it alone, gentlemen, we must still do it. Speed has detached the Emden, which is now raiding alone throughout the South Atlantic and deep into the Indian Ocean. Between the Emden and the rest of speed squadron, the Pacific stands in dread of the Germans. They will detach three battle cruisers from the European war zone and send them to run down speed. But, sir, whereas he's sorely in need of every kind of speed, he must be destroyed. Order the following battle cruisers to proceed at once to the South Pacific. Oh, yes, sir. They'll buy the file, but he's still trying to look. He'll never get out. He's here in the paper. I caught up with him down by the Falklands, eh? Yes. Down in the South Atlantic off Argentina. Were there any Japanese battle wagons in on the keel? Not within 10,000 miles, there wasn't. What is it he gets at doing in this blasted war? We asked him to send an expeditionary force to France, and the crisis too far. They ain't got the transportation facilities. They let speed give them the slip, and when we asked him to hunt with us, why the... Oh, I asked, sir, what kind of a war is it these Japanese are fighting? Japan firmly incensed herself in Singdao, in Shantung province, around it, and in the Mariana, the Carolin, and the Marshall Island. Then she began to waver in her allegiance to the Allies. Japan seized the opportunity in 1916 to extract from Britain, France, and Italy a promise to support her claims at the peace table to Shantung and the island. Secret treaties were entered into between all. When the United States met at World War I in 1917, the United States was the only Allied nation that had not agreed to Japanese hegemony in Asia. The Japanese were soon to create a crisis on this store. To consult on joint efforts in the prosecution of World War I, America's allies sent missions to the United States in 1917. From Japan came Viscount Ishii. All interests in Asia, Mr. Secretary, might be called a Japanese Monroe Doctrine. I see. Your worthy predecessor, William Gening Bryant himself, met two years ago in the 1915 that Japan had a special interest in China. The purpose of your visit, Viscount Ishii, is to discuss our joint efforts in the war, is it not? By all means, Mr. Secretary, and also an understanding on problems in which we are mutually interested in the Far East. We wish only to clarify our understanding. Mr. Bryant meant in speaking of your special interest in China that there were particular conditions rising from your nearness to China. Japan is sure that America sees eye to eye with us. Germany is our common enemy. Of course, of course. Then would it not be best in order to end the rumors of differences between America and Japan that we show our singleness of policy and interest by exchanging notes? The United States is most eager to do that. Since Mr. Bryant declared that Japan had special interest in China, might it not be helpful both to the United States and Japan to clarify our understanding by setting this forth in these of notes? Mr. Bryant's meaning, Viscount Ishii, was perhaps less definite than the words imply. He meant it merely as a pleasantry. The United States is a great nation, Mr. Secretary. I have seen your battle-feet in Long Island sound. I have seen your preparations to maintain an ever-increasing army in France. You are strong because you understand other nations. We have no other nations staked out for seizure by Count Ishii. You have nothing to fear, nor has Japan. Thus, you see, we have only to gain mutual confidence by clarifying the understanding between us relative to China. But there are other points on which we are in complete agreement. We have no disagreement, Mr. Secretary. Japan wishes only to state in our agreements the policy which was set forth by your William Jennings Bryant Secretary of State Robert Lansing was unwilling or unable to repudiate the words of his predecessor, and the Lansing Ishii agreement was signed in 1917. Before the ink was dry and prior to the date the agreement was to be announced, the Japanese informed the Chinese, the United States has admitted that Japan has special interest in China. This amount to an abandonment of the American policy over friendship for China. China was stunned, and Japan was quick to take advantage of the situation. While the Allies sought the help of the remaining neutral nations against Germany, Japanese agents went to China, and working with Germans there sought to keep China out of the war. But China won her way into the Allied camp. At the Beside Peace Conference at the close of the war, the Lansing Ishii agreement clearly states that the United States recognizes that Japan has special interest in China. It must not be some school, Baron Montino, to mean that the United States accepts the Lansing Ishii notes as a commitment to give Japan permanent accession to the German rights in China, and in the North Pacific. Japan was in possession of Shandong, and the German islands when the Lansing Ishii agreement was signed. A clear confirmation of Japan's rights in these places. Yes, Baron Montino is trying this peace conference in the North. Yeah, for the benefit of Japan. My paper's been buzzing me for a lead on the Shandong question, but with this guy, Montino, putting on an act that the United States is giving Japan a run-around while Japan is actually giving the rest of the nations the run-around. Well, there ought to be a break somewhere along here soon. They can't keep on ranting over this Shandong question forever. They can, as far as China is concerned. That guy, Montino, is not going to break down. Well, I've told my paper they're giving China the works here. Well, I don't know. I'll tell you. Well, he's in cruise at the whole conference on its ear with that plea of his for Shandong as China's sacred province. Well, for my doubt, there's going to be some horse trading here, and China's coming out on the short ends. Japan has got a hook on Shandong and those German islands. Japan had Shandong. Her troops were holding it. Her troops were also holding the Carolin Islands, the Marianas, and the Marshalls. To support her claims at Versailles, she brought out the secret treaties extracted from the allies before the entrance of the United States into the war. The big four of Versailles peace conference have surrendered Shandong to Japan. China is indignant and invited, and the Chinese delegation has been deluded with telegrams not to accept this decision. Well, what did I tell you? They've sold China down the river. They just let that guy, Montino, make a monkey out of him on the Shandong question. Not only Shandong, the League of Nations have mandated the Carolinas, the Marshalls, and the Marianas to Japan. Well, I don't know. But they've only mandated the islands to Japan. They haven't given them to her. Now Japan's got them, and Japan's going to keep them. And that means Japan now has strongholds south of Manila and east of Guam. And you can figure out what that means to the United States for yourself. Two days after the peace conference decided the Shandong question in favor of Japan in April 1919, China flared in protest. On May 3rd, the United States group of Chinese students at the National University of Beijing met to protest the Versailles decision. The Shandong question is the result of corruption and injustice. And we as students must fight to show the world that might should never be right. There can be only one conclusion. A greater world war is coming sooner or later. And this great war will be fought here in the east. But we cannot wait for the next world war. We must drive Japan out of China now. We must drive out the Chinese traders who have sold our Versailles to Japan. We students with no access to grind can carry out protest against the award of Shandong to the British and American ministers in the Legation Quarter. We can march in their bodies. We will march, all of us. Tomorrow, all of us. We must expect opposition. Some of us may die. But we can do no less than the student who bumped his head against a stone pillar that can't seem to show how easily a student can die for his country. We can do no less than the student who have openly defied the bayonet to the Japanese or the willingness of the orphans to be imprisoned in places of students and to die for them if necessary. I pledge that I will march in protest and for death. Mr. Chairman, Mr. Chairman, look. Mr. Sia here has deliberately broken his finger and written in blood on the wall. Return our sing-dow. We need your courage, Sia. I shall march in the vanguard tomorrow. We shall all march in a mass parade to the British and American Legations tomorrow. We will assemble in groups according to our schools and we will have... Next day, May 4th, 10,000 Chinese students march through the streets of Peking, carrying flags, bearing inscriptions. Health determinations. International justice. Down with the payers. Return our sing-dow. The students fired the imagination of the public, marching mile after mile to the Legation Quarter to see the allied ministers. That's where you are. We have come to see the British and American ministers. The guards have been reinforced. Yes. Only a delegation of us wish to enter. If we cannot see the British and American ministers, perhaps we can see Sao Ru Lin. Sao Ru Lin is greater. Yes, just Sao Ru Lin is greater. Yes, just Sao Ru Lin is greater. We can go to Sao Ru Lin's house. Yes, we can go to Sao Ru Lin's house. Off to Sao Ru Lin's... On to Chang'ang Street, the 1,000th march to the home of Sao Ru Lin. The three pro-Japanese-Chinese officials link with the surrender of Shandong to Japan. We wish to see Sao Ru Lin. You cannot see Sao Ru Lin. No one is permitted to enter here. They have thrown extra guards and policemen around the soldiers. Sao Ru Lin to come out. Stand back. Stand back. Continue your march. We wish to speak with Sao Ru Lin. Stand back. Sao Ru Lin has determined not to speak. No, everyone is open. The students are going in after Sao Ru Lin. Yes, let us go in and talk with Mr. Sao. Sao, I'm right with you. Let us force our way through who we have found. Come on. Who is it?  Our Chinese minister to Tokyo equally guilty with Sao Ru Lin in the surrender of Shandong. He is pro-Japanese. Yes, another one of the hated pro-Japanese officials. Who is that? I have been looking for you too, Mr. Chang. Students of other cities joined. Merchants, newspapers, scholars joined. On June 6, the guards were removed from the doors of the prison, and the 32 students were ordered to go home. But before they would depart, they made four demands upon the government. We demand that the three pro-Japanese traitors identified with the surrender of Shandong be dismissed. Certainly, we demand that students be allowed freedom of speech. Thirdly, that we be allowed to parade the streets of Peking, unmolested, and forcibly that the government make a public apology to the students. We demand that these... The students had fired the will and the imagination of China. The people of China had taken up the torch. The three traitors were dismissed. The government of its own accord sent an apology to the students. The police apologized and sent automobiles to the prison doors. And when the students marched triumphantly out... The removal of the three pro-Japanese officials from the Peking government has been reflected at the side. The Chinese delegation not being permitted to sign without reservations as to the Shandong question have refused to sign the peace treaty, unquote. At the close of World War I, the seeds of World War II had already been sown. Even at the start of World War I, China had foreseen the catastrophe to come. Before Japan had seized Shandong and the German islands, President Yuan Shikai said, Japan is going to take advantage of this war to get control of China. These are the facts. And here to tell the meaning behind them is Owen Lattermore, authority on the Pacific and director of the School of International Relations, Johns Hopkins University. Mr. Lattermore. What is the biggest difference between the World War of a quarter of a century ago and the war we are fighting now? In my opinion, the difference is in the importance of Asia. In that other war, nobody in Asia was fighting for any particular cause, good or bad. Japan just hung around the edges of the war like a jackal, hung really snapping up any good bits that came her way. China was hardly in the war at all, though Japanese fought Germans on Chinese soil for Chinese plunder, and later a number of nations used Chinese territory as a base for intervention against Russia. It was only at the end of the war that China awoke, stung to protest by some of the more outrageous decisions of the Versailles Peace Conference. This war that we are fighting now is very different. In order to understand it properly, we Americans need to repeat to ourselves constantly a number of statistical facts and to arouse our imaginations to the vast historic sweep of the events in which we are taking a decisive part. How could anybody else's part in the war be more vivid and real than America's part? American blood paid for the beach head at Salerno, and American courage and skill has carried the attack on inland into Italy. Americans are fighting in the most remote Pacific jungles, and in the air over China and Burma. There are American prisoners behind Jap and German barbed wire. The advance on almost every fighting front is marked by its quota of American graves. Yet with all this, the war is for us only a recent war and it has not cost us a tithe of what it has cost many of our allies. The Dutch have lost every foot of their territory and their possessions. The British have been in the war more than twice as long as we have and the cost to them in blood, sweat, toil and tears has been far greater than our sacrifices. The Russians are casualties in millions while ours are counted only in thousands. Above all, the Chinese are the veterans of this war and it is the reasons for which the Chinese fought and the way in which they have fought which have shaped the issues of the war as a whole. Just imagine what terrible problems we should face if this war were in fact on top of everything else a racial war, a war of Asia for the Asiatics we owe it to China that the war in the Pacific is not a war of Asia for the Asiatics but a war in which the issues are the same for Asiatics as they are for Europeans and Americans issues of self-defense against aggression of freedom against subjugation. These are things that have become established clearly in men's minds partly because the war has been going on longer in Asia than anywhere else. Yesterday, September 18 was the 12th anniversary of the stealthy and treacherous Japanese attack on Mukden. To China, the cost of that attack was the loss of three of her richest provinces followed by steady encroachment until the whole nation was at war but the whole world also paid a price for Japan's aggression. Failure to control the aggression undermined the League of Nations and opened the way to the rise of Hitler in Europe. What is the essential difference between the passive, lethargic China of the last war and the dynamic, history-making China of today? How sudden was the transformation? That is just the point and it is the whole point. The awakening of China is not due to a sudden transformation and neither is to Japanese aggression the result of a sudden transformation. There is a direct line of development from the Japanese generals who were looking for loot in the last war and the Japanese generals and admirals who were looking for loot when they struck Mukden in 1931 when they struck at Marco Polo Bridge in 1937 and when they struck at Pearl Harbour in 1941. There is also a direct line of development from the passionate students of China who roused their countrymen to protest against the Versailles Treaty in 1919 to the skilled Chinese generals of the nation's Chinese guerrillas of today. In a quarter of a century China has changed from the kind of country whose fate is settled for it in distant councils to the kind of country which determines its own fate and in so doing helps to shape the fortunes of other nations and peoples. 25 years ago China was at the mercy not only of other countries but of its own corrupt politicians and conscience-less warlords. The protest of the Chinese students in 1919 was not only against heartless, fallen statesmen but against traitorous Chinese in high places. In a quarter of a century since then the Chinese have no more become a perfect people and a model nation than America has but they have become less and less a country of civil wars and more and more a country of responsible political standards. They still have great problems to face and to solve but it is not where they actually stand at the moment that counts it is the direction in which they are moving. They are moving forward and because they are moving forward there is hope that the rest of Asia can also move forward. That in itself is enough to open out the horizons of the world and an assurance against the closed horizons of the Versailles Treaty of a quarter of a century ago. Thank you Mr. Lathamore At this same time over most of these stations we will present the Manchurian incident and its consequences with drama of the past and present and commentary by Owen Lathamore authority on the Pacific and director of the School of International Relations Johns Hopkins University who may secure an illuminating handbook of the Pacific story with background information on each program in this series with suggested further reading. This Pacific story manual will be sent to you for 25 cents in coin to cover cost of printing and mailing address the University of California Press Berkeley, California the address again the University of California Press Berkeley, California by Arnold Marquess the score is composed and conducted by Thomas Peluso your narrator, Gane Whitman this program has been presented as a public service and another feature of the Inter-American University of the Air by the National Broadcasting Company and the independent radio stations associated with the NBC network this is the National Broadcasting Company


This video will show you how to check your grades on the problems for a single homework set, as well as the full list of grades you've earned on all your homework sets in a course. Log into WebWork First. Then look for the link that says Grades in the left sidebar and click that link. This gives you a page with all the homework sets you've been assigned so far in the course, both the ones that are closed and the ones that are active. For example, Delilah here has earned a grade of two points out of a possible three on homework set one, which we can see by looking at the number under score, which lists the grade she earned, and comparing it to the number under out of, which lists the number of points total on the homework set. The entries off to the side show that she got the first and second problems correct because they are marked with a C. She attempted the first problem three times and the second problem one time, but she got the third problem wrong. If a problem allows partial credit, you may see a decibel number appear in this top row. On homework set two, she got the one problem on that set correct, so she earned a one out of one, and she has made no attempts yet on the orientation problem set. Delilah can keep track of her grades here on this page or manually enter those grades into a spreadsheet for her own record keeping. And that's how to check your grades in progress on your WebWorks sets. Thanks for watching.


This part of the session, I would like to describe how I believe pointers could be introduced to our students. By now, the students would have understood that there are memory locations which are tagged by the names that we give them and that these locations form a sequence of consecutive places where values can be kept. We would now like to emphasize to them that while we normally deal with the values stored inside these locations, the location addresses also can be deployed meaningfully. Use of these addresses of the location and the values therein has been handled traditionally in C C plus plus at an extremely low level and that is the reason why pointers are predominantly used in C, used less in C plus plus and not used at all in languages such as Java. Many puritanical programmers consider the use of pointers as a very dangerous thing. However, pointers and pointer arithmetic forms the very crux of many good programs that have been written. Your power to write programs, of course sometimes the programs become unreadable. In general, in C C plus plus, you cannot avoid using pointers. There are certain simple things also which cannot be done without pointers and therefore understanding pointers is a necessary event. In particular, when I want to pass parameters in functions by reference, I need to use pointers. So, we will see one example of this and input output functions in C C plus plus such as scanf will necessarily require a pointer. The way I like to introduce pointers to students is to tell people that memory consists of many locations. Each location has a unique address. Usually, the address inside the machine starts with 0. The smallest units of addressable memory is a byte. That means you can address individual bytes. For numerical values, we use larger locations which are made out of composite bytes. So, you put two bytes together, four bytes together, eight bytes together and you get a larger location. Now, if you consider int float and care variable types in arrays and have a declaration int float a3 care c4, assume that you have assigned these values, 573 to m, some 673.85 2 to a0, some very small value to a1, some very large value to a2 and you have assigned individual characters u, n, i, x to c0, c1, c2, c3. Please note, I am not talking about a string here. So, do not search for a backslash 0. These are just arbitrary assignments made here to demonstrate the notion of a pointer. Now, if these variables are listed and if we assume that these have been allocated consecutive location in the memory, what internally will happen is something like this. Suppose the first location is allocated at the address 10000, then the addresses of all locations will follow like this. The location 10000 will contain the value of m since an integer is ordinarily allocated 4 bytes, the next available location address will be 100004 which will be given to a0. Now, a0 is a floating point element, it also requires 4 bytes, next element is 100008, subsequent is 1000012, etc. At this 1000012, I have the element a2 which contains this large value and it is 4 bytes long. The next element is addressed at 1000016. This then will become the address of the element c0 which contains u. However, this is a care array, so it requires only 1 byte and therefore the address of the next location is 100007. These then are the addresses and these are the names. Now, this is what happens internally and we should particularly tell our students that ordinarily we have nothing to do with these addresses. We deal only with the name and the corresponding value. However, it is possible to deal with these addresses which are actually pointers to memory location because they point to specific memory location. Now, 10000 is thus an address pointing to m which is a int type, 1000012 is an address pointing to a2 which is a float type, 1000016 is an address pointing to c0, 1000017 is an address pointing to c1. What is important to emphasize to our students right at the beginning that while the addresses simply look numerical and therefore exactly similar in nature to us they are not. Internally c plus plus makes a great distinction between a pointer which points to an integer value and a pointer which points to a floating point value and a pointer which points to a character type value. Ordinarily we do not deal with these pointers at all. We use names and values, but c plus plus permits us use of pointers within a program. A location address can be found and stored as a pointer and contents of such address can be accessed and used. Notice that as I said we normally deal with these names. The first question is if a pointer is defined as an address to a location given the name of the location how do I find an address and where do I store that address. The corresponding reverse problem is given the address stored in some appropriate variable which we do not know how, but given an address how to find the corresponding value. The corresponding value which is located inside this name m. These are the issues with which the pointers deal with. So for example consider the location name m its address in our example is 10000 value of m is 573. The value at address 10000 is 573. So even if there was no name m if you knew the address you can relate it to the content 573. Of course we deal with that. As I said we require two possible operations given a name what is its address. Given an address what is the corresponding value stored in that location. These two are made available to us by the operator n and the operator star. Note that the symbol star is used as multiplication operator in the arithmetic expression symbol and is used in our logical expression. But in a standalone fashion associated with something that we shall shortly see these stand for operators dealing with addresses and their content and is called the address operator. When it precedes any name it returns the address of that name. Star is called dereferencing operator whenever it precedes a name it actually gives us the value contained in the address referent by name. For example and m will give us the address of m. Star p will give us contents of the location whose address is stored in p. What is p? Is p an arbitrary integer variable because we think that addresses are simply numbers and they can be stored in integer variable. The answer is a plain no and this must be told to our students emphatically that while the addresses are numerical values c c plus plus does not permit us to deal with these addresses as plain numerical value. If at all we want to extract an address and use it even numerically for doing some operations as we shall see it must be stored in specially defined variables called pointer variables. How do I get an address if I have a variable p which is a pointer variable I simply say p equal to and m. Notice that the and operator will get us the address and this address will get stored in p. How do we declare p and how does it hold an address? Here are some examples. There is a special type called pointer type and I can say int star p. Why do not I say pointer p? Simply the reason is as I said c plus plus distinguishes pointers of different types. That means pointers which point to names of different types. So a pointer which pointing to a integer variable a pointer which is pointing to a floating point variable a pointer which is pointing to a cal type variable are all considered separate types of pointer. And the simplest way to define a pointer since every pointer is always associated with a type c plus plus has decided as design a mechanism by which you write the type and then you write a simple star followed by the pointer variable name. It means that you are defining a pointer which points to variable of that type. So here is an example int star p defines name p to have a type int star which means it is a pointer of the value type int. Please note that p itself is an address. So it is actually a numerical value. But can I say p equal to let us say one lakh twelve thousand? The answer is no. This is a wrong thing because while p is contains a numerical value it is not an arbitrary numerical value that we can assign. It has to be a valid address of one of the variables or array elements in your program. And that valid address must be calculated by c c plus plus only. You and I cannot do that because we simply do not know what any address of a location is. And this can be found by saying p is equal to and m. So only such an assignment can permit us to get a value for p. Of course once we get a valid address there are numerical operations which are possible on p which we shall see shortly. Here is a code m n int star p. m is equal to 25. This is a normal assignment. m is an integer variable. p is equal to and m. This means the address of m is assigned to p. n is equal to star p plus 3. This is a valid statement. Why? 3 is a value. p is a pointer but star p is a value. Remember star is a dereferencing operator. So star p actually means the value contained in the location pointed to by p. This is nothing but m whose address we got it here. Since the value of m is 25, star p is replaced by 25. 25 plus 3 is 28. So you get this value. We can declare pointers for any data type.  This will allocate separate memory locations for these three pointers. As I said each can contain an address which ordinarily itself is a 32 bit number. So the address can be a very large value between 0 to 2 to the power 31 minus 1. When I write p 1 is equal to and m where m has a value 573, p 1 will be assigned what value? p 1 will be assigned the value which is address of m. What is the value of star p 1? The value of star p 1 is the value contained in m which is 573. So here is an example. If I print the value of m using c out star p 1, I will get actually 573. We can also print the value of pointer itself which is meaningless to us ordinarily. Suppose I say c out p 1, I will actually get the address contained in p 1 and in fact whenever you ask c out to print the value of a pointer variable, it will print it in extra decimal because it knows that it is not a meaningful value to your program. It is an address which is in turn. We can actually increment the value of a pointer. For example, if we say p 2 is equal to and a 0, notice that this is an address operator a is an array. So the address of the 0th element of array is stored in p 2. Now when I say p 2 plus plus, p 2 will not increase by 1, but it will increase by as many bytes as are associated with that type of array a. Since that type requires 4 bytes, the address will be advanced by 4 bytes. Why? Because when we say p 2 plus plus, the implicit understanding of c plus plus compiler is that you now want the pointer to point to the next element of this array and the next element of this array is 4 bytes away, not 1 byte away. Now this is automatically handled by the compiler. You and I do not have to do any. Now if I say c out less less star p 2, it will print the value of a 1 because p 2 has been advanced by 4 bytes because of this instruction. Here is an example program. I declare m n a 3 is a 3 element array. I assign p 5 73 to m and some minus something, something value to n. I define two pointers, integer type pointers because all of these are integers, p t r 1, p t r 2. I have assigned the values of m and n, I just print them out just for confirmation. I will get m as p 5 73, n as 1, 2, 3, 4, 5, 3. I do what I just demonstrated. I extract the address of m, store it in p t r 1. Now p t r 2 is also a pointer.  Please note that these pointers are in type. Since integer requires 4 bytes, p t r 2 will have a value which is 4 greater than p t r 1. Since I have declared m followed by n followed by a 3, I would now expect that p t r 2 points to n if p t r 1 was pointing to m.  If I execute this program, this is what would happen. Value of m and n is this and this. The pointers have these two values. These are the values which are written by what you call in hexadecimal by c plus 1.  Why is that? Why are we not getting the right value of n? That is because n need not be located 4 bytes away from m. There is no guarantee that the compiler would do that. The only guarantee compiler gives is when I have in as a pointers pointing to array elements because array elements are only always allocated consecutive locations. The correct way to deal with two different values m and n is extract the address of m separately by an AND operator, extract the address of n separately by an AND operator. Now if I print these, I will get the right values of values pointed to by those pointers namely the value of m and n. These kind of explanations I have found very useful to the students who otherwise get lots of confusion in the case of pointers. What is important to tell them is that if you are dealing with arrays, then pointers which have successive values of that particular type will always point to successive elements of an array and that is because array elements are always allocated successive locations. So if I output a 0, a 1, a 2 and I assign address of a 0 to pointer 1, I add 1 to it to get pointer 2, I add 2 to it to get pointer 3 and then I print the pointer values and then I print the data values which are pointed to by them by saying star ptr 1, star ptr 2 and star ptr 3. Observe what I will get as output. The actual values are these, the pointers have these values and the corresponding data values are the same as these. Notice that the pointers which are printed by my program, those of you who can easily read hexadecimal, this value ends in 5 c and this value is 6 0, it is exactly 4 bytes away from here. This value ends in 6 4, it is exactly 4 bytes away from here. It confirms that c c plus plus will always allocate consecutive locations to elements of an array. Of course the consecutive locations will not be 1 byte away, they will be as many bytes away as are required to represent one value of that type. So this is floating point type or integer type, these will be 4 bytes away. As I said this is merely an introduction to the pointers, there is much more to the pointers, the more important things are to talk about passing parameters to function. Ordinarily when we deal with functions, initially we tell them about passing parameters by value. So for example when we pass, when we write a function f with a parameter int x and a parameter int y and we call it in our program by saying c is equal to f of a b. We presume that a goes to x, b goes to y, the function is calculated and I get the sum returned back here which is assigned to c. Does the value of a and b change? Well it does not because this method of parameter passing actually copies a value. Let me skip this example, this is a very simple example. The point is when we invoke the functions f, the values of x and y are copied and sent to the function. So even if the functions f these or changes the value, the changes not reflected in the original value. Since those values are not copied back, only one copy is sent. Now if we want to tell the function that if you change the parameter which I have sent, do not change your local copy, but change me then by mentioning me as a parameter is not adequate.  So whatever you do with that variable I will get changed because that pointer is pointing to my address. This is what is known as pointing, calling by reference. If I pass the parameter as a star, as an and, as an address then I will get an updated thing. The array names are always passed as addresses or pointers. That means whenever I pass an array name as a parameter, it automatically treats that array name as the pointer to 0th element of the array. That is the reason why when an array is passed as a parameter to any function and in that function if modify the value of any element of that array, that change is reflected in the calling program because what has gone out there is not a copy, but what has gone out there is a pointer to the array and therefore changes happen there. Here is that example. I say int, main, whatever, swap and x and y and this swap function is written as int star a int star b. So whenever I exchange a and b, it reflects back on to x and y and x and y gets changed. The I o function since c plus plus remember I said on the very first day that it is scary to explain and scary for students to understand the use of and in a scan f, but once we define the pointers and tell them how pointers work, we will see that it is very easy to explain the function scan f particular. The parameters, this is an explanation for scan f and print f. I am not going to those details, but what is important to say is the print f function, but let us look at the scan f function. The scan f needs to be passed pointers to the argument. Why? Because when we call scan f function, it actually collects a value from the input and inserts it into the variable. Now, if that variable was merely a copy, that value remain inserted in there. We want that value back. So therefore the parameter that we give is an address parameter. So for example and where variable 1 and variable 2 etcetera is the way to call scan f. So here is an example in this scan f when I say and x and y, then whatever value is read by scan f is given to me as value of x and value of y. Therefore, when I say c out, I will get actually the input value. Why am I not using an and operator here? Simply because it is not necessary. Name is an array and by convention c plus plus always passes as a parameter the address of the name of the array name. Therefore, if I read something here, it will automatically reflect in this variable. This is the essence of pointer. There are a lot more things that you can do with pointers. Sadly, there are many programmers who write very difficult to understand code by using only pointers. So for example, it is fashionable or it was fashionable at one time among c programmers to not to use arrays with their indexes. So instead of writing c i, they would write star c plus r because star c is a pointer, i is an index. Now this might make sense to a tricky and in their ways, elegant programming. I personally consider that as poor programming because a program which cannot be understood by another human reader easily is a poorly written program in the modern context, where programs are increasingly written by someone and used and modified by someone else. I do not have the privilege of writing programs for my own sake. I always write programs which will be shared. So good coding practice should mean that you should not try to use such tricks. But what is important is to understand that pointers are extremely critical and important. A few things such as parameter passing by reference cannot be done without pointers and of course they can be used for some elegant coding practices. Here is another example of scanf where an input data line contains this. So notice that there is no blank space here. Observe that all the while we are shouting at c in that without a separation of a blank, I cannot read anything. But the scanf can read the entire character string and the scanf has the ability to extract portions of that string based on the format that I have described. I suggest that we take the tea break now


What's going on, everyone? Sam here with the late in sports cards. We are ripping 2022-23. Penin revolution basketball, hobby eight box, case break number 30. Pick your team style. Read off the list of our names on our teams. We've got Allen G. Mabs, Dante P. with the Knicks, Dean W. Rockets, Derek K. Heap Wizards, Gilbert S. Bowles, James L. Pelicans, Jared T. Clippers, Jeremy S. Magic, Lizzie with the Raptors, Long J. Timberwolves, Louis L. Lakers, Matt H. Pistons, Matthew K. Pacers, Mike Y. Grizzlies, Nathan A. Thunder, Robert S. Nuggets, Scott T. Bucknets, Scott A. with the Trail Blazers, Tony K. Sixer, Sons Hawks, Tyler D. Cabs, Vaughn with the Celtics, Kings, Spurs, and Jazz, Victor F. Hornets and Victor O. with the Warriors. Good luck here, everybody. Another 10 box Tuesday spot. Thank you, Matthew C. We're down to six. Six to go now, everybody. Six to go. I see that four. Good luck, everybody. Let's do it. Revolution. Boris still hasn't answered if he wants my old shirts yet. In my latent backpack. He hasn't answered me. No. You know you don't want that. Anything about that? No, you don't. Rookie Revolution, Jake Leravia, Josh Manant, Astral. I think he does. I think he wants my old Unwashed Shirts. He has much of ours. Fractal stuff, very shock-worthy. We're losing it. Yeah, it's only 10 o'clock. That's pretty funny, actually. Terry Eason as well. That was Shade on Sharp Shockwave. Triple S there, Shade on Sharp Shockwave. Kendall Brown, Astral, Malachi, Branham, Rookie. Supernova, Luca, Oseme and Jing, Boyan, Bogdanovich.  You just got jingled. There's not even Joe Engel in here. Yeah, we'll make it to personal tonight, Nate. Lebron, Cubic. Nice one there. Supernova to 50. Rats on that. Yeah, we did both lose it a long time ago. That's true. Yeah, Nate, I think you're first in queue to A.J. Griffin, Jake LaRavia. You have two, so a 60 future frame is Jake LaRavia. You have two five stars, right? So I think if that's you, then yeah, you're first in queue. Now, no wrestling, unfortunately. No wrestling. Yup, yeah, you'll be first in queue. So once group breaks are over, you'll be the first person to do it. Yeah, no problem, Nate. Six to go, everybody. Six to go. You got Facebook in it. Thank you, sir. Thank you, sir. That is breaking next, 10 mobs Tuesday, Prison Treasures. This one has extra cards in it, I think. What is this? Look at all this base. That was weird, and this one's something that's going to have like one card in the pack. Supernova, Paolo. Do you not say Murray? Is this a one card pack? Oh, it's a two card pack. Keegan Murray and Ty Ty Washington to 149. That's actually a pretty good one, two card pack, though. There you go. Rockets, Dean. This might be a one card pack. The Lonely. Scotty Barnes. Vortex in one pack. Nemhard. The Earned Fox. Go, Dean. Yeah. Yannis Astro. Terri Solan. Musa Diabate, Astro Rookie. Do you want my shirts? That is Jaylen Williams, A.J. Griffin Groove. Nikola Jovic's Groove. The Heat. How's your hair look like that? Chat Holmgren, nice one there. Sunburst to 75. That was just funny when you had it down.  Looked like a... No more fudge. Like an emo punk rocker. Jaylen Jackson. There it is. Galactic. Michael Porter Jr. Case hit. Going to the nuggets. There you go, Denver. Nice one there. I think we're down to just three spots left. Now Scott A and John H. Nice one there. We'll get that magged for the nuggets. We had Denver in this one. Let me see. Denver is Robert S. There you go, Robert. Liftoff, Cade, Fractal. Astro, Wendell Moore Jr. Jean Morant, Supernova. Kyrie, Paul George. Can't think he's seriously looking like that. I really can't. Hey guys. Nice and dance. Isaiah Moebley. Jaylen Williams. There's Michael Porter Jr. Going for that rainbow to 75 on the sunburst. So I have a Discord server for me, Jake and Dylan and anyone else who wants to play with us on the show because that's the only way we can chat on the show. Look at the server. That's our profile picture for the server.  Hey guys. That's Terry Eason. A.J. Griffin.  We've got Dyson Dangles on Instagram. Two 100. Nice auto there for the pelicans. That's a steal. I sent it to Jake to look at it when we were talking. I think he genuinely... Because you know how when he gets laughing he will just go. He was for like two straight minutes just laughing. Bradley Beal. James Hardy. I think he was DJ Liddell. He's off on Tuesdays. I think. Shade on Sharp Rookie. Jabari Walker. Astro Rookie. There's Supernova Paolo. Paolo Astro. Nice one there for the magic. Yeah, he's at State Farm. There you go. What's he wearing? Still just three to go everybody. Three spots left in 10 Box Tuesday. Only three spots of the night. Thanks again everybody for getting this close to fill. Thank you again for filling everything up today. Started off a little bit slow but thank you everybody for taking spots and getting us very close. Yeah, we pitch. There's Jason Kidd. Nice one there for the maves. Nice hit Dallas. But you weren't expecting to see that one today. Jay Kidd. Walker Kessler. Jeremy Sohan. Kenneth Lawton. Junior Astro. Rookie for the Grizzlies. Sorry he's smart. Peyton Watts. An Astro Rookie. OG Anonymi. Og Anonymi. Jabari Walker. Groove Rookie. Blazes. Yeah, always going to be three base on the back guys. Not missing anything on the back, I promise. Jabari Smith. Luca Groove. Bradley Biel. Osmane Zhang. There's D'Angelo Russell. Timberwolves 2. 149 on the impact. Hardin. Butler and Harrison Barnes. On to the next one. Here we go, here we go, here we go. Jaden Hardy. Dyson Daniels Rookie. Terry Eason Rookie. Fractal Shockwave Keegan Murray. Yeah, we're rocking now here. Zai. There's Paolo. Jalen Durant.  I can do that. I do that with some people. Jaden Ivey. There's a Ochaig Bajie. Dyson Daniels. Dyson Daniels Groove. Bass, bass, bass. Doesn't matter. All right, work. I'll do that with some people, if they have a name. If they have a name that's too hard to like, they have like a username that's too hard to say, or too takes too much time to say. They should just call it by their first name. There's James Hardin. Cool story, bro. 299 Cosmic. Oh, we have one tonight. We have Tavo in 10 Box Tuesday football. We have an Illusions. There's a Darren Fox Sunburst to 75 for the Kings. Again, guys, just three left on 10 Box Tuesday. Three to go. Yeah, we do. I don't know if we have any for personals, Rory, but we've been doing group breaks of it. We've got probably like four or five cases. I think we've done two cases worth of group breaks. We'll do like two 10 boxers, usually per. Should have two autos in these next two packs now. Bari, Smith, Vortex, Trevor Keels, Astro, Rookie. Yeah, maybe we'll put them in stock for personals eventually. Jaylen Williams. There's Fractal, Rookie Revolution, Shade on Sharp. Like maybe we'll put like one case in stock. Yanis, Shockwave, Fractal, James Hardin. Oh yeah, Forest is excited for that. Yeah, yeah, they've been fun, man. I've ripped, I did two half casers yesterday. Which is pretty, pretty awesome. Palo, Astro, Jovich, David Roddy, Astro. Yeah, just three to go guys and it breaks next. Is 10 box Tuesday at Basketball. Prism Treasures, two years of prism. National treasures from last year. E.J. Lydzel. Oh, for illusions. Yeah, I'm sure Forest is pumped for illusions. Evan Mobley, 299 on the Cosmic. Jabari Smith, Astro. Malcolm Brogdon, that is Sunburst of 75. Sixth Man of the Year, Malcolm Brogdon that is. Rookie Revolution, Kygan Murray, excuse me. There's Caleb Houston, Astro. Otto, Malachi Branham. Nice one there, San Antonio. Spurs, picking up a Malachi Branham Otto. Wanzo, Shreyman. Jalen Halyaduren, Kygan Murray, Rookie Revolution. Gary Buckets, base, base, base. Scott Jha, Jake LaRavia, Groove, Rookie. Josh Minna, Astro, Bryce McGowan, for the Hornets. The Cell, base, base, base. Shrey Young, Jaden Hardy. Out of anything, Rory. Out of Hobby, no Holland Colour Blast. Terry Eason, Groove, Deandre Aitin, and base. Do a quick recap here. Only three autos in this one. Malachi Branham, Jason Kidd, Dyson Daniels, to 100, and Galactic MPJ for the Nuggets. That'll do it for the break, guys. Thanks again for the fill. Up next, 10 Box Tuesday, let's sell it out.