1 00:00:00,210 --> 00:00:06,750 Now that letters that are encrypted with the same subcu we can now use to get and circulate those to 2 00:00:06,750 --> 00:00:13,380 try decrypting with some potential killens, not the next, we will move on to attempting the decryption 3 00:00:13,380 --> 00:00:20,160 with unlikely KMD now recalled Kosofsky examination function isn't guaranteed to return the actual length 4 00:00:20,160 --> 00:00:26,550 of the Virginia key, but rather a list of several possible lenth sorted in order of most likely. 5 00:00:26,550 --> 00:00:27,610 To least likely. 6 00:00:28,380 --> 00:00:35,400 And if the code has determined Long Island, it will try again using a different Kēlen attempt hack 7 00:00:35,400 --> 00:00:38,820 with the Keelen function, which is the next that we have to find here. 8 00:00:39,300 --> 00:00:40,250 It does. 9 00:00:40,290 --> 00:00:43,870 This went past the ciphertext and determined the killing. 10 00:00:44,190 --> 00:00:47,870 If successful, this function returns a string of hacked message. 11 00:00:48,180 --> 00:00:51,260 If the hacking feels function returns none. 12 00:00:51,270 --> 00:00:54,210 The hacking code works only on uppercase letters. 13 00:00:54,480 --> 00:00:58,980 But we want to run or return any decrypted string with its original disk. 14 00:00:59,220 --> 00:01:05,200 So we need to preserve the original string and to do this with the uppercase form of the ciphertext 15 00:01:05,200 --> 00:01:09,110 string in a separate variable that is your ciphertext up. 16 00:01:09,530 --> 00:01:16,980 We if we assume the value is the most likely guyland is correct guillén the hacking algorithm then calls 17 00:01:17,250 --> 00:01:25,440 your get and Sukie letters for each subject and brute force through all the twenty six possible letters 18 00:01:25,440 --> 00:01:32,850 to find the one that produces decrypted text whose letter frequency most closely matches the frequency 19 00:01:32,850 --> 00:01:34,610 of English for that subject. 20 00:01:35,070 --> 00:01:42,660 And the first attempt on an empty list is stored in all frequency schools, which was stored the frequency 21 00:01:42,660 --> 00:01:48,360 Matsuko written by the frequency analysis dot your English frequency. 22 00:01:48,360 --> 00:01:55,130 Matsuko, which we have already created, and the same function we are trying to call it here. 23 00:01:55,650 --> 00:01:56,750 So over here. 24 00:01:57,300 --> 00:02:04,980 So the for loop, which is over here in this line, it's at the end of variable to each integer from 25 00:02:04,980 --> 00:02:06,780 one to the most likely guyland. 26 00:02:06,990 --> 00:02:13,020 And recall that when the range is passed as to argument, the range goes up to but not including the 27 00:02:13,020 --> 00:02:13,900 second argument. 28 00:02:13,920 --> 00:02:18,870 Hence we have put a plus one into the code so that the integer value is most likely. 29 00:02:18,870 --> 00:02:26,320 Gillanders included in the range, the letter of the end, the subject written from your get and subcu 30 00:02:26,340 --> 00:02:26,850 letters. 31 00:02:27,090 --> 00:02:30,450 And next, we need to decrypt the letters of the end. 32 00:02:30,750 --> 00:02:31,620 Give it all this. 33 00:02:31,620 --> 00:02:36,630 Twenty is possible Sakis to see which one produces the English like letter frequencies. 34 00:02:36,810 --> 00:02:43,320 So a list of English frequency match score is stored in a list in a variable named frequency schools 35 00:02:43,320 --> 00:02:49,830 here and this variable starts on an empty list and then for loop on it, loop through each of the twenty 36 00:02:49,830 --> 00:02:52,160 six uppercase letters from the letters. 37 00:02:52,250 --> 00:02:59,280 Still, the possible values or the possible key values decrypt the ciphertext by calling your vagina's 38 00:02:59,400 --> 00:03:04,150 for the Modot decrypt messages and the subject is impossible. 39 00:03:04,150 --> 00:03:06,390 The key is only one letter, but the string. 40 00:03:06,390 --> 00:03:11,310 In the end, the letter is made up of only the letters from message that would have been encrypted. 41 00:03:11,310 --> 00:03:12,210 Would that give? 42 00:03:12,210 --> 00:03:14,700 The code has determined the key length correctly. 43 00:03:15,240 --> 00:03:21,870 So next, the decrypted text is then passed onto frequency analysis dot English frequency Matsuko function 44 00:03:21,870 --> 00:03:27,750 to see how closely the frequency of letters in the decrypted text matches the little frequency of regular 45 00:03:27,750 --> 00:03:30,660 English, which we have already learned in the earlier session. 46 00:03:31,200 --> 00:03:37,370 Then we put this frequency match code and the keys used to decrypt and what tuple and stored in key 47 00:03:37,380 --> 00:03:42,450 and frequency matched tuple, which is this particular variable on this line. 48 00:03:42,660 --> 00:03:50,280 And then the Stupples opponent to the end of frequency schools by saying frequencies kosdaq up pentimento 49 00:03:50,670 --> 00:03:57,650 after the for loop completes the frequency score list should contain the six keys and frequency might 50 00:03:57,690 --> 00:04:02,150 score tuple one for each of the twenty six subcu. 51 00:04:02,400 --> 00:04:07,830 Then we need to sort this list so that you build with the largest English frequency map score comes 52 00:04:07,830 --> 00:04:08,330 first. 53 00:04:08,640 --> 00:04:14,130 This means that we want to solve the tuple and frequency scores by adding value at index one and in 54 00:04:14,130 --> 00:04:14,930 the reverse order. 55 00:04:15,300 --> 00:04:21,720 Hence we have done this sort method over here on frequency score list, passing the function value that 56 00:04:21,720 --> 00:04:27,600 is good item at index one from the key argument node that we are not calling the function. 57 00:04:27,600 --> 00:04:34,170 As you can tell from the lack of parentheses and the value true is pastoralist's function call the keyword 58 00:04:34,170 --> 00:04:40,190 arguments sorted in descending order, hence the distal parameters apostrophe the function over here 59 00:04:40,650 --> 00:04:42,510 now if we move on further. 60 00:04:42,720 --> 00:04:49,170 So initially the num most frequency letters constant was said to integer value for in the above line 61 00:04:49,170 --> 00:04:50,940 if you have seen over here. 62 00:04:52,500 --> 00:04:54,160 This one had to settle for here. 63 00:04:55,050 --> 00:05:01,980 Now, if we go back to over my thought here, if we see the next thing that after sorting the tubas 64 00:05:01,980 --> 00:05:06,990 and the frequencies scoring intervals out of the offender list containing only the first three Dupas, 65 00:05:07,230 --> 00:05:13,790 all the tubas with the three highest English frequency, Matsuko to our all frequency schools. 66 00:05:14,010 --> 00:05:16,290 So as a result are all frequencies schools. 67 00:05:16,290 --> 00:05:22,380 And Exito contains frequencies, codes for the fourth subject and one contains the frequencies code 68 00:05:22,380 --> 00:05:23,440 for the second subject. 69 00:05:23,970 --> 00:05:30,330 So after the loop completes here, the all frequencies code should contain a number of list values equal 70 00:05:30,330 --> 00:05:33,020 to the integer values and most likely Kēlen. 71 00:05:33,510 --> 00:05:36,540 Now, for example, of the most likely length was three. 72 00:05:36,540 --> 00:05:43,410 All frequencies score would be a list of Thrillist for list would hold the pupil for the top three highest 73 00:05:43,410 --> 00:05:51,000 matching Saki's for the four subcu of the second list would hold of the pupil for the top three highest 74 00:05:51,000 --> 00:05:54,880 margins of for second UPU of the full beginner and so on. 75 00:05:55,380 --> 00:06:01,560 So originally if we wanted to brute force through the full beginner number of possible keys would be 76 00:06:01,560 --> 00:06:04,470 twenty six raised to the power of the chelate. 77 00:06:04,980 --> 00:06:10,820 But checking the English frequency matching helped determine the four most likely letters for each. 78 00:06:11,730 --> 00:06:21,280 So this is a huge improvement over how many more possible he's so now the end giver argument for print 79 00:06:21,690 --> 00:06:21,940 now. 80 00:06:21,960 --> 00:06:24,750 Next, we want to bring the output to the user after this. 81 00:06:24,750 --> 00:06:29,340 To do this, we use the print, but as an argument to an optional parameter. 82 00:06:29,790 --> 00:06:31,170 We haven't used it before. 83 00:06:31,380 --> 00:06:36,620 Now, whenever a print function is called, it brings to the screen the string Bastar it along with 84 00:06:36,630 --> 00:06:37,610 a new line character. 85 00:06:37,980 --> 00:06:43,020 So to print something else at the end of the string instead of a Newlon character, we can specify the 86 00:06:43,020 --> 00:06:46,500 string for different functions and the key argument. 87 00:06:47,100 --> 00:06:51,720 For example, we will enter something in the interactive shell to see how to use the print functions. 88 00:06:51,990 --> 00:07:01,290 And the keyword argument, if we go back over here and if we try to see the fine print stuff and in 89 00:07:01,290 --> 00:07:03,210 this we are defining, say, print. 90 00:07:04,390 --> 00:07:13,660 See, right now, we are giving here and is equal to say and in single court, then next we are defining 91 00:07:13,660 --> 00:07:24,760 print see single quotes again hacking and the end is equal to just open closed bracket. 92 00:07:25,450 --> 00:07:29,450 Now, next print we are giving here greetings. 93 00:07:29,530 --> 00:07:33,880 Great things and defining and is equal to, say, X, Y, Z. 94 00:07:34,660 --> 00:07:42,760 And next we are giving print just saying thank you all. 95 00:07:42,800 --> 00:07:43,280 Thanks. 96 00:07:43,440 --> 00:07:44,560 OK with no end. 97 00:07:45,010 --> 00:07:53,390 And then we say here call print stuff so we get Biton with a new line. 98 00:07:53,650 --> 00:07:56,380 Hacking is just having nothing at the end of it. 99 00:07:56,620 --> 00:08:00,900 So it continues gradings on the same line and we have X, Y, Z. 100 00:08:00,910 --> 00:08:04,870 So after X, Y, Z again, we have the next think tanks which is being printed. 101 00:08:05,080 --> 00:08:08,440 So passing in is equal to slash and preindustrial. 102 00:08:08,470 --> 00:08:14,740 Normally how we would passing in is equal to just open to a single course or some string replaces the 103 00:08:14,740 --> 00:08:16,230 usual newline character. 104 00:08:16,480 --> 00:08:20,320 So subsequent print calls are not displayed on the new line. 105 00:08:20,740 --> 00:08:22,240 That is what this difference is. 106 00:08:22,720 --> 00:08:23,960 That's it from the session.