 In the previous video we introduced the idea of the Caesar Cypher and talked about how one could encrypt messages using this very fundamental, symmetric key cryptosystem. But we also mentioned the great vulnerability of the Caesar Cypher. The Cypher is only as effective as the size of your alphabet and 26 letters is way too small that it's vulnerable to a brute force attack. Even if you could increase the number of characters in your alphabet to be hundreds of characters, that's still going to be insufficient for a computer to brute force all the possibilities. We need our modulus essentially to be hundreds of digits long. I'm not talking about hundreds of characters. The number of characters to be hundreds of digits to truly be secure from computer brute force attacks. And so therefore we need a lot more possibilities than just what the alphabet provides us. So what we're going to do is we're going to increase the Caesar Cypher to what we'll commonly refer to as the Affine Cypher. Which the Caesar Cypher, it follows the basic idea that X, we'll think of as a number we're trying to encrypt, we'll replace X with X plus B, some shift to it. The Affine Cypher is going to improve the number of possibilities by taking X and we're going to replace it with AX plus B. So we're going to multiply X by some value A and then we're going to add a shift to it as well. So we're going to basically stretch the value and then add to it. This is called an Affine Cypher because we're performing an Affine transformation like you might see in linear algebra. Now if A is chosen to be co-prime to your modulus N, then you can divide by A. We know that A inverse would exist. And so then we can solve this equation. We can solve it for Y. So if Y equals AX plus B, then we subtract B from both sides. We get AX equals Y minus B and we divide both sides by A. So we get A equals A inverse Y minus A inverse B, something like so. And therefore we can decrypt this process. And so that adds a lot more possibilities. So beyond just your modulus N, your number of possibilities is going to be phi of N times N. Where phi of N here, this is Euler's totient function. So you get phi of N times N. So it's going to be much more secure than the Cipher method without that. And so if you take something like, maybe you're going to times by A and you're going to add three. And so what would happen to the message algebra? Let's take a look at that in magma right here. If you've been following along with this in the series here for magma, the magma code, you can find from the link from GitHub in the message description here. In order to do this encryption, you have the Caesar encrypt and the Caesar decrypt commands in your compiler. You also need the supplementary procedures of alphabetize and digitize. So you can turn letters into numbers and vice versa. So we can see some messages we had from before. What we're going to do, showing you what's going on here, just erasing this code. So we want to encrypt the message algebra, I believe is what we wanted. I'm doing lower case, the previous was uppercase alphabetize and digitize. They don't care. They're not case sensitive here. So if we encrypt using A was five and B was three. If we run that, we're going to get the message DGHXIKD. Great. And so if we want to decrypt it, then we're going to run Caesar decrypt. We plug in E, the message we have there. And we have to use the same key five and three. And so when we run that, it's going to give back the original message algebra, which admittedly switched everything to uppercase. But that's something we definitely can live with if you can pick a different key if you want to. So it's going to be much more secure than the Caesar cipher. Now I should mention that the affine cipher in terms of professional grade photography, of course, it's going to be pretty. It's going to be still pretty elementary there that even with 26 letters of the alphabet. You're going to get 26 times fee of 26, which fee of 26. That's just the same thing as fee of 13. 26 is two times 13 there. And so that's going to give you 26 times 12. And so, you know, if you look at that, that's going to give you a couple hundred possibilities. So it definitely would be very difficult for a human to do this by hand, but a computer is going to be able to exhaust these possibilities very quickly. So the idea is perhaps there's an encoding process that we can use larger, larger modulus in this consideration. And the answer is, yeah, our encoding process for this lecture is very, very naive. And there can be ways of doing it so that we get a much, much larger modulus from the encoding process itself. So for a large modulus, this is a great improvement over the Caesar cipher because the, because the number of possible keys can be too large to be brute-forced, right? Unfortunately, this is still considered a weak cryptosystem for the following reason. Since different characters in the language, in a language, appear with different frequencies. So for example, if you're in the English language, just using the language I'm speaking right now, I hope that's English, the letter E, for example, it shows up in a random word with a probability of 12.702%. So about 13% of all letters in the English alphabet are going to be the letter E. On the other hand, if you look at the letter X, this comprises about 0.15% of every letter in the English language. Now, admittedly, if you're using X as a spaces, then that's going to change the frequency as well. But we can make these considerations or you can consider these things. And so using the frequency of the letters in a language and a little bit of guess and check, a computer could very easily decrypt anything from a substitute cipher where by substitute cipher, what I mean is every letter is being replaced with a different letter. This is sometimes referred to as a mono-alphabetic substitution cipher. So if you replace letter with letter, like so X is replaced with Y or something like that. The frequency of letters is too valuable of a tool for e-droppers to attack that type of crypto system. So one thing you could do is you could improve the function digitized that we've introduced earlier and you could try to avoid frequencies by using numbers maybe to represent pairs of letters or triples of letters or things. So instead of coding one letter at a time, a mono-alphabetic method, you could try doing something like a pair of letters is then encoded where you could do a substitution like that. That gives you a lot more possibilities and that makes the modulus much, much, much bigger. Now admittedly, these are not without vulnerabilities to frequency attacks as well. You know, because for example, the pair th is much more frequent in the English language versus the pair qx. I don't know if that ever appears, right? And so again, there's some frequency issues that can come into play here. Fortunately, there do exist much more sophisticated digitization processes to protect the ciphers discussed above, but that's going to take us beyond the scope of this lecture series. So what I'm trying to say is that one could implement an affine cipher in practice if the encoding process is sophisticated enough to guarantee a large modulus that if the modulus is big, big, big, then the idea, the brute force technique is not going to work. And so then Alice and Bob can have some security and that Eve cannot trans, or cannot decrypt their message because she doesn't have the key. And without the key, just guessing is never going to work. But again, there's a lot more to this that we're not going to talk about because I just want to give us, to give the viewer here an elementary introduction to these symmetric key cartography type topics, particularly how they are relevant to algebraic problems we've talked about before, such as the Caesar cipher and the affine cipher right here.