Now that letters that are encrypted with the same subcu we can now use to get and circulate those to
try decrypting with some potential killens, not the next, we will move on to attempting the decryption
with unlikely KMD now recalled Kosofsky examination function isn't guaranteed to return the actual length
of the Virginia key, but rather a list of several possible lenth sorted in order of most likely.
To least likely.
And if the code has determined Long Island, it will try again using a different Kēlen attempt hack
with the Keelen function, which is the next that we have to find here.
It does.
This went past the ciphertext and determined the killing.
If successful, this function returns a string of hacked message.
If the hacking feels function returns none.
The hacking code works only on uppercase letters.
But we want to run or return any decrypted string with its original disk.
So we need to preserve the original string and to do this with the uppercase form of the ciphertext
string in a separate variable that is your ciphertext up.
We if we assume the value is the most likely guyland is correct guillén the hacking algorithm then calls
your get and Sukie letters for each subject and brute force through all the twenty six possible letters
to find the one that produces decrypted text whose letter frequency most closely matches the frequency
of English for that subject.
And the first attempt on an empty list is stored in all frequency schools, which was stored the frequency
Matsuko written by the frequency analysis dot your English frequency.
Matsuko, which we have already created, and the same function we are trying to call it here.
So over here.
So the for loop, which is over here in this line, it's at the end of variable to each integer from
one to the most likely guyland.
And recall that when the range is passed as to argument, the range goes up to but not including the
second argument.
Hence we have put a plus one into the code so that the integer value is most likely.
Gillanders included in the range, the letter of the end, the subject written from your get and subcu
letters.
And next, we need to decrypt the letters of the end.
Give it all this.
Twenty is possible Sakis to see which one produces the English like letter frequencies.
So a list of English frequency match score is stored in a list in a variable named frequency schools
here and this variable starts on an empty list and then for loop on it, loop through each of the twenty
six uppercase letters from the letters.
Still, the possible values or the possible key values decrypt the ciphertext by calling your vagina's
for the Modot decrypt messages and the subject is impossible.
The key is only one letter, but the string.
In the end, the letter is made up of only the letters from message that would have been encrypted.
Would that give?
The code has determined the key length correctly.
So next, the decrypted text is then passed onto frequency analysis dot English frequency Matsuko function
to see how closely the frequency of letters in the decrypted text matches the little frequency of regular
English, which we have already learned in the earlier session.
Then we put this frequency match code and the keys used to decrypt and what tuple and stored in key
and frequency matched tuple, which is this particular variable on this line.
And then the Stupples opponent to the end of frequency schools by saying frequencies kosdaq up pentimento
after the for loop completes the frequency score list should contain the six keys and frequency might
score tuple one for each of the twenty six subcu.
Then we need to sort this list so that you build with the largest English frequency map score comes
first.
This means that we want to solve the tuple and frequency scores by adding value at index one and in
the reverse order.
Hence we have done this sort method over here on frequency score list, passing the function value that
is good item at index one from the key argument node that we are not calling the function.
As you can tell from the lack of parentheses and the value true is pastoralist's function call the keyword
arguments sorted in descending order, hence the distal parameters apostrophe the function over here
now if we move on further.
So initially the num most frequency letters constant was said to integer value for in the above line
if you have seen over here.
This one had to settle for here.
Now, if we go back to over my thought here, if we see the next thing that after sorting the tubas
and the frequencies scoring intervals out of the offender list containing only the first three Dupas,
all the tubas with the three highest English frequency, Matsuko to our all frequency schools.
So as a result are all frequencies schools.
And Exito contains frequencies, codes for the fourth subject and one contains the frequencies code
for the second subject.
So after the loop completes here, the all frequencies code should contain a number of list values equal
to the integer values and most likely Kēlen.
Now, for example, of the most likely length was three.
All frequencies score would be a list of Thrillist for list would hold the pupil for the top three highest
matching Saki's for the four subcu of the second list would hold of the pupil for the top three highest
margins of for second UPU of the full beginner and so on.
So originally if we wanted to brute force through the full beginner number of possible keys would be
twenty six raised to the power of the chelate.
But checking the English frequency matching helped determine the four most likely letters for each.
So this is a huge improvement over how many more possible he's so now the end giver argument for print
now.
Next, we want to bring the output to the user after this.
To do this, we use the print, but as an argument to an optional parameter.
We haven't used it before.
Now, whenever a print function is called, it brings to the screen the string Bastar it along with
a new line character.
So to print something else at the end of the string instead of a Newlon character, we can specify the
string for different functions and the key argument.
For example, we will enter something in the interactive shell to see how to use the print functions.
And the keyword argument, if we go back over here and if we try to see the fine print stuff and in
this we are defining, say, print.
See, right now, we are giving here and is equal to say and in single court, then next we are defining
print see single quotes again hacking and the end is equal to just open closed bracket.
Now, next print we are giving here greetings.
Great things and defining and is equal to, say, X, Y, Z.
And next we are giving print just saying thank you all.
Thanks.
OK with no end.
And then we say here call print stuff so we get Biton with a new line.
Hacking is just having nothing at the end of it.
So it continues gradings on the same line and we have X, Y, Z.
So after X, Y, Z again, we have the next think tanks which is being printed.
So passing in is equal to slash and preindustrial.
Normally how we would passing in is equal to just open to a single course or some string replaces the
usual newline character.
So subsequent print calls are not displayed on the new line.
That is what this difference is.
That's it from the session.