 Welcome back to our lecture series, Math 4220, Abstract Algebra 1 for students at Southern Utah University. As usual, I'll be your professor today, Dr. Andrew Misseldine. We're starting a really fun topic in Chapter 7 of Tom Judson's Abstract Algebra textbook. And with this, it's going to be short for us. We're going to talk about it in Lectures 20 and 21. But we're going to talk about the idea of cryptography, which cryptography, what is that all about? Well, when people need to secretly store or communicate messages, they turn towards cryptography. Cryptography involves using techniques to obscure a message so that outsiders cannot read it. It typically is split into two steps. There's the encryption phase, in which case the message is obscured, and there's the decryption phase for which the original message is recovered from the obscured form. Now, there's a lot of ways that people might encrypt a message. So how might they encrypt it? Well, one possibility is that the sender literally hides the message. So it's like, alright, I'm going to hide a secret package under a bench in the park. Or I put a secret symbol inside this painting that'll be in the museum. So in some regards, I mean, the encryption process literally hides the object, where only the recipient should know where to go looking for it. Or if you like treasure hunting movies like National Treasure, it seems like it's hidden inside of a riddle, and only those who are able to crack the riddle, solve the riddle, can find the secret treasure like that. So this is the idea of encryption. And then decryption is the process of turning this process... Well, just trying to turn it around, right? So if the object is hidden somewhere, you know where to go find it. That's how you decrypt it. Or if there is a riddle that hides the treasure, then you know the answer to the riddle, things like that. Now, of course, these methods I mentioned have some advantages, but there's by no means the most sophisticated type of encryption out there. In section 7.1 of Tom Judson's textbook, I want to introduce the idea of symmetric key cryptography, which Judson here refers to as private key. And although that, I mean, he's describing it in contrast to public key cryptography, which we'll talk about in lecture 21, public key cryptography has private keys as well. So symmetric key is a more accurate label here. And I'll explain exactly what that means in just a second. So in this lecture, we're going to introduce the idea of a cipher. So from a cryptography point of view, from a mathematical point of view, a cipher replaces each letter or number or character symbol, whatever, in your alphabet. It replaces each letter in the message with a different letter or number or special character, whatever. It replaces each letter in the message with a different letter following some established mapping. This is going to be a function and it's commonly referred to as the encryption mapping. The pre-image of a message with respect to the encryption map is called the plain text. The image of a message with respect to the encryption map is the cipher text. And the mapping is necessarily bijective so that the cipher text can be converted back to the plain text. The inverse mapping is the decryption mapping. So if we were to just illustrate what we mean with this basic cipher method right here. So we start off with our so-called plain text. This is the text which, if anyone were to read it, they would understand the meaning. And ideally we want to keep this somewhat secret. Well, so we want to encrypt the plain text, put it into the cipher text. And this is what the encryption process is all about. The process of converting from plain text to cipher text, this is encryption. Whoops, encryption. But this process has to be reversible. We don't want to encrypt our information by like the pharaoh's tomb policy for which no one will ever have access to it other than dying, right? So this process needs to be reversible. And so the cipher text can be converted back to the plain text by the method of decryption. And a different crypto systems will have different encryption mappings and thus decryption mappings as well. So how we convert back and forth between them will make a difference depending on the crypto system and play right here. So really the strength of any crypto system depends on the difficulty of some eavesdropper Eve from discovering the decryption map. So this is the idea of like this little diagram right here is our plain text here. But so what happens is we have, let me draw another little flow chart here. Oftentimes we like to, we often refer to the people in our crypto messaging here as Alice and Bob. So Alice, she over here has this plain text for which she wants to share with Bob for which she then converts the plain text into cipher text, right? And we're going to abbreviate these things. We're going to call the plain text simply P and we're going to call the cipher text simply just C for the sake of it right now. And so she wants to send the cipher text over to Bob. So she wants Bob to receive the cipher text and then since Bob is able to decrypt it, he can convert it back to the plain text and listen to it. But the thing is we have to assume that there might be eavesroppers, people who can hear the cipher text. When you send something online, we can't necessarily assume that just because it's an email that no one else can see it. And so our eavesdropper is typically referred to Eve, Eve for eavesdropper, right? And so the strength of any crypto system depends on the difficulty of an eavesdropper, AKA Eve, from discovering the decryption map. So we can, we must assume when we have encryption here, we must assume that Eve can find the cipher text. We assume that Eve has access to it, that as it's been transmitted, she received it. And so she has the cipher text, but can Eve translate the cipher text back into the plain text? That's where the strength of encryption is going to all be about. So although much, if not all of the encryption mapping is public information, some information about the encryption mapping is kept secret. And that's what we mean by the key, right? So the idea of transforming the cipher text back into the plain text, that requires some type of key. And perhaps that same key is used to translate the plain text into the cipher text. And so this is what leads to the idea of symmetric key cryptography, that imagine you want to leave your house or your apartment for the day. Well, if you're responsible, you probably lock the door before you leave. In which case, you put a key inside the lock, you turn the key, and now the door's locked, and ideally no one can then open the door without the key. When you return home to get back in the house, to basically decrypt your possessions, you place the same key back in there, you turn it, and that unlocks the door. So symmetric key cryptography is based upon the idea that the same key used to lock the door also is the key that unlocks the door. We use the exact same key to encrypt the message as we do to decrypt it. It's just in one case, when we lock the door, we turn what the key to the right, but to unlock the door will turn the key to the left. And so anyone who has a key can then decrypt or encrypt the message. And so the security here is the idea behind the security is that Eve, if she doesn't have the key, then she cannot unlock the door to get the plain text. Alice and Bob both have keys. Or another metaphor, if you like to think about it, imagine that Alice and Bob are queen and king of two separate kingdoms. They're siblings, right? They ended up ruling kingdoms, neighboring kingdoms. And so if Alice wants to send some great treasure to her brother, that's a treasure chest in case you couldn't tell. She would then lock it, send it to Bob so that he could unlock it, right? And so the lock to this royal treasure chest has only two keys. One sits around Alice's neck and one sits around Bob's neck. And so that even if marauders like Eve tried to attack and steal the chest, they can unlock it without the key, the royal key or something like that. So this is the idea behind encryption, right? We want to send valuable property or in this case, usually information from one party to the other without Eve being able to crack into it. So how are we actually going to accomplish this? Well, so the mappings that we typically use in cryptography, they're not going to be things like treasure chest and doors. Although it's the same type of thing analogously. What we're going to talk about is algebraic cryptography. And so as such, it typically requires that the plain text and the cipher text actually be numerical of some kind. So if we want to communicate with each other with plain English, you know, using the Roman alphabet, there's going to be some way of turning our Roman letters into numerals. So you could just have a simple rule like say, a becomes zero, b becomes one, c becomes two, etc, etc. And so then we can turn our messages into numbers. So without the loss of generality, we can pretend that the things we want to encrypt are numbers. We have secret numbers we want to share. And so it's not too ridiculous an assumption. So for the purpose of this lecture and in the next lecture, if we want to do any decent cryptography, we're going to use some computer software. And so I've elected to base the code for these lectures around the software through magma. Magma is a computer algebra software designed for working on computations and abstract algebra. One thing that's nice about magma here is there is a free web based version of magma. You can find on the following link right here. You can also find a link in the description of this video. Clicking on this link, it'll take you to magma. I'll show you just a second what that will look like. And so you can run the following code in magma. So just be aware of those things here. So if we want to convert a plain text into some type of number, we're going to use the function I created here called digitize. And admittedly, this is a very elementary way of converting a plain text message into a number. I do not claim that this is the professional grade way of doing it. It's meant to be simplistic so that the student or viewer watching this video who is not very well trained in either information science, computer science or cryptography can intuitively understand what's going on. Basically, all this does is it turns the letter A into the number zero. It turns the letter B into the number one. It turns the letter C into the number two, much like we said before. And this digitization process will not be case sensitive. Both lower case A and capital A will be written as the number A. And you can copy this code. This code you see in front of you, you can actually copy it from a GitHub link that you can find in the description of this video. So let's show you how it actually works. So let's say that the message, the plain text message is the word cryptography. Maybe this is a keyword we want to, Alice wants to share with Bob. Well, if we put cryptography into this digitized function, it'll turn the letter C into two, the letter R into 17, the letter Y into 24, the letter P into 15, the letter T into 19. And you go through the 26 letters of the alphabet right there. So it's going to go from zero to 25, the way we have this thing set up. So be aware that if you want to implement this into magma, the code, the basic way of running a code in magmas, first of all, you have to copy and paste the code that you see previously here on the screen. So we need to have this code in the compiler first. And then after the code, you can run a command like digitize. So we list the name of the function, the procedure we want to run. And this procedure has a single parameter. Let's talk about that for a second. It has a single parameter, which is the plain text message we put right there. So this one requires a message and magma will interpret this as a string. So you do need to have quotation marks before and after the cryptography so that it can interpret it as a string. And then every line of code needs to end with a semicolon in magma so that it knows that you've ended a code, because otherwise it ignores white space. And so if you run this command, it'll output the digitization, which would be this array of numbers right here. Now, if for some reason you need to store it on the compiler to use it later for future code, you might actually set up some letter or some function, what was called capital E for encoded here. And so colon equals is going to in magma will declare that the thing to the left is going to be a variable assigned this quantity right here, which would then be this array of numbers. So let's see actually how this would work if we switch over to magma. So I have already took the liberty of inserting digitize into the compiler right here. If I were to run it submit, you see no output in the box down here because I didn't tell it to output anything. So if we want to run it, let's use the command we had a moment ago, let's say digitize. And then we want to do the message cryptography and hit make sure you end with a semicolon hit enter or submit here. Then we got the array we had before if you don't have this semicolon, you're going to get some type of error, right? Because it doesn't know what's going on there. If you forget the quotations, you should also get an error because it's like, I don't know what to do there. If you didn't have any of the quotations, it also would give you a problem and needs to interpret it as a string. So those are necessary things when you run this. Now, like I said, if you want to store the data, you can maybe store it as the variable E. You won't see any output because when you store it, it's not actually declaring any output. So you can just, if you want to see to say what's E, and then it runs it again. Great, no big deal right there. All right, so that's part of the process to work with these cryptosystems. We need to write our messages as numbers, but this process, we also have to be able to convert numbers back into letters. And so if I do the inverse map to our digitization function, we'll call this alphabetize. And so this will accept an array of numbers, we'll call that the code, and it'll convert them back to numbers. So if you see the number zero, that means it's an A. If you see the number one, that's the letter B. If you see the number two, that's the letter C. Just reversing the process, just the inverse operation to digitize that we saw before. And so if we put this into practice here, perhaps we take this array of numbers right here, 12, 8, 18, 18, 4, 11, 3, 8, 13, 4, then alphabetize will report the string misalign. Like so. And so we would copy this and put this in there. Make sure you also put the code into magma. You have to copy and paste this code. So if we go back over to magma, I'm going to get rid of this part right here. And by liberty, I left the code here already. So the code for alphabetize is already copied and pasted right here. This other code is something we'll do later. Don't worry about that. And so let's run it. If we want to do alphabetize, that's what I called it, right? This will accept as its parameter a string of numbers. And so if we insert the string I had before 12, 8, 18, 18, 4, 11, 3, 8, 13, and 4. Maybe I should have copied and pasted this earlier. Oh well. It's nothing too complicated. When we run this thing, whoops, it then gives back the message misalign, right? If we had done the message we had before, remember the encoding of cryptography was 2, 17, 24, 15, 19, 14, 6, 17, 0, 14, 7, and 24. If you run that, we got back cryptography. And if we just write a bunch of random numbers, something like this. You're just going to get a bunch of gobbledygook back. EEDCG. I mean, that's all this procedure is doing right now is it converts numbers to letters and then digitize converted letters to numbers. Now I don't want you to confuse this process of digitization and alphabetizing with the encryption process. That's not the encryption. The fact that we're replacing A with 0 and B with 1, this would most likely be public information. Alice would know this, Bob would know this, and Eve would know this well. So just sending these random numbers would seem like random numbers, right? Sending this sequence of numbers is not the encryption process. This is just the encoding process that we can encode our messages as these strings of numbers. We'll actually get into encoding a lot more in the next chapter, which is also a very interesting mathematical problem as well. And so I've deliberately taken very naive process on how to encode the message, but that's not the same thing as encrypting the message. Encoding will be a public knowledge. The encryption process will have some secrets to it, and we'll talk about more of that in the next video.