 Okay, so, second week Thursday? Thursday? Yeah. Cool. Awesome. Uh, our role came out on the crypto. Here's a few minutes to get back into the swing of things. So, what the heck is cryptography? So, what's the purpose? Cool. So, yeah. So, we need some kind of confidentiality guarantees. So, we want some kind of guarantee that when we send a message to somebody else, that anybody can see that message through the comments. Yeah. Cool. Okay. So, as I think we, where we left off is we were talking about kind of classical cryptography. So, this is, um, what we're going to talk about, and we've discussed this in terms of the Caesar Cypher, but essentially the key thing is the sender and receiver share a common key. So, why is this, is this a feasible scenario? Yes? How do you share keys? What are the requirements here? Yeah. You can meet up and tell people in person, what is, why can't you just, so you want to send a message to somebody, why don't you just send them the key? Because that can be intercepted too, and then what happens? Then they get not only that message, but every other message you use using that key, right? So this is one of the key things to think about and one of the key, and sometimes the weakness of classical cryptography is this sender and receiver must share the common key, also called symmetric cryptography, which goes into, well, we're going to get to asymmetric cryptography. But this is really the key idea here, and what's really important. Um, if, I assume it used to be thought that this was the only way you could ever do things, right? It seems very counterintuitive how can you and I share a secret if we don't also share some kind of key, some secret sharing for me. So actually, when we look at asymmetric crypto, we'll see that it's actually really cool because it gets around this ability. Cool, okay. So, we talked about different types of cypress, substitution, which when we looked at with the seizure cypress, we substituted one character for another, one letter for another, and transposition where you shift things around and move things in different orders. Putting these together in complex ways makes product cypress. We'll look specifically, we'll look at a number of these types of different crypto systems. So we've already looked at one type of substitution cypress, and that is the nice seizure cypress, right? So, somebody in mind, do you want to do seizure cypress? Yeah. Shifting over the letters, if you don't want their normal name. Which letters? Perfect. Yeah, the letters are the alphabet, right? This is an important thing, we're not shifting the characters of the message, right? We're shifting the alphabet itself. So, as a substitution cypress, right? So we're in the message hello world, we're going to substitute for h some new value, or associate key some new value all based on the key. The key is three. We would shift it by three. So what's this message going to be then? E, I think these are barbaric. Wait, A, E. H? H. I'm not going to do this. You just want to interview, I'm sure somebody do this. O, O, Z, R, U, O, O, E, G. Shout out letters until you get it right. Cool, okay, so. And you think in kind of simplistic terms, right? Maybe you can see, well this is actually pretty like, if you just intercepted a message that said this, it seems like the meaning is pretty well hidden, right? But what are some things that are not hidden? So you mean the two letters that are, have to share like the O's, they have to share some of the common stuff. Yeah, so that we know, so two common interesting things, right? We know that the, let's see, even in this small text, there's one character that occurs three times. Right? And why do we know that for a fact? Right, because we've shifted the alphabet so the letters remain the same. So we know this O, if we don't know the key, we just know it maps to some letter in English, but we know every instance of O maps to that same letter. So we know that in the original text, there's three of the same letter. Then we have, in some sense, other things we can infer, that we have actually two letters together. What tells you more information? Useful information? Right, so you can think about different types of statistics, right? We'll talk about this in terms of what they call n-grams. So specifically one gram would be how many letters, like what's the frequency of each letter occurring in English? Two grams would be what's the frequency of one letter followed by another letter. So it's the frequency of A followed by A, A followed by B, A followed by C, all of that, and you can calculate that over a vast array of English texts to get really nice things. So you can see there's also limits, maybe what words you could possibly be, or lots of different kinds of things you can infer from this. Great, okay, cool. So attacking the Cycler. So now we're going to attack this. How do we do it? We've talked about already some methods. Let's bring some more. What was it? Brute force. Brute force, yeah. Why is that a really good first answer? It's not very cross-laxed, right? It's easy. There's actually a tip you should take into, I see some of you are wearing ties in the collared shirts. I'm sure you're not just dressing up for this class. Probably a career fair going on. We also can tell at Microsoft that some of you were wearing nice shirts. They were there to interview. And you can tell that. But when you're being asked how to solve a problem in an interview, often times what people can do is they freeze up and they start thinking about what's the best possible solution to this problem they're escaping, right? And when the interviewer is sitting there waiting while you're doing some thinking, you're waiting, waiting, waiting, when oftentimes what they want is a dialogue, right? So they want to see you iterate your way to a better solution. So a better thing to do rather than just be silent and not say anything, is always engage with your interviewer, maybe try to be able to intentionally give you vague questions to say, oh, how do you write a function that does this? And they want you to refine it and say, well, what parameters are we talking about? What's the size of the input? Is it in the order of gigabytes, terabytes, petabytes, or is it in the order of kilobytes, right? All these types of things. Do we have to worry about no pointer, what language are we working in? All these kind of things help refine the problem. Other than that, you can go with the dumb, simple brute force approach. You can solve most problems in a very dumb, straightforward way, right? Just like this. So could you write some code that queries over all possible Caesar sites or keys if this was like a whiteboard question? You can just say, so I... Yeah, everyone knows, like, you know, do a for loop, you loop over to that, try to see what the output is, and then only 26 options, you just print out each of the outputs and have the user pick which one is correct, right? You don't even need to do anything smart, right? You can just do the dumb thing that works. And then they're going to say, okay, great, what are the problems with that approach? So I'll ask you, what are the problems with this approach? You came up with the approach you can't answer. What was that? Time? Who's time? Computer's time, yeah. So it depends on the size of the key space, right? So we're talking here about attacking the Caesar Cypher, but we also want to think about attacking other types of crypto systems. Here, Caesar Cypher only has, let's say, 26 options, right, of characters. But what if instead of the alphabet of plain text being just A through Z characters, what if it was, let's say, all possible bytes? So eight bits. How many possibilities are there there? 256 possibilities, yeah. So your key size could be much larger. It may be computation size, and then you also have this problem of how do you know when you've found the correct solution? Right, so you're going to output 256. And then what if I expand the key size more? What if I operate now on 32 bits? How, what's my key space there? Two to the 32? Oh my god. Big number, something like four billion, something like that? Anybody know? Max for the math person, he'll study this stuff. Two to the 32. I don't know that, I'll stop here. Yeah, better key. I don't know either, but I think it's around four billion. Anyways, so this should always be your default domino approach, right? Try all possible keys. As we look at different crypto systems, this is the type of crypto analyst we want to do, or crypto, yeah. So, trying to bring a crypto system we want to look at, we should look at, hey, can we just try all possible keys? Because in that case, then we're good to go, we don't have to worry about anything else. Okay, what other techniques we can try? Have it ordered be kind of dictated by like the most common letters. So like you look at the, like you maybe need to read the first one, and you look at the most common letter and it'll just read that you have. So rather than being, in some sense, rather than just doing a dumb group more so than the entire key space, right? We could maybe selectively try different keys based on what we think is a likely good key. And one of the things we can use to guide that is what's the most frequent letter in English. Right, so we can use statistics, so going back to our example. So we see that there's three O's in this plain text. Would it make sense to try the, as our very first guess, whatever maps O to Z? Why not? Z is probably not a common letter, right? In English, similar with X maybe. And then we think of what's likely to have two in a row. It's probably not, you know, we can think of other statistics, right? So we can use those to help guide our search so that we can efficiently look through the search space. So this is going to be, and this is what we're going to look at when we talk about grams. So this is just being letter, like one gram. So just looking at the frequency of one character in English. Okay, cool. So now we've got this. What is this? Framing, right now. Could you do it? What information do you need? The amount of chips that you're looking for the key? Is it a word or a phrase? Is it a word? Is it a phrase? Who knows? It'll just rank all 26. Yeah. Cool. I mean, you are free to do whatever you want in class. So if you want to do this, I think that's totally fine. But let's say you want to break it using statistical attacks. How would we go about that? Okay. Yeah. And what does that involve? So the dictionary. Counting, dictionary, right? Just count. You can go through. This is something you can do with kind of paper, right? Much easier. We don't have a program. We already have a program, so we don't have to use my hand. So you compute the frequency of each letter in the ciphertext. So the frequency, what are we specifically computed? So one thing we can look at is the number, right? The number out of the total, right? Why is that more useful than just the raw number? I told you there was, let's say, 25, well, ignoring this ciphertext right here. But if I said there's 25 occurrences of these ciphertext letters, A. Is that useful information? Any number that has the same rate with appearances and number that you found that you could more like repeat that? Why is the rate important? Yeah. Because it could be just like a book and 25 days isn't that much. Right. So it could be a book's worth of text in which case 25 days is, maybe it could be Z, right? Because that could come up depending on if we have, you know, 100,000 words or something, right? Right. So you standardize it so it can accurately compare. So you can do that here. So that's key kind of hidden in this word frequency, right? Is the occurrence of the letter divided by the size of the number of letters in your ciphertext. So I'm highly confident you can all do this. You can even write a program to do this. So we'll do something like this where you can say, well, and this, and then, you know, here we're ordering it by frequency. So it should be the case that the most frequent letter is B and then E and then Q, U, J, F, so on. Is that right? I think B, H, L. I'm going to read it. And then it's this way? Yeah. Yeah. Okay. Okay. Sure. It goes left to right. You've got the bottom. B, H, L, E, Y, R. And then what do we do? Boris, B, L, F, G, R, and R are considered to be the top. Yeah. So compared to, as I said, even at a higher level, right? So it's clear we're making it something that this is English characters, right? If this was a different language, we'd need to treat it differently, right? So we're using some information about what we think the language is. Yeah. So we just say distance. What are you talking about? Like, any of the ciphertexts itself? No. We're not talking about the e to i, just the b and b to e is 3. We may have this counting, but we can do something like that with two other frequencies. Right. We need the frequencies, right? So we need something to compare this with. So we have this frequency, right? We need to compare it with the English frequencies. So, where do you find this? Google. Yes, Google's a good resource. If you go to Google, you would find something like this. You can see I literally put this from Wikipedia. This character frequency of all that letters a to z in alphabet. And the most frequent is, what is that, e? And then t. But how do you create this on your own? Yeah. You can build a program that takes some like a giant input. And then you just do the same thing. And just count, calculate 3. Yeah. This is exactly the same thing we did in this. Right? Just counting. Right? So you can do this. So what types of things do you use to calculate this? Oh, a dictionary. Interesting. Yeah. Do you want to take a program that will take a little, I think it's going to feed a bunch of books progressively and easily how the books go from. Yeah, interesting. I would say a dictionary. I would, that's interesting. I would say that a dictionary is very biased, right? Because it literally includes every word. I mean by definition, right? So it has some bias there in the frequency of words. Of course, in each of the definitions of each word, you would have, like, that would probably reveal something. So in some sense, it kind of depends on what the language is in some sense, right? So you could use, people talk about books. You can get free text books through, what's that, common? Something I'm thinking of? You know? Do you know? Project Gutenberg? Yeah. Project Gutenberg has a bunch of, that are out of intellectual property. So they're open source. Not source. Open rights. I'm trying to say. Great. Great. So great example. So what, so there are, you know, what you're trying to do is essentially build this frequency based off of single, right? So all you use was Charles Dickens books. Right? Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. Yeah. So you have to build a frequency based on Charles Dickens books, which you can use that free online and you can find them. Right. But the language is maybe more modern English. What would maybe be some problems there? Yeah. Yeah. So if we have no plain text, right? And this is actually what, when we studied, I mean, talking about in historical context in war, they obviously have to know the target language, right? So you need to know like slang that they use, We know who it's from, and we like to get older text in written. Like in Caesar's play of speeches. Yeah, so if it's, yeah, that would be great. So we can send scribes to Caesar's speeches or the letters that he writes and we could use those to get frequencies. Yeah, these are all great because we're now tailoring our attacks specifically to an individual in the context that we care about. Cool. Okay, so you can create this. This is not a fantasy main, I don't know if this is just handed down. You could actually calculate this stuff if you wanted to, yeah. So I have a question. Does this apply no matter how large the sample text is? Or does it seem like sufficiently large? Interesting. So, yes and no. Maybe both. It's, we'll look at different measures we can use to kind of in some sense test that. So you can think of, the problem is basically like a statistics problem, right? So here we have some letters, right, that were drawn originally from the English alphabet in the formal words. And now we're looking at those ciphertexts. But how many letters is this? Can anybody count really quick? What, 25, maybe 30 letters? So, and depending on what they're talking about, they're talking a lot about xylophones and other types of things, right? Yeah, 32 characters here. So yeah, our guesses may be wrong. So we have to keep that in mind because there's errors and bias in here. So we need to try to keep refining down to what we can. See what the standard deviation is from with the smaller text. So on average, how much does the smaller text vary by from the actual averages? And then you use your standard deviation to start with the middle. Let's say, oh, this is most likely going to go out or by your regular variance. Interesting. Possibly. I do call all that, but I think I have to do analysis. Yeah, you can definitely do more types of analysis. We can also use, right? So what we can do is essentially the idea is we're going to calculate for all the possible keys. So now, in this sense, we're going to enumerate the key space and try to determine what's the most likely key based on these frequencies. So this is actually pretty simple. What we're going to try to do is calculate just the measurable keys, right? C from 0 to 25. And characters, sorry, characters and says, what's the frequency of that character in the ciphertext and what's the frequency if I shifted that character into English? We'll sum those up. So this gives us a very nice... So for instance, I would get something very low if the frequency of the character in the English when I do the shift is very low, like zero, right? It will add very little. So it doesn't matter what the frequency was in our ciphertext. This will give us a very simple measure for then calculating and we can calculate all this. Then we can sort it. And so we can see that on this ciphertext in kind of decreasing order, we can see what our possible solution is. And of course, with you in mind, it may not be exactly 23 or 13 or 7, right? To actually do these run this to see what the actual shift is. So this is our original cipher. We take it to 23. What's it going to look like? It's going to be easier to make an A3C and just start counting. What was it? Just shifted back three letters. Yeah, C or this is the problem of the month, right? So we shifted in a certain way. So the interesting thing is this actually matches English text. Like the frequency character is the best of all our samples. Of course when we have 32 characters to work with. Is this the message? Probably not, I probably don't. Doesn't make any sense. Doesn't make any sense. There's no actual words in here. Once it's like really cryptic slang, you have massive problems. Okay, 13. That was when we shifted to 13. Yeah, so we shifted like halfway basically. So first letter. Keep doing this. This is probably the key. And we can keep doing them, right? So we can see that this makes no sense either. Bring the cipher with us and play three tries. So let's get it. Okay, so do you want to explain to us how that formula works? Like edit this thing in addition or whatnot? Yeah, so the basic idea comes down to this graph. So essentially what you have here, do you have enough frequencies for all the characters? Right? And so if you were to then draw, I will try to attempt to do it. If you were to draw the frequencies of the actual characters here, so like B is very high frequency, so B is, okay, I'm going to have to look at very small letters. So we have B was 1.5, so B is like here. Next we have E, which is right about here. No, no, H, sorry. H is 1.2. I'm not going to keep drawing this. I'm just going to stop at a certain point. Okay, so basically if you put these graphs on top of each other, right, you can see the different frequencies. So the idea is you're computing essentially how well do these match each other, right? And at what shift do they match each other? So if it was, and so essentially what you're doing is for each of, if I move it over it's going to not work, so I will draw this again. Some C equals 1 to 26. Frequency of C times, that's a multiply symbol, C minus 5. Okay, I is the character shift. Okay, so this probability of C minus i is you shifting your ciphertext into a different alphabet, so you're shifting each of them in there, and you're measuring how much do each of these letters match up. I look at the entire derivation of this formula to remind myself exactly why it works. We just take your worth more, basically. You definitely can't. I take other people's worth more. I look at these differences, right? Yes. Yes. The shift that minimizes the difference between all the characters, right? All of ours, yeah. Cool. So what were some of the problems? Could you use that same method if you were to write the cipher to shift alternating letters to different methods? Right now we're shifting the whole message one of them. You could say shift the first letters 26, shift mod 2, 13, shift mod 3, 5. So then you have the system shifting every third letter of a different number. Every third letter of a different number. Time on this for the point right now. Okay, so what were some of the problems that the ciphers? Yeah. It's really easy to break. Yeah, why? Because you only have to try 25 different keys. The key is too short, right? If I'm not going to do the key too short, that's very, very clear, right? We can find it by exhaustive searching. What else does this mean because the key is very short? Can we guess? So we can guess it really easily? Yeah, so then what other problems does this have then? So one thing we can brute force all the keys. What else? Yeah. It doesn't obfuscate what the original alphabet was? Yeah, so it doesn't. So if we think about that, I don't like to think about it in terms of graph, right? We look at that graph of English frequency characters. All we're doing is shifting that graph one way or the other, right? But that graph, those frequencies still remain in the remaining text. Yeah. I guess I'm not going to dispute the length. It's sort of the same. The lengths? Yeah, so the length of the plain text is sort of the same, although you do have some problems like how you go back at the length. If you make it bigger, that's fine, but where did that information come from? Yeah. Yeah. Yeah, you can break it very quickly because of the statistical. So the other idea is that statistical frequencies are not concealed very well. So what if we made the key bigger? How do we make the key bigger? Do we expand the number of characters? Still though, let's say we expanded it to uppercase, lowercase, and numbers. What was that? 52. 52? Sure, go with that. Twice as much. That good? Yeah. Yeah, so maybe that would be interesting. So we could take that alphabet and scramble it. So essentially created a mapping of characters from one character to another, a unique mapping. Here, your key would then be rather than just a shift, you have to give somebody the alphabet, which is essentially a key per letter. Now, a little bit difficult to do because you do it when you do 26. You need that key, right? Exactly what character maps are what. Cool. So historically, the key, well, let's fix it. Let's make the key longer. And in some sense, the idea is let's add multiple letters to the key. So the key can, let's say be as many letters as we want. So let's say it's three letter long key and we just keep repeating the key and then we shift every first, the first letter of the cybertext by the first letter of the key, that many amount. We shift the second one by the second key, the third by the third of the key, and the fourth by the first of the key. We'll see an example of this very quickly. Essentially, the idea is smooth out the statistical frequency. So smooth out that, so that instead of just shifting this whole statistical frequency in one direction or the other, let's smooth it out to make it more difficult. Okay, now I will try to pronounce this correctly. I checked with somebody who's from France. The vision of the air-cycler is where I land on this. So again, a person's name in France who came up with this. The idea was similar to see-through-cycler but used a phrase or a word as the key. So we'll look at an example. So we have the boy has the ball. I know. A really great message that we need to send. The key, let's face, and this is VIG. So essentially, what we're going to do is encode, so we still use the see-through-cycler essentially for each letter, but now instead of just shifting the alphabet once, we're shifting the alphabet three different ways. So if we had VIG, VIG, VIG, VIG, the boy has the ball. So we have a plain text, the boy has the ball. We essentially think it was repeating the key over and over. And so we're going to shift the first one by how much? V, whatever V is, I don't know, whatever that maps to in numbers. That's how much shift we do there. H, we shift I. Pretty easier. What does that say? I think that's what we're on. Right? And then E, we shift by G. And then V, we shift by V, O with I, Y with G, so on and so forth. So what does this do that the see-through-cycler does not do? The see-through-cycler could be different letters based on their position, which makes it a lot harder to find probabilities or extract any meaning from the letter. Right. So just like before, we had the problem of, we had the L-O-V-R-L, and all the L's map to exactly the same letter. And we could say that, we could say something about that, right? Here we can't really say that. So the cycler here is O-P-K-W-W. So this W with W, is this the same letter in the original context of this W? It is with one of them, but not with the other one. The P is the same. Oh, it was also the same. Which one? A. Yeah. The original message, yeah. Yeah. So does our old trick then work? We just tried our old analysis. We did the frequency analysis, right? We could go exactly through the same steps. And we could try and prove force, obviously, of all this. These are cyclers, but we could say, okay, 22 is the most likely based on our measurements. And when we get, it looks like this. K-L-G-S-S-A-Y. Stay in there. We took it by 10. We did something like this. We took it by four. We did something like this. We took it by two. We did something like this. So A, we're using, but why did this happen? So clearly, we're using a different encryption algorithm. So we're trying to decrypt it with a Caesar Cypher with different key size. But why were we able to determine the key? Yeah? When the implication of the original line was founded on the fact that each letter was always going to map that mistake, say. So if you shift the frequency distribution in a certain way that they lined up and that's quite the product, you probably come to the right thing. But that's not the case here. Right. Other characters were shifted different amounts, right? In the original plain text. Right? So none of that original, what we had with that nice, beautiful English single-letter frequencies gets completely destroyed by this method. So, are we just stuck? What do we do? Is this the perfect Cypher? So let's say we need to break it. What do we need to know? The length of the reading. So we need the length of the key, right? Do we assume we know that? No, because we don't know the key. We don't really know anything about the key. So it could be any length, I mean, to a certain amount, yeah. So it gets shorter than the length of the Cypher. Do you just like mentally read it? Yes. Okay. So the key is repeated over and over again. And so that way, you think it is a modular, right? So it just keeps going over, shifting each letter of the plain text with the corresponding letter of the key. Yeah. Well, the fact that there's the two repeat OPKs mean that we can assume that if we're breaking it to the better and so it should meant the index. Yeah. So that's something interesting we can look at, right? So you can see it's OPK, OPK. Let's think about this for a second. Pause that. Fine. Let's think about, so we have the period, the length of the key. So then let's think about, how does this affect our brute forcing? So how long is it going to take to brute force a one letter key? How many guesses? 26. Same as a Caesar Cypher, right? So the visionary Cypher is more complicated than a Caesar Cypher, or encompasses the Caesar Cypher within it, right? Okay. What about two characters? 26 squared. Three characters. Q, four characters. At some point you want to stop brute forcing. Yeah, I mean it depends on how much hardware you have and how what your budget is, but at a certain point it's going to be unfeasible to brute force these keys. Which is actually something that's really cool to think about, right? This was created, I believe, I don't know, I'm just going to make up before computers, I know that's definitely true. I can say that. So you think about it's very, and you could do this with pen and paper, right, this encryption scheme, right, and you could easily use up to like a five digit key or a five key of five length. It could be a word or whatever you wanted it to be. It could be something that would be easy to transmit, but you would get, you would increase the key space to 26 to the fifth, is that what we said? Can somebody do that number? Is that a large number? It's a small number. 26 to the fifth. 12 million? Yeah, let's add another one. Six. You do six one, I'm sure that makes it slightly bigger, right? And so now you're in the range of it's difficult to brute force even in computers, right? If you had 10, 26 to the 10th is pretty large. You keep going, you have an encryption scheme and a crypto system that you can do by hand that is difficult to brute force through the key space. It's kind of crazy, right? So in the period with the, the key has different letters. So we're going to talk about this in a second in this thermal way sense in a bit, but we know each, the key has different letters. We don't know exactly how many, but how can we attack this? Are we, so we know, what do we know won't work? Let's go through it. It's sometimes helpful to explore the negative space. What type of things won't work? The type of statistical analysis we used before, right? With one gram, specifically the one gram English frequencies. You can think of that is going to be smoothed out. So what do I mean by smoothed out? All those letters are going to kind of go towards each other to some average. Okay, we can't do that. What else can we do? Could you switch to the statistical analysis if you were to say like, statistical analysis on every third letter and then group all the third letters and then run an analysis? Yeah, so the one thing that we do know is we know that we don't necessarily know the key lengths to start, right? But if we assume we know it, right? Let's say it's length n, right? We could take, actually I hate using n, let's take three, right? Let's do a key length of three. You could take the first, the fourth, everything, mod three, whatever, n, mod three equals zero. Take all of those. So let's go through an example. I don't know what the period is, right? We were talking about it. We know it's three. So what is that? How does that help us? Does that help us at all? Yeah, we can break it up into some problems. Yeah, we can break it up into, so we can take every third letter, O, W, C, maybe that's right then. G is y, right? Always breaking it up. No, so that's wrong, right? I think it's y. Yeah. W is y. So we can split it up into, and now we can think of this as three different alphabets, right? Y. So assuming that we're correct, we know the period, we know the period is three of the key. Why can we think of these as three different alphabets? They were all shifted by the exact same letter, right? We don't know what that is, but we know this is like key zero, key one, and key two, right? All of the characters in this alphabet were shifted by the exact same amount, right? So now what does that remind us of? Caesar cipher, right? Each of these was shifted by the exact same amount. It means that the statistical frequency here is still going to match English. Yeah, so we've cut the samples we have in thirds, right? That's one problem. What's another problem? Yeah. Okay, let's go with that for now. Yeah, we still need to figure out the length. It's definitely still a problem, yeah. Well, I feel like the fact that it's not really true in English anymore is like split, it won't follow the same statistics. Yeah, so how do we know when we get it right? So let's say we run our analysis on each of these. We get it different. This says try 10, 5, and 20, right? We were doing that on a small example. It took us two tries to get the correct answer. So how do we know if we've shifted key zero correctly? We have to compute all of them. So you have to, like, we do k, k0, k1, and k2. Try all the possible k2s. Maximize that number. Maximize every single k1. Maximize every single k0. So that's, like, we're running, like, three inches from the two actuals of the problem. Right, the key problem here is that all these are related, right? Which is exactly what you've all been saying, right? So these keys are related. The letters are related essentially like this, right? So, but if we just shift one, if we just shift and try to guess the first letter, we won't know if we're correct because we only have a third of the health of that. So how can we tell if our guess is actually correct? So we need to have some way to think about that or deal with that. So the bad? Yeah, so now it gets more difficult. Or can get more difficult, right? There's five iterations of each one, so then you're doing, like, five to the third as opposed to, like, twenty-six to the third. Yeah, so we can maybe reduce our search space of the keys that are more likely to occur? Yeah. Are we assuming we're at, like, a really grand smell? No. Or you have to memorize the key because it's possible it's going to be a common phrase Yeah, so that's an interesting thing. So why does that matter? So we said that the key space was two to the, or twenty-six to the third in this case. Right, so we're going to brute force the key space and we know it's, let's say, three characters. We could make an assumption. Do we think that they memorized the key? Like, is it a word or is it completely random? If it's truly random, then how many keys do we have to test? Like, twenty-six to the third. We'd have to enumerate every possible key. If we think it's likely that it's a word, what would we have to do? Try to look three little words. How many three little words are there in English? In English, scramble a lot? Probably less than twenty-six to the third. I'd say that's, you can easily verify that that's true. Probably significantly less. Right, so this is, now we're getting to this interesting thing about breaking the key itself by making assumptions of how it was generated. So if it wasn't generated in a purely random way, then maybe we'll have problems. Because the more difficult scenario is something that is completely generated randomly, that's kind of what we want to focus on. So that there's no, no aspect. This is a situation where, where before we didn't really need an example of a plain text letter, it didn't really matter. Here having a plain text that compares to actually, like, substantially increase maybe makes me easier to apply it on. So you would participate in one plain text and say, well, there's, So a plain text with the corresponding ciphertext? Yeah, that would, Yeah, so what does that give you? So let's say, let's say you have a plain text one and a cipher text one. How does that help you? Now you can start matching just one at a time. Like, as if we were just a regular Caesar cipher, you'd have to compare one to one of the letters of my position. Do you need to go that far? What do you need to do to extract the key now? Alright, so if I gave you, what was this one? Was this the boy in the ball? What's the difference between, so this is plain text one and cipher text one? I think it was supposed to be OPK. The other letter, not one. That doesn't make a K to you? Okay, cool. So what we can just do is take, what's the difference between O minus P? I mean, spoiler, it's going to be V over number 26 minus V is. And we can take HP, it'll be I, and then G. We're going to do this again, V, I, G. So this is why we characterize the different types of attackers in terms of different capabilities, right? So specifically for this cryptosystem, in the case of a, just a known plain text attacker, your scheme is completely broken, because they can trivially drive the key from having both the plain text and the cipher text. Everybody agree with that? Some more difficult cases than what we don't have in plain text. Okay, cool. So we have some kind of approach here, right? We actually have an approach that we can start to take. We've talked about some of the difficult things, but this is all hinged on actually getting the period, right? So we then need some way to get the period and figure out the length of this key. So you just stay up on this. I'll break this, yes? I want to see the kind of over view of how to do this, right? We've talked about some of the complications that occur. You can kind of leverage one. So if the key is, let's say, like five, and you think you've got three of the keys guessed correctly, what can you try to do with the last ones? You can brute force it, or what else? Guess what's the next letter? It's based on what you see, right? So if you think about it, if you have, let's say you're able to guess key one and key two here, in this example, it's going to be T-H-E-V-O-Y-H-A. I'm sorry. It's really difficult to read it this way. If I break it out, we could O-H. So what are some things we could try? We could try. So we basically leverage the fact that we think we've got two of them correctly. Right? You can see key. That's kind of nice to see. What would we guess for this next alphabet next? The O is a T. The O is a T? Why? Because, I mean, look at the start. You know that that's the first word. Does that make sense? Yeah, very common word, right? So we can see that it actually works correctly. So that's it. He's going to say how we know that it just is the opposite of the question. Yeah, exactly. So we guess at that key, we shift everything, and that would actually tell us right away. So just by getting two of them right, we can likely guess what the next ones are. So we can use this to our benefit as we're trying to break the key system. How would we know that those two are right? That's a great question. You still don't know how to get, like, three is the number of keys. Yes, many things. But we can at least, that's the letter in one part from the other. So it's pretty confident we can go with that. Okay. So we have now a large sum of text. We'll just say for viewing purposes, it's broken up into spaces, right? This obviously doesn't mean anything to the message. Left and right, top and bottom. So now we need to figure out the period. So what can we use? We can actually also encode in periods themselves, like punctuation marks, or just letters. Just letters here in this one. So this is just letters. Because our alphabet is remember A through Z. So there's nothing, no spaces, no punctuation. We'll assume the other person knows our intent from the message. And then you go get all the ones, look at the frequency and all that thing and see how close the text is in English. Then go, okay, now we'll try for length three. Check all the ones, check the frequency. And then so on and so forth each length and the general length and the frequency closest to English you could attempt that one first. Interesting. Okay, so the idea is break up the keys into, let's say the essentially brute force the period in some sense. So first try key length of two, right? So brute force, so then you need to double check that you're right. So I guess this is a question. If I said the period here I think is length four, how would you tell if I was right or not? Or what's the probability for what the distribution of letters is and so what are the close English ones? For each of the alphabets, right? So the idea is if we break up the cybertext into the different alphabets for our guests, let's say it's four in this case, break it up into four different alphabets and then we could do frequency distribution of each alphabet to see is this likely, are they still likely more random than not? Like is this actually English? So this would be one way. We'll actually use that approach to test, to test our guests of the size of the key. But there's other cues we can use that exist in the cybertext to give us a better, let's say a more targeted focus of what to look at first or what to guess, what key length to guess first. By the way, it's split by a group of five. That's I did that, not the cybertext. So let's say I did that by a group of five. Although that is the case, I'll be upset, but I don't think that's correct. Check for repetition anywhere? Check for repetition anywhere? Why? Because the length of the repeating string would give you the length of the period. Yeah, so let's think about this for a second. So why can't we use repeating characters? What do we know about those three nodes in the upper right? Zero, zero, zero, zero, yeah. They're all probably mapped to different letters. Right, they're all probably mapped. The plain text has those different characters, but it doesn't happen that they map to O, O, O, O, right? So the fact we can't necessarily say anything about O, O, and this O, and this O, because we don't know anything about that. Let's go back to our original cycle here. So thinking a little more about this idea of repetitions. So what repetitions do we see here in this type of text? OPK. OPK? So we have OPK and OPK. Is that it? We need to search that in early. OPKW, actually, yeah. So this, right, and this. So why? So the question is, why did these repeat? They're the same word in the cycle. How can we be able to say that at that point? Yeah, so we look at just, okay, great. So there's two things, right? So OPK occurred because we had THG in the line text that repeated twice, and something else had to happen. Exact same off that set in reference to the key, right? So they're all, you can think of shifted by the exact same letters in the original, in the key, right? So we can't say anything about, let's say, this O and this O. Just by looking at the O's, we don't know that they're encrypted by the same, that they're shifted the same amount. But, so what's the alternative? What else could have happened here? The thing about it in reverse, is it possible that we see OP and OP here that don't have the same corresponding line text? Yes, why? You guys are getting it vigorously. Well, it's also likely that somehow they got sandwiched at a different point in the text. That just happened to be that this T8, or that some other letters were somewhere else on the key, and then the key shifted the alphabet such that it output an OP, right? So the fact that there's a repetition, but how likely does that happen with three characters in a row, or four characters in a row, right? Less and less likely to happen. So what do we do? So let me say what's the difference between this OPK and this OPK? One, two, three, four, five, six, seven, eight, nine. So it's going to say the key is length nine. What do we actually use of this information? Yeah, it's likely. I would say it has to be, right? It's likely that it's sum, the key is sum multiple of nine. So what type of things could we check for then? Yeah, three, 27, it could be any number of things, right? This at least gives us something to start with. And heck, this is something we had with it, what's this? 12. 15 characters. We also know that the period is bounded by the length of the string. Yeah, we did not assume that the key length, because the key was the exact same size as the message, you still think you had to communicate that key to them at some point, so why don't you just give them that message then or whatever, so we'll go into that later on. Okay. So what repetitions are there in this? Cybertext. Cool. So, yeah, this is actually all the stuff we just talked about, right? So that repetition in the cybertext are likely to occur when characters of the key appear over the same characters in the plaintext. Right? It's not the guarantee, but that's a very lightly scenario. So in this exact example we had, so it could be, you know, the distance is nine, it could be less than nine, it could be more than nine that we talked about, one, three, or nine. So let's look at this here. What repetitions do we have? Let's take a sample. Yeah. There's the EQ po-o-g. EQ. Okay, you're at the... In the first column, second row. First column of the second row. EQ po-o-g. And then second column third row. EQ po-o-g. Yeah, that's... How many characters does that have? One, two, three, four, five. It's a five-character repetition. O-e-d-q-o-o-g. O-e-d-q-o-o-g. So you actually include this one. What's the offset here? So this is one, two, three, four, five, six, seven, eight, nine, ten, one, twelve, thirteen, fourteen, fifteen, six, and seventeen, eighteen, nineteen, twenty, twenty, twenty, twenty, twenty, twenty, twenty, twenty, twenty, five, six, seven, twenty, twenty, twenty, twenty, thirty. So that's offset thirty. Three, ten, fifteen, two, three, ten, fifteen, two, five, six, thirty. What are the repetitions? Column four, row two. And this is looking at a self-fragment email. And then you column three, row four. Three, row four. Okay, cool. Yeah. This here, and this here. Alright, somebody else can calculate this. Eight, five, ten, fifteen, twenty, twenty, five, six, twenty, twenty, five, thirty, forty, wait, thirty, five, forty, five. Can we calculate just character of the column underline, or can we calculate the last character of the line? You have to calculate exact same one from one to the other. So for here, what's the difference between this first day to this first day, or you can say the last letter to the last letter. You need to count both of those. Yeah. Okay, it's fine. We don't have to calculate it. I have to say later, but I'm pretty happy to get all this. Well, N, E, C, I, N, C, I, ten it looks like. M, I, the first row. M, I, U, S, E. I don't know, are you? Ten, another ten. In fact, that was weird. Cool, so you keep doing this. Everybody see how we do this? We write down the distance. You can look through all of these to start the end, the distance, and calculate all the factors. So based on this chart, what will we start looking at first? Two and three seem very common. What do we look at? Two or three? What do we have to look at? Fine, fine. Yeah, so fine facts. We're going to do two, three, maybe six. What of, so this gives us a nice overview, right? But, I mean should we, we're going to write this like Q, O, that's like seven and seven, or the M, I, that's, or the O, O, that's just this five? Why not? Yeah? For one, it's two letters. The probability of that being a problem is 45. Two, the distance, like it's so not correct. That number of factors is so not correct. I love it, like it's both. Yeah, so, so that's an important thing to look at. We're looking at this chart, right? We can just focus on these factors, but if we do that, we're actually ignoring the information that's contained in the amount of letters that match. Right? So, we should really be focusing on the, what's that, the six letter match, and the three letter match here, right? Those kind of have the most, in some sense, weight, because it's the least likely that there's a curve I can't see. Yeah, for like MOC, can you explain to the fact that you're doing three? Is that breaking down to 72? Just breaking it down, like, like, so two. Yes, so we will, when we start looking at them, then we can, we'll look at all of the factors. So, basically, this kind of, I think this is breaking it down into prime factors, I want to say. Okay, so it can't be like four, like four factors? That would be something we would try. Yeah, so we'd look at these of, like, what are the base factors we're going to work with, and then we would build up and try different variants in there. And the thing we want to focus on, like we said, right, is the longest string, right? Let's start on the longest string match, that's the most likely to be something useful. So, the distance was 30, right? So, although we talked about, we could try different periods, maybe one, two, three, five, six, 10, 15, or 30. So, now when we can push it, we can try. So, we could try all of them. That would be one thing. And we know our test now, the test for it, right? We can split it up into different alphabets. We calculate the, the, how close that alphabet is to English. Why? Yeah, let's come back to our table, right? And try to say, okay, of these, how many of them have, so, we'd look and we'd say, okay, well, 7 out of 10 have two as one of their factors. See that? And 6 out of 10 have three in their factors. Maybe likely that we could try a period of 6. Yeah. I was supposed to say, like, I mean, the problem with it, is like 50% of all key periods will have two as a factor. Yes. That is, well, for two, yeah. Yes, that's definitely true. So, we have that, but looking at what factors we have here, I think it's safe to, so I think you can say, the key wasn't in odd size, how many twos would you expect to see here? Right? Very little. So, it actually would probably be easier in that sense. But you would get some stuff by chance. Okay, now we need to check our guess, right? Which is what we talked about. So, is this correct? Because, again, we're just guessing. We're guessing that the period is 6. And imagine how frustrating it could be if we split the alphabet up into 6. We start trying to brute force and guess the different shifts, but our period is incorrect. We will never get the correct key. Yeah. What's the intuition of doing, like, two times 3? Which is like, I'm gonna go these two numbers over here. You, what if I use 4? Why would you want to use 4? Yeah, it's not a multiple of the biggest one, right? Yeah. So, it's 4. Well, there you go. So, ideally, you have a pretty easy way of checking this period, like the checking of the guess that we'll talk about next, so you could run these for them and see very clearly which one it is. It pops out pretty easily. So, we're gonna introduce a new statistical measure. And this measure is gonna call the index of coincidence. So, the nice thing is, so the idea is that if we choose randomly two letters from the ciphertext, what's the likelihood that they're the same letter? X is completely random. What's that likelihood? Yeah, 1 over 1 times, wait, what? 1 over 26, right? So, that would be completely random. You pick one letter, you pick another letter, thoughts of they're the same, they're completely random letters. If it's English, is it gonna be completely random? No, because you now know how random distribution, right? The distribution is through English, you can calculate over English, that's what that likelihood is. And as you choose different periods, this, so you can think of completely random on one side, a period of 1, which is English text, is where English is. As you get closer and closer, you get closer to that index of coincidence. It's actually pre-calculated for different size periods. So, it's actually one guess that might help you a little bit. Alright, I guess we're gonna get back to this on Tuesday, but it's just calculating exactly how we talked about this.