 Welcome back to our lecture series math 4220 abstract out of 1 for students at Southern Utah University. As usual I'll be your professor today Dr. Angea Missildine. This is actually going to be a really exciting lecture. I'm really excited here. I mean you can see a pot of gold in front of you already. You know this is going to be good stuff. In this lecture we're going to talk about the idea of public key cryptography. So suppose you are connecting to your bank's website. Well it's possible that someone could intercept any communication between you and your bank. So you want to encrypt the communication. Even though symmetric key cryptography can be modified to make it much more secure than the models we talked about in the previous lecture. The problem is that symmetric key cryptography, these methods require that both parties already have a shared secret encryption key. How can you and your bank agree upon a key if you have if you've not already talked to each other right? How do two people who've never met before set up a encryption with each other if it's a symmetric key? Well I'm going to give us a fairy tale here and the purpose of this fairy tale is to explain the basic goals of public key cryptography. To provide a way for two parties to agree on a key without a snooping third party being able to determine the key, the method relies on a one-way function. That is a function that's easy to do one way but very very very hard to do in reverse. So here is our fairy tale. So we have a king and queen, their brother and sister. So in one land we have Queen Alice who rules over the people and in another land her brother King Bob rules over his people. Now Alice wants to send Bob who lives in a far far far away kingdom a very valuable treasure. We can see the treasure chest right here. She wants to send this valuable treasure to her brother. Now since she is not able to meet Bob in person to deliver the treasure because again he lives far far far away, she hires servants to take the treasure chest to Bob. Alright these couriers will take the treasure to Bob here but not sure if she can actually trust the servants that she's hired here and not sure if they'll try to steal the treasure along the way. Alice places on the treasure chest a lock. A lock for which only she has the key to this lock. Okay so now we see our locked treasure chest right here. So because the servants don't have the key to the lock there's no way they can open it. So they faithfully take the treasure to Bob. So now Bob has the treasure chest right here but the thing is Bob can't open the treasure chest either because he doesn't have Alice's key to open the lock only Alice does. So what Bob is gonna do is Bob is going to place a second lock on the treasure chest. A lock that only he has the key for. Alright so what we saw here is that Alice sent this locked treasure chest to Bob and it has one lock on it. Okay and we'll say that let's say a little better this treasure chest had Alice's lock on it. Okay so what Bob is gonna do he's gonna put his lock on the treasure chest and he's gonna send it back to Alice. So this time it has two locks on it. It has an Alice and a Bob lock like so and so Bob sends his treasure chest back with his lock on it and Alice's lock on it. Alright so now when the box returns to Alice it now has these two locks on it. One that was given by Alice and one that was given by Bob. Alice is now going to remove her lock from the treasure chest and then her servants have to take the treasure chest back to Bob one final time but this time when the treasure chest returns to Bob the only lock on the treasure chest was the lock that Bob originally put on the treasure chest. Okay and so Bob who has the key to unlock the treasure chest is then able to unlock it and voila the treasure chest is open again yay. So Alice and Bob were able to securely share the treasure amongst each other and no one in transit neither the servants who deliver the treasure nor bandits who might have been along the way anyone who intercepted the treasure chest would never have been able to open it except at the very end when Bob removes his lock from the box. What I've now explained to you via this fairy tale is what's commonly referred to in the cryptography literature as the Deffie-Hellman Key Exchange. So this idea that's back and forth between Bob and Alice here is that we were able to have Alice share with Bob their treasure and no one was able to access the treasure except for Alice who knew what the original treasure was and Bob who was able to unlock it at the very end. We call this a key exchange because really the treasure that Alice is trying to share with Bob is going to be a secret key. It's going to be the secret key that is this is a key a secret key for a symmetric for some symmetric key crypto system that crypto crypto system that they're going to be able to communicate. So removing the fairy tale let's imagine you and your bank want to communicate with each other online or some other online purchase you're perhaps doing where you need a secure connection. Well if you've never communicated with this individual before how in the world can you set up a secure communication? Well one idea is that you could perform some type of Deffie-Hellman Key Exchange where let's say the bank creates a secret key and then you exchange digitally this key using this key exchange so that now you have the secret key that the bank came up with and then you can proceed to communicate with each other using symmetric key cryptography. The advantage of symmetric key cryptography is that it's very simple and the communications can be really fast rapid communication between each other but it depends on having a common secret key. And so this Deffie-Hellman Key Exchange although rather kind of slow it could be a secure way of creating the key and then all future communications then could be worked out with this symmetric key cryptography here. So we can see how this could actually be an effective thing and this Deffie-Hellman Key Exchange is essentially the first public key crypto system out there so that anyone could observe what they were doing. Anyone could see what Alice and Bob was doing but because it was public in that essence but no one was able to still break into the treasure chest. Now this Deffie-Hellman Key Exchange as you can see was rather quite slow but it can be implemented in any group it's really nice. Let's think about the following idea as a as a as being represented inside of a group. So imagine Alice wants to exchange the secret element g with Bob so maybe this element g in the group is valuable this we're going to be able to create us this will be the symmetric key for a new crypto system we'll do in just a moment so this is the secret so to speak this is the message that Alice wants to send to Bob but she can't just say g because then everyone will know what her secret message is and then their future encryptions will be compromised. So what Alice is going to do secretly is she's going to pick uh she's going to pick some number we're going to say m that should be somewhere between the order of g and the number one clearly one is a bad choice and perhaps even the order of g might be a bad choice but we're going to pick some number between those and then she is going to compute she is then going to compute the element g to the m and we're going to call this a this is then what she transmits to Bob so Bob receives the a he doesn't know what g is but he does see what a is and so this right here is the cipher Bob doesn't know what the original message is so what Bob's going to do is Bob himself is going to pick a secret uh he's going to pick some number n uh between the order of g and that's the thing is we don't actually know what g is little g so we really should be thinking of capital g here he's going to pick something between the order of g and one again picking the order of g and one or not the best choice he's going to pick something randomly and as this right here is supposed to be a big group uh you want this because you don't want eve to be able to do some type of brute force attack so we want the order of our group to be very very big and so the likelihood of Alice and Bob picking the same secret here is very unlikely so this is the secret that Alice has and this is the secret that Bob has these are kept secret these are not shared publicly but this message a was shared publicly with everyone so what then Bob does is he's going to take this element a and he is going to then compute a to the n power let's call that b b for Bob and then he sends it back to Alice so that Alice receives b now we know that b is just g to the m to the n like so and in which case because this is a group and we have associativity this is the same thing as g to the n to the m right and so what Alice then can do is because she knows what m is she can then apply the negative the the inverse right there she can do the negative m power so then she's going to compute she's then going to compute b um she's then going to apply the inverse right here and we'll talk some more about this in the next video but she knows how to undo this process so there's going to be some element um some element here m uh excuse me there's there's going to be sort of a way of undoing m so that that is to say there's some element we'll say m d uh which is then congruent to one in this process here and so she then applies this element d here which then this would compute well it's but whatever it is she's going to send it back to Bob right so she sends back this b to the d right here and so what's happening here is that this is going to give this element b to the d uh this is going to be the same thing as just g to the n right so m and d cancel each other out in terms of these exponent rules so she sends this back to Bob and again this is public information everyone can see it and so when she sends this c back Bob on the other hand knows there's a number such that n times e is is congruent to one and so that's what then Bob's going to do Bob when he's going to take c to the e power since this is g to the n to the e power this will just give back a g and so Bob was able to get the secret message g that Alice wanted to send him now if eve is e-dropping which we should assume she always is what does eve see along the way she saw she saw the message a she saw the message b she saw the message c so she saw these back and forth and so is this enough information for eve to figure out what g is well again if the order of the group is chosen sufficiently large then it would be very difficult for her to able to solve this equation they solve solve the misinformation is it impossible for or is it possible to solve it of course it is but if we choose these things effectively enough it becomes a very hard process for eve to do but again there's a lot of back and forth going on here and so a way to simplify the diffie helman key exchange is the following again this makes a lot more sense as as in groups a lot less makes less sense as treasure chest but if you want the about paint it works out with nicely here so what Alice and Bob are going to do and so this is what really makes it a public key crypto system right here what bob and i can do is they're going to publicly they're going to publicly decide on some modulus here this is in the public here they're going to choose some number in okay and so this this is information that even eve knows about and so secretly secretly what they're going to do is so they're going to choose in and they're also going to choose some element inside the group so they're going to so this is like our modulus and we're going to choose some element g as well so we have a module so we have some specific element g so secretly alice is going to choose some number m and bob is also going to choose some number n right here and so then what alice does is she's going to compute g to the m this is going to equal some number a and she's going to transmit that to bob so bob receives an a on the other hand bob he's going to compute g to the n which we're going to call that number b and then he sends b to alice who then has the number b so alice will then compute b to the m which thinking about that for a little bit since since b is g to the n this will then give a composite g to the mn like so and on the other hand bob who receives a he's going to compute a to the n which as a is equal to g to the m you raise that to the n power that's going to give you g to the mn right and so you'll notice that they're able to compute the exact same number but eve who's e-dropping eve she'll have the she'll have the modulus she'll have the element g but she won't know n she won't know m she'll have a and she'll have b right but it turns out with these four bits of information in oh i used the word i used the letter n twice didn't i so we'll just call this the order of g so we're working where we're going modular arithmetic here so uh so yeah it doesn't even have to be modular arithmetic we really just need a group and we have an element of a group and then we just take powers of that element in the group so if the group is chosen sufficiently large then we're guaranteed that alice or eve excuse me would not be able to determine these common powers even though she knows this is a power of g and she knows this is a power of g the a and b she even know these she knows these are powers of g she can't figure out what the combined power is because the calculation is too difficult this is what we mean by a one-way function it's easy for alice and bob to compute the powers of g but it's difficult for alice to basically take the discrete logarithm in this situation uh we we can exponentiate easy but we it's it's hard to do the logarithm and so this is how one can communicate securely in a public domain and that's the power behind public key cryptography