 In this lesson we're going to be learning to upgrade our cryptographic methods out of our mono-alphabetic ciphers, like the Caesar, multiplicative and affine, to poly-alphabetic ciphers, such as what we're going to see here today using the tabula recta. Let's learn a little bit why this became so important. So a little historical context here. By the time we got to the year around 1700, this crypt analysis that we have been doing in the past couple of lessons, this frequency analysis, had become really commonplace, particularly among governments in Europe. In fact, many governments, most notably in Vienna, Austria, set up what were called the black chambers, where literally every piece of mail coming in and out of the country would end up in one of these government rooms where they would open them up, every piece of mail, copy them down, reseal them, and then send them back out often as little as just a couple of hours for that entire process so that the receiver of the mail didn't even know it was happening. And when they encountered an encrypted message, they passed that along to their intelligence team, where they would work in unison to quickly decrypt and store some of the secret information that was being passed through. Now, not only was this helpful for the governments to have information maybe about what other countries were up to, but also their diplomatic messages, all of those things, they had them, they would keep them, and they would often even sell them for a profit. So you can see that this idea of knowing that the government was reading all of your messages became probably unsettling to other countries who are trying to get messages to their ambassadors in Austria. So they needed to upgrade the cryptography that they were using to a new level that would be unbreakable by the government workers in these black chambers. So just like we saw happen in Europe, but also like we've seen in the last few lessons, the ciphers that we know and love so far are pretty much dead. Once you've mastered frequency analysis, and especially today with a modern computer, but even back in the 1700s with a team of mathematicians and cryptanalysis, even the most sophisticated mono-alphabetic cipher could be cracked in a reasonable amount of time. And mono-alphabetic just means that for every plain text letter that you're working with, it gets mapped to one and only one cipher text letter in the alphabet, and that's consistent throughout the entire message. So what could be due to improve it is to go to a polyalphabetic cipher where sometimes a plain text letter, maybe the letter B, sometimes that goes to a one cipher text letter, maybe Q, but other times it goes to a different cipher text letter, Z. Now, that might sound like that's a bad idea. We saw that happen with bad keys with our multiplicative ciphers. But the reason it was bad for a multiplicative cipher is that once you have the cipher text and you saw those two different cipher text letters, there's no way to know that they were which which plain text letter they got mapped to. This new system we're about to look at will have a built-in mechanism for us to know that when we see these cipher text letters that it could possibly go back to the same plain text. So this is going to be a nice upgrade and we'll see helps disguise some of the frequency analysis that we've come to learn. So this first started with Leon Battista Alberti back in the 1400s was the first person to ever come up with this idea of a cipher disk that we see in the lower right hand side of the screen here, where you've got your plain text and your cipher text rings. The way that this would work is that you would agree upon an index ahead of time. So in this example, it would be the lowercase letter G. And then you would move that underneath a particular uppercase letter on the outside ring. And this example is lined up with letter A. And now you've got your mapping between your plain text and your cipher text. So for example, if we were to kind of lay out the mappings here, our stationary disk, which is the outside ring is ABCDEFG and so on. And then the movable disk would be GKLNP and so on. And there's your mapping. The numbers we don't really see in our ciphers today, but Alberti here even had a plan for these numbers to be used with a code book where if you had like the number 231, you'd have to look that up in the book to figure out what word that took place. So we're not going to worry about those for us. We're going to keep working with just letters, but just a little historical side there. So the beauty of the disk is not just for creating the mappings, that's still just a mono-alphabetic cipher by itself, but that it included a mechanism to change the mapping at any time by moving that lowercase letter G to somewhere else in the message. So you might write your message out like this. If this is your plain text, he kind of flipped it. Alberti here did the plain text with uppercase. I know we do ciphertext uppercase, but roll with it here. Those underscores are going to be placeholders for where you would indicate where you're changing the ring location. So when you create your ciphertext, you would start with lowercase G under capital A, so you would write that down. And then you'd write your ciphertext Z, G, T, H, and so on using that mapping. And then you would flip around the ring, so you'd move that lowercase G somewhere else and you would write that in your ciphertext. So that capital letter Q is indicating where your index would go. So the lowercase G rotates around to underneath the capital Q, and then you continue in ciphering with a brand new mapping. So because you're flipping around that mapping over and over, you'll find that the same plain text letter, in this example, R, can be mapped to two different ciphertext letters in the message. But the person decoding the message would actually be able to kind of have a matching ring and flip around the mapping on their ring to correspond so that they don't even have to really think about it too much. Those two different ciphertext letters just end up going back to the same plain text R when they're decoding it. This idea of flipping around your ciphertext to plain text mapping throughout your message will help disguise the frequencies of the letters. If sometimes your plain text letter R goes to M, and other times it goes to K, and other times it goes to maybe like Z or X, you're going to see that you're going to really smooth out that distribution of ciphertext letters because it's not going to keep the same percentages that we would see in the English alphabet. This is really powerful. Somebody else built on this a little bit later. You'll see the years overlap just a little bit. This was a Johannes Trithemius, and it was not very sophisticated. It didn't have the nice rings or anything, but it did make it a little bit easier for us to lay out here in a grid system, which we'll see is helpful for us to think about when we get to programming this. He had this grid essentially wrote down every mapping from top to bottom, but you can also see some nice patterns here in the grid where every row is offset by the row previous to it just by one spot. So you can kind of see along diagonals here the same letter showing up over and over and over. We'll look at how to use this in just a moment. Let's see the way that Johannes Trithemius used this, what he called the tabular recta, this kind of table, square table basically. He didn't use it very sophisticated. In fact, his method was what we'll see is not very good, but it was the foundation. This one in the Alberti ring where the foundation for what is known now as the visionaire cipher, which we'll learn in our next lesson, which was kind of the gold standard for encryption, and it lasted almost up until the late 1800s. So really good method, and we'll see why it's so good in the next few lessons. Let's see how he would use this tabular recta. So you can see that the table that we have here has kind of a top row and a first column that are set apart from the field or the inside of the table. That top row is where we're going to look up our plain text letters, and then the first column along the left-hand side is where we're going to look up our keyword letters, and then we're going to follow them to the intersection to find the cipher text letter. On the left-hand side of the screen we've got our plain text message, something very simple, just my secret, and then we've created a key that goes over the top of the message. Now notice the key here is a sequence of characters. It's not just a number or two numbers. It's an actual kind of string or a text phrase. Now, this is the way that Tritimius did it. Pretty boring, just kind of the standard alphabet. A is my first key for the first letter. B is my second key for the second letter and so on. But there's a myriad of ways that we could set up that key on the top, and we're going to see that's where the real power on the system comes in is how we set up that key. So for now it could be any letters, but we'll talk about better ways to do it in our next lesson. Alright, so let's encrypt the message using the key A, B, C, D, E, F, G, H. The way it works is that you're going to look up your plain text letter in the top row and kind of think about that whole column of letters underneath it. And then we're going to look up the letter of the key that's above the letter M in the message. So in this case we're going to use the key of A. Those rows and columns that we've highlighted intersect at the letter M, and that letter M is our cipher text letter. Now mathematically you could think about it a slightly different way, is that we had our plain text of M and our key letter of A. Numerically they have the values of 12 and 0, and we add them together to get our cipher text number of 12, which maps back to M. Very similar to a Caesar cipher where M is our plain text and A is just the key value. So this is basically a little mini Caesar cipher we're doing on one letter at a time. Alright, let's go on to the next letter. So we would take our plain text letter Y, think about that column, our key letter of B, find the intersection of Z, and that's our next cipher text letter. Again, it's like a little mini Caesar cipher, Y plus B, 24 plus 1 gives us 25, 25 is the same as 25 in Mod 6, so there's our cipher text letter of Z. And we can kind of keep doing this, these kind of mini Caesar ciphers to get the next letter of U, the next letter of H, and so on to kind of build out our cipher text here one letter at a time. You can see it's very methodical, very algorithmic, so very good for setting up perhaps in code in just a little bit. So there's the encryption process. Let's take a look at the decryption process. Very similar. Here is another way we could have picked a key, so we've got a shorter message here, five letters, H, A, X, K, O, and the key is just kind of alternating between two letters, D and then K, and then D and then K, and then D until we fill up the whole cipher text. Very similar, we just kind of work this process kind of in reverse. We're going to start by choosing the row for our keyword letter, and we're going to follow that across to our cipher text letter of H, remember the cipher text letters are always in the middle, and then we're going to follow that up the column, which gives us a letter of E. So there's our first letter in plain text. Now, again, mathematically, maybe you want to think about that as your cipher text minus the key. Again, kind of like undoing a Caesar cipher, we're going to take our letter and subtract off the key. So seven minus three gives us four and four corresponds to E. We're going to do one more using the table. So we find our key letter of K, go across the row, find our cipher text letter of A, and follow it up to give us the plain text letter of Q. Mathematically, that would have been A minus K or zero minus 10, negative 10 mod 26 is 16 and 16 corresponds to Q. I'm going to finish this one out using the mathematical method. So X minus D is 20, which corresponds to U. K minus K is 10 minus 10, which is zero, which corresponds to A. And zero minus D is 14 minus three, which corresponds to 11 or the letter L. So there's our decrypted message equal. That's it for the tabular recta. So the system itself is very straightforward, but we're going to see, as I alluded to earlier, the power of the system doesn't come from the table itself necessarily, but it's this changing of the key from every letter. That's the first part. And the second part is how do we choose the keyword? We're going to see that some keys are better than others at disguising the frequency of our plain text letters in the ciphertext message. And we'll see that some keys are better than others when it comes to cryptanalysis and trying to figure out what is that key if I don't have it. So we'll look at all of that and more in the upcoming lessons. But remember, the overall theme is that changing keys is good for security. How you change the keys is important. And that it's going to lead to a stronger message created using a polyalphabetic cipher.