 Hey everyone, Mr. Gibson here with the next lesson in cryptography. Today we're going to look at how we can determine what the visionary keyword is, now that we've been able to successfully determine how long the keyword is, either using the Kasiski test or by using the index of coincidence to determine the length of the keyword. So we're going to keep working with the same cipher text, and since we now know that the keyword has the most likely length of four, let's start by highlighting every fourth letter, starting with letter j, all the way down to the end. We're going to create this first group. So this should actually be pretty reminiscent to how we use the index of coincidence to determine the keyword how to length of four is that the first thing we did was we created these groups and we calculated the index of coincidence until all the groups had an index of coincidence of around .068. But this time we're actually not going to calculate the index of coincidence. What we're going to do is we're going to take that group and analyze it. So remember the assumption that we made with the index of coincidence method was that all of these characters should have been in ciphered using the same character from the keyword. And that was verified using the index of coincidence, but now the task is which letter was it in the keyword. In the previous lesson we just used some filler letters to just kind of set up our groupings, but now we actually care about the real letters. So let's go ahead and see if we can figure that out. If these were in fact all created, all of these characters in the cipher text created using the same letter in the keyword, they should follow a mono-alphabetic distribution just like a Caesar cipher. So if we plot the bar chart, this actually does look like a mono-alphabetic distribution similar to a Caesar. The order is even preserved. And if you look for those patterns like spikes and valleys, it would be a reasonable guess to assume that J maps back to A in the plain text, because we can see that it's got a relatively high frequency around 8%, and then three or four letters down the line to the character N would correspond to the character E in the plain text. So these patterns all check out. Now this is a very visual way of doing it. Remember the whole idea of using the code is hopefully to move away from the visual, even though as humans that might be easy for us to understand, having a calculation or a quantitative approach will make it easier for the computer. So we can verify what the bar chart is showing us if we use our chi-squared scoring. If we send this group of cipher text letters, not the whole message, but just this group, through our chi-squared scoring algorithm that we've done in the past, we can try all the different keys and see that the letter J, which corresponds to the key value of 9, is the key that gives us the lowest chi-squared score, meaning that it's the most likely key that when we decipher this group of cipher text, the distribution would be very closely aligned to what we would expect for English letters that have the same length of this group. We can do the same process on group 2. So again, we take just this collection, so a subset of the whole cipher text. We can look at the bar chart and we can maybe guess this one's a little bit harder. Is it O that is the A with the spike for the E a few letters down the way at S, or is it S that corresponds to A on the plain text and then W to E? So this one's a little bit harder for the bar chart. However, if we go back to the chi-squared scoring in a second, we'll see that O actually corresponds back to A. Here's our chi-squared scores that verify that. So using a key of 14, which corresponds to O, we get the lowest chi-squared value out of all the possible keys, meaning O, or 14, is the key that when we decipher this subset of the cipher text is most likely to line up with an English distribution. We can do the same thing for group 3. And we'll see that that character must have been K, because it came from a key of 10. And in group 4, we'd use a key value of 4, which is equivalent to the character E. Putting all of those together, the four characters that we just were able to determine were J, O, K, E. The keyword is joke. So if we take our original cipher text here, which we know is encrypted using vision air, and now we know the keyword was joke, we can decipher that back to the plain text letters. And with a little of reading here and reading between the spaces and adding some punctuation and capitalization, we could actually recreate our plain text here, which is a joke about a mathematician, a physicist, and an engineer. So I'll let you pause and read that if you like. So we can use this strategy to determine the characters that make up a keyword of any length. We just happened to use one of length 4, but this algorithm could be extended out to do keywords of length 4, 5, 6, 7, 8, 9, 10. However long you want, it would just take a little bit more time. But hopefully, if we could program this algorithm using Python, it wouldn't really matter to us. It's going to tackle it very quickly. It's a very efficient way to get this done. So that's how we determine the vision air keywords. Thanks for watching. We'll catch you in the next one.