 Hey y'all, Mr. Gibson here and welcome to the next lesson in cryptography. In this video, we'll be taking a look at monolithic substitution ciphers both in general and then focusing in on using keywords to generate mappings between plain text and cipher text alphabets. The idea of a substitution cipher is that we want to find a way to map our plain text letters to cipher text letters and then go to the message and substitute out the plain text letters for the cipher text letters. We can do that any way we want to and it's still considered a substitution cipher. For example, we can randomly assign cipher text letters to plain text letters. Let's do that now. Just pick some random letters here like l and then j, a, q, r, b, and so on. We can keep going right on down the line and then we would follow the mapping from plain text to cipher text. So if I, for example, wanted to encrypt the plain text letter c from my message ncssm, I would go to the plain text row and look down and realize that c got mapped to a. So my cipher text letter would be a. So while we can do it this way, it's not great for practical use. It'd be really challenging to let the person receiving it know what the mapping was. We actually have to kind of give them the full on plain text alphabet and cipher text alphabet mapped out. And that idea of exchanging the key is difficult. Remember, one of our goals on cryptography to the side of its valid system is that we should be able to remember the key in our hit, no writing it down, no passing in the note. So this is certainly not going to meet that criteria. So we're going to look at a lot of different ways to create these mappings over the course of the week. Some of them are going to be a lot more structured than others. So we're going to learn about algorithms like the Caesar cipher, multiplicative cipher, affine cipher, we've already learned about the add bash cipher. All of these are just different methods for mapping plain text to cipher text. And all of those methods have some sort of mathematical component that we'll focus on when we cover each one of those algorithms in turn. For today, we're going to focus on a kind of a non mathematical way to do this. And we're going to we're going to focus in on using keywords to generate mappings. So our keyword is just going to be a word of your choosing, it could be a keyword or even a phrase. I'm going to choose for us since our plain text messages NC SSM. I'm going to have our key be the word unicorn. And the way that we can use a keyword that generate our mapping is that we can start at the beginning of our message, taking the first letter of our keyword. And moving on down the line, using each letter in turn. Now, the word that I chose happened to have a repeated letter in it, unicorn has two ends. So that could be confusing, we don't want both plain text letter B and plain text letter G being mapped to the same cipher text letter of N. While that wouldn't be a problem when we're encrypting the message, you can imagine if you are the one receiving the message, and you saw a capital letter N in your message, you wouldn't know which of the plain text letters that came from. So again, thinking back to what do we need for our encryption scheme to be valid, we need to be able to undo the message. If we can't decrypt it from the cipher text that we have, we're going to be in trouble. So we need to find a way to fix that. Now, the way that we can do that here is if you have any repeated letters in your keyword or key phrase, we're just going to skip over every occurrence of the repeated letter after the first one. So if I had multiple occurrences of N, I'm only going to keep the first one and then keep moving on. Now, you might also notice that this is a relatively short key phrase, it doesn't help me with the mappings of the rest of the letters, only the first six, not the last 20. The way we can get around that is we just now go through the remainder of the alphabet starting at the letter A, and we include now every letter we haven't already used. So I would do A and then E, I already used C in Unicorn, so I'm going to skip over it, and then D, E, F, and so on. And you might notice the issue with doing it this way, even though we get a nice mapping kind of early on, once we get to the end, since U, V, W, X, Y, and Z are relatively uncommon letters in the English language, you're going to frequently end up with these last five or six letters being just mapped to themselves, which doesn't do a great job disguising your message. So we can get around this in another way here, but let's just hold off on a minute. Let's actually go ahead and encrypt using this one. So our plain text message of NCSSM would now become the ciphertext message of J using this right here. C gets mapped to I, S gets mapped to Q, and M gets mapped to H. So there's our encrypted message. So let's go ahead now and try and get kind of find a way around this issue over here of having a lot of letters getting mapped to themselves. So it's not an issue of just one or two do, but when we've got a whole bunch that get mapped to themselves, it's not going to do a good job disguising your message. So let's clear this out. We'll keep the same keyword, but let's add in, we can call this an offset or maybe a key letter, we can call it either way, but instead of starting unicorn at the beginning of the alphabet, let's pick a place to start it later on in the alphabet. So let's have our offset or key letter be the letter S. So what that means is I'm going to start writing my keyword underneath the letter S. And we'll follow the same rules. Don't repeat any second or third occurrences of a letter just the first. And then we'll also continue in the same pattern we did before. We'll start back at the beginning of the alphabet A. And we're going to write every unused letter underneath the next letter in the plain text wrapping around to the letter A when we got to Z. And I'll go ahead and fill in the rest here. And you can see now that we've gotten this mapping, we have very few letters that map back to themselves. In fact, looking it over, I don't think we have a single letter that maps to itself. So this is a nice way to generate a mapping between plain text and cipher text. That's pretty easy to describe to somebody. You tell them the keyword is unicorn, the offset is the letter S, or the key letter is letter S, and they'll notice shift that keyword into the right spot and they can generate the mappings. No need to write it down. You're good to go. Using this system, our plain text message of NCSSM, NCSSM would become V F U U T. So as I said at the beginning, there's a lot of ways we can create this mapping. This is not a very mathematical one. In the next lesson, we'll learn how to use some simple arithmetic to create some mappings, even easier than this. But one thing to keep in mind is that there's a lot of ways that you can do this. While these ciphers are very simple to execute, there's a lot of possibilities, and that's where some of the security comes in. If you think about it for the first letter, if you were to think about the plain text letter A, we've got 26 choices that we can map that to in our cipher text. And then we've got, for the letter B, 25 choices, since we can't repeat whatever letter we chose to go to A. And then for C, we've got 24 choices, and so on, down the line. If you want to think about how many total ways we could do this, we need to take the product in each of those numbers. And that number is 26 factorial. Well, that does not appear to be very long. When you take the product of all 26 numbers between one and 26, you get a crazy big number, something along the lines of 4.034 times 10 to the 26. So there's so many possibilities using this method. What we'll see is that in order to actually get access to all of those 26 factorial possibilities, they're not all going to be easy to remember or implement. So while in theory, there's a lot of possible kind of mappings in practice, we're not going to really use many of those. So that's it for now. You should be well equipped to handle substitution ciphers using your keyword in an offset. The next lesson, we'll take a look at using addition in the Caesar cipher to generate some easy to remember mappings. We'll catch you on the next one. Thanks for watching.