 In this lesson, we'll have a brief introduction to what cryptography is to set the stage for the rest of the course. You might be familiar with cryptography from many images in pop culture, whether it be a book like the Da Vinci Code, several movies like James Bond or The Imitation Game, even National Treasure or Little Ralphie in The Christmas Story, or maybe you've heard about cryptography in some lessons in history class, most famously Mary Queen of Scots. Or maybe you've just heard about cryptography from cryptocurrencies or NFTs. All of these make it really difficult to understand really what is cryptography and how you might be able to use it in your own life. But simply cryptography is using mathematics and then oftentimes computers to carry out these mathematical calculations to hide the meaning of a message in a way that's difficult for somebody else to reverse. And in this course, we're going to study various ways that we can employ cryptography to keep our messages or maybe more modern times just data safe from prying eyes. For example, say we have this short message of North Carolina, we could encrypt or hide the meaning of this message by applying some cryptography methods, in this case, the Caesar cipher, to create this cipher text that we see on the right, which is unreadable. If we were to take away the original message and all you had was the cipher text, it'd be rather difficult to understand exactly what the original message was. So some vocab that we might have already heard there that we might want to familiarize ourselves with. First is the plain text. That's our original message or original data that we're trying to hide. So in our last example, that would have been the words North Carolina. The cipher text is what we're trying to create. This is our unreadable secret message or encrypted data. In the example, it was those letters Q, R, U, and so on. A cipher will often determine the algorithm that is used. So in this case, I mentioned it was the Caesar cipher. But the Caesar cipher needs a little bit of information to do his job, otherwise it's always going to create the exact same message. So we have to give that algorithm a key, which is a unique piece of information that will allow you to take your plain text message and create the cipher text message. In this case, the key used was the number three. We'll learn in a later lesson exactly how the Caesar cipher uses that number to go from plain text to cipher text, but for now, not important. Another aspect of this course that we'll get to in a couple of weeks is called cryptanalysis. And this is using some mathematics like probability, statistics, and other information to try and go the other way with this. Propose that we had a cipher text and we wanted to know what the original plain text was. Could we reverse this process without having any advanced knowledge of the key or the algorithm that we're used to create it? That's where James Bond might come in, he could come in and actually determine the algorithm and the key by stealing it from somebody. But as a mathematician and a programmer, we don't have those tools at our disposal all the time, so we have to be able to use cryptanalysis. Here's an example. Cryptanalysis might sound really difficult, but there are a few things about language that are rather predictable and we could figure out without the need for any sort of espionage or advanced computing, perhaps just a little bit of time and trial and error. Take a minute here, pause the video, and look at this message that's on the screen. You'll notice it is encrypted, certainly not readable. The original spacing and punctuation has been retained in this message, you'll see that might be helpful. And see if you can figure out what the original message might be. It might take you some time, maybe 15 or 20 minutes, feel free to reach out to others in the course to see if it might help you. And we're going to go ahead and start walking through it in three, two, one. So maybe the first thing that jumped out at you is this repeating fragment of text FZW. We're able to figure it out because of the original spacing that was left in the message. We can see these short three letter words and it happened to be the same one over and over and over again. So that might allow us to make an educated guess that maybe this common three letter word in the cipher text corresponds to a common three letter word in the English language. In this case, maybe we would make the guess that that three letter word is the word, the T-H-E. Some other things that might have jumped out at you. Here we see the letter Q is the only one letter word in the cipher text. And again, English language is somewhat predictable. There's only so many letters that could actually appear as a one letter word in English, most notably the letter I or A. Lastly, maybe you saw this repeated two letter word, AX. Not a lot of common two letter words. We also see that A shows up at the beginning of quite a few other words in this cipher text. So it could be a common beginning of a two letter word. Think about maybe which two letter word it might be. This idea of pattern detection is really powerful. And in fact, it underpins all of the crypt analysis that we do. If we can find a pattern in the message, we could probably use that to our advantage somehow. So as we said, we saw this cipher text fragment, F-C-W, probably the word D. This letter Q, probably the letter A or I. And in this case, the letters AX could have been a couple of different two letter words. We're going to go with the English word of OF, and that's just a guess. There's no way of knowing. That's the other part of crypt analysis is that we'll often play our odds or percentages. I know that OF is a very common two letter word in English language. So it might be a reasonable first guess. If we're to take this information, we can create what's called a letter mapping between the plain text alphabet and the cipher text alphabet to help us keep track of these guesses or things that we've deduced. Once we've copied down our guesses, now we need to start figuring out what are the remaining plain text letters that we don't understand the mapping for the cipher text letters quite yet. One way we could do that is by substituting in the letters that we think are correct back into our cipher text message and taking another look. Here, we can see that we're starting to see some English words taking shape. I've kept track of the ones that we've replaced by using lowercase letters for the plain text. That's a very common thing that you'll see throughout the course. Plain text letters are lowercase, cipher text letters are uppercase. Now looking through, not many other words are jumping out, maybe on the body of the cipher text, but down here in the pink box, we can see that we might have a signature. This could be a message in that little dash between what looks like maybe a short first word and a longer second word could reasonably guess to be first name, last name. And looking at the first of the two words, an OH in the middle two letters could easily perhaps be the word John or the name John. So if we were to make those guesses, so adding in now those two letters to our mapping and updating again, now we can start to make a few other guesses. And as we start to fill this out, we can complete this mapping from plain text letters to cipher text letters. It's oftentimes more useful to have the plain text letters alphabetized instead of the cipher text. So just reshuffling it is this way. And you might see in the cipher text alphabet the word science and math in some shape or form there. And that was actually a key to how this mapping was created. This is what's known as a keyword substitution cipher. Applying this mapping back to the original message, we can see we have this message here from John Chadwick that begins, the urge to discover secrets is deeply ingrained in human nature. So an interesting start to this course here, but certainly speaks to the universal nature of humanity trying to keep, but then also find out secrets and solve puzzles. So I hope that will drive you forward in this course. So what we just looked at was what's known as a substitution cipher. In fact, I think we even said the word substitution once we started making guesses for the plain text letters that mapped to a cipher text letter, we went back to the message, we substituted out the cipher text letter for the plain text letter. And when we were creating that message, we substituted out the plain text letter for a cipher text letter. In general, we're going to call a substitution cipher any type of cryptography that creates a cipher text by mapping a single letter. And later on in the course, we'll see this can be done with groups of letters as well to a single letter or groups of letter in the cipher text. So again, we're mapping a single letter to a single letter. Specifically, the cipher text that we just looked at was created using a monoalphabetic substitution cipher, which just means that mapping that we came up with, it remains the same throughout the entire message. We'll see there's other types of substitution ciphers that are called polyalphabetic substitution ciphers where that mapping can change some points throughout the message, perhaps every letter or every five letters or so on. We'll study all of these throughout this course. Now, it turns out there are just so many different ways to create these mappings. In fact, there's 26 factorial ways that you can do it, which you can see as an astronomically large number. Now, we need to figure out a predictable way to create these mappings. So it's easy to explain to your friends or colleagues how to undo the process that you just did. If you just randomly assigned letters from the plain text to the cipher text, you can't tell your friend or colleague to just randomly assign the exact same way. So that's where some of these cipher types that have names that maybe you've heard of before, like the at-bash cipher, the Caesar cipher, or the affine cipher, they create a system of rules and mathematics to apply these mappings in a predictable way so that somebody who receives a message from you, with the key, of course, can undo your encryption process. So we have to whittle down that 26 factorial possibilities to a smaller set that are more predictable and easy to use. Now, besides substitution ciphers, there are other types of ciphers. In fact, ones that you've probably seen since you were a very young age, we call transposition ciphers. And you can see over here on the side of the screen, we've seen these all the times for jumbles. They just shuffle up the letters. So when you just rearrange the letters in a message, we're not changing the letters in our message, we're just changing their position in the message. And you can see here that the small word in plain text math has many different possible ciphertext just by shuffling around those four letters. In fact, there are 24 different rearrangements. Now, you might think this isn't very secure because, well, you can just look at those four letter rearrangements and probably guess the word was math, even if you didn't know that. But it turns out as our messages grow longer and longer, the number of possible ciphertext grows incredibly quickly. So for example, take this short sentence in green. There are 35 factorials, different rearrangements of those letters. And that would be an incredibly difficult task for somebody to take some of those scrambled 35 letters and try and put them back together into the original message possible, but incredibly difficult and computationally difficult and challenging to do. Now we'll see there's not as many transposition ciphers that get used throughout cryptography, but those that do get used are used in a very specific way and provide a lot of power to hiding your secret messages. At the end of the day, these different ciphers all have to have some certain characteristic that makes them fit to use. And it was August Kirkhoff who first tried to establish what are some of these guidelines and rules or principles for using ciphers in this modern era. Now in his day, the modern era was in the late 1800s, so no computers clearly, but still some of these principles remain today. Many of them, like talking about being able to use on the telegraph, maybe not so relevant. However, this second one is kind of the driver of our underlying modern cryptography. It should not require secrecy, meaning you shouldn't have to hide to somebody the algorithm that you use to create your message. You should be able to say, I use the Caesar cipher. And as long as they don't have the key, it shouldn't be a problem if that message were to fall into enemy hands. Now we'll learn very early on in this course that the Caesar cipher is not a valid encryption method, according to August Kirkhoff, because if you know it was encrypted with the Caesar cipher, it is not too hard to figure out what that plain text message was because there's only a very small number of keys that you could try. And with a computer, it's very easy to try all of them. But we will later on in the course discover many other cryptography systems that are valid, that even if you knew it was encrypted, say with the RSA algorithm, it would be so difficult for you to figure out what the original plain text message was, if all you had was the cipher text and no key. So we're gonna start this course by looking at a lot of invalid or insecure cryptography methods to understand the history and some of the elemental mathematics that drive today's modern, secure encryption methods that we'll study by the end. And all the while, we'll be learning how to use our computer with the Python programming language to analyze and study these different ciphers and build up this nice toolkit of functions that we can use through our work in cryptography.