 Hey everybody, Mr. Gibson here with the next lesson in cryptography and today we'll be looking at how we can use the index of coincidence calculation to determine the keyword length when we're working with the Visionaire cipher. Let's jump right in. So here's our ciphertext. This is the same ciphertext that we used when we were looking at the Kasiski test. And we're going to start off in a similar way. We're going to try and think about how long is the keyword. So let's start by assuming a two letter keyword and we're going to look at just the first line in the text. So we picked a very simple two letter keyword just to kind of see what happens here. And we're going to create some groupings out of our ciphertext letters. So we're going to take first all of the letters in our ciphertext that were created using the letter A in our keyword, and then we'll create a second group of letters that uses just the characters that were in ciphered using the letter B in our keyword. So we've got two groups of letters here. And if we guessed correctly that our keyword was in fact two letters long, that means that these letters in each group were encrypted using the same letter out of the keyword A for group one B for group two. Now what we don't know yet is if that guess was correct. So we had to think away how we could verify that. So if we think about if we if all of these letters in group one J, K, Q, W, C, and so on were in fact in ciphered using the letter A from the keyword, they should follow a mono alphabetic distribution because they were all encrypted using the same letter, which means we could maybe plot these on a bar chart or we could just calculate the index of coincidence and we would expect to see a value that is in line with English mono alphabetic substitution ciphers. So about point zero six six or point zero six eight somewhere around there. And we would see the same thing for group two, because all of those characters should have been in ciphered using the same key letter. In this case the letter B. So let's calculate each of those index of coincidences. And we can see that group one had an index of coincidence about point oh six zero and group two point oh five six. So kind of close to what we would expect if we guessed right. But the average of that is still below point oh six. So not a real strong evidence that this is in fact a two letter keyword. We can undergo the same process. Let's try it with a three letter keyword. We'll pick a simple three letter keyword ABC. And we'll do the exact same operation. We'll look for the same characters that were in ciphered using the same letter from the keyword. So group one, all of those characters were in ciphered using the first character in our keyword a group two with the second letter of our keyword and the characters in group three all created using the third character letter C in our keyword. And when we calculate the index of index of coincidence for each group, we see that those are even lower point oh four four point oh five one and point oh four eight with an average index of coincidence of point oh four seven six five that average index of coincidence actually very close to what we'd expect for a normal vision air cipher. So that's not what we want even though the cipher text as a whole was created using the vision air cipher. The hope was that if we got the at least the length of the keyword correct, each group would follow a mono alphabetic distribution. So we could keep trying different keyword lengths just increasing our guest keyword length until we get an average index of coincidence of what we would expect to see for a mono alphabetic distribution. This table shows the average index of coincidence based off of the keyword length that we've guessed. So we've already got two three and from the previous slides. And then we've got the average index of coincidence for key length four five six seven and eight included as well. And when you look at it this way, I think the average I see for a key length of four definitely stands out point 083. That's pretty close to the point oh six six that we were expecting for a mono alphabetic distribution a little bit higher, but that can definitely happen when we're working with a somewhat short cipher text. And then it goes back down for key length five six and seven. So it seems like key length four is pretty likely our correct key length. You will notice that a key length of eight has a very similar index of coincidence. But so does key length 12 16 20 and so on any real multiple of four, which actually should make sense if the actual key length is four, but we try a key length of eight. That should still result back with the correct index of coincidence. We basically we're just taking the four letter keyword twice to create the eight letter keyword. So the algorithm that we just used there is that we're going to assume some key length we'll call that n and we'll start with a value of two. Then we'll split up our cipher text into n groups in a way that the characters in each group would have been in ciphered using the same character from the keyword. Then we calculate the index of coincidence for each one of those groups. Average those together to get an average index of coincidence for all of the groups. And if our index of coincidence, the average value is close enough to the English value of around point oh six eight, then we'll assume that that guest value of n was the correct length. And if not, we'll increase the value of n by one and start that process over again, continuing until we get to a correct English value. So there's our method for using the index of coincidence to determine the keyword length. What we'll see in our next lesson is what are we going to do now that we know how long the keyword is. Thanks for watching and we'll catch you on the next one.