1 00:00:00,210 --> 00:00:08,400 So the Getler function, which we have defined here, is basically text messages, string and returns 2 00:00:08,400 --> 00:00:16,680 a dictionary value whose keys are a single uppercase letter strings and whose values are in BIJA that 3 00:00:16,680 --> 00:00:21,150 stores the number of times that letter goes in the message parameter. 4 00:00:21,510 --> 00:00:29,160 So here we have created a letter found SDR variable by assigning it to a dictionary that has all said 5 00:00:29,200 --> 00:00:31,400 Stewart, initial value of zero. 6 00:00:31,430 --> 00:00:34,080 Hence we have set all the keys from A to Z. 7 00:00:34,290 --> 00:00:36,060 Everything's A to Z. 8 00:00:36,500 --> 00:00:43,680 OK, we then increment the value associated with the key until they represent the count of each letter 9 00:00:43,680 --> 00:00:47,460 by taking each character in the message using a form Lupul. 10 00:00:47,850 --> 00:00:52,120 So we have before this year in the message dot Apple. 11 00:00:52,530 --> 00:00:56,790 If your letter Asgeir is in the constant then you make or incremental value. 12 00:00:57,300 --> 00:01:04,380 So therefore loop iterate through each character in the uppercase version of the message SDR and assigns 13 00:01:04,380 --> 00:01:07,190 the character to the letter OCR variable. 14 00:01:07,560 --> 00:01:14,310 Then we check whether the character exists in the constant letters string because we don't want to count 15 00:01:14,310 --> 00:01:16,420 the known little characters in the messages. 16 00:01:16,980 --> 00:01:23,280 So when the letter is a part of your constant increments, the value at letter count are the index of 17 00:01:23,280 --> 00:01:25,680 letters plus is equal to one. 18 00:01:25,710 --> 00:01:32,970 So after the for loop, the letter count is your dictionary should have a count showing how often each 19 00:01:32,970 --> 00:01:40,080 letter appeared in the messages and the dictionary is written from the get a letter count as saying 20 00:01:40,080 --> 00:01:42,120 return the letter count as dear. 21 00:01:43,020 --> 00:01:51,600 OK, now if we move on to the next one, say getting the first member of the stupid now the get item 22 00:01:51,600 --> 00:01:58,360 at the index zero function returns the items at index zero when the duopolies pass to it. 23 00:01:58,590 --> 00:02:01,640 So it is just having a simple written statement given. 24 00:02:01,680 --> 00:02:07,680 And later in this session we will pass this function to this sort method to sort the frequency of the 25 00:02:07,680 --> 00:02:09,390 letters into numerical order. 26 00:02:09,810 --> 00:02:14,550 OK, we will look at this in detail in the some other sections of hacking. 27 00:02:14,820 --> 00:02:18,480 But as of now, currently, we will be using this function to sort. 28 00:02:19,110 --> 00:02:23,190 So moving to the ordering the letters in the message by frequency. 29 00:02:23,490 --> 00:02:30,420 The next function that we have defined is our get frequency order function, which takes a message string 30 00:02:30,420 --> 00:02:37,080 as an argument and returns a string with a twenty six uppercase letters of alphabet arranged by how 31 00:02:37,080 --> 00:02:43,100 frequently the upbuilding message parameter f message is readable English instead of random anything. 32 00:02:43,350 --> 00:02:49,650 It's likely that the string will be similar, if not identical to the string in the edit or in constant. 33 00:02:50,130 --> 00:02:56,250 The code in the frequency or the function does most of the work of calculating the string frequency 34 00:02:56,540 --> 00:03:01,860 score, which we will be using in order which will be used in the Virginia hacking program in the next 35 00:03:01,860 --> 00:03:02,370 session. 36 00:03:02,400 --> 00:03:07,980 OK, for example, if we have passed certain string to it, the function would return the string in 37 00:03:07,980 --> 00:03:13,920 a particular order because E is the most common letter which would be used, for example, followed 38 00:03:13,920 --> 00:03:16,360 by B then I then and then so on. 39 00:03:16,860 --> 00:03:20,490 So the frequency of the function consists of five steps. 40 00:03:20,790 --> 00:03:27,270 First, if you are counting the letters in the string, second is creating a dictionary of frequency 41 00:03:27,270 --> 00:03:35,220 columns and the letter list is sorting the letters list in the rebels or in order for this converting 42 00:03:35,220 --> 00:03:37,260 this data to the list of tuples. 43 00:03:37,260 --> 00:03:42,900 And the last is converting the list into the final string to return from the function, get frequency 44 00:03:42,900 --> 00:03:43,650 or the function. 45 00:03:43,770 --> 00:03:49,740 Now let us look at each of these step into succumbing to the first one that is found in the letters 46 00:03:49,740 --> 00:03:51,900 with the little count function. 47 00:03:52,320 --> 00:03:58,380 OK, so over here before step off your get frequency auto function, which calls together that account 48 00:03:58,380 --> 00:04:06,270 function with the message parameter to get the dictionary named letter frequency is containing count 49 00:04:06,270 --> 00:04:08,830 of every letter in the message. 50 00:04:09,450 --> 00:04:16,140 OK, so after this two lines of code that we have written, we get the values there and then we pass 51 00:04:16,140 --> 00:04:18,180 this particular string as the parameter. 52 00:04:18,180 --> 00:04:24,060 For example, say we have passed by and hacking something like that or Alan Matheson. 53 00:04:25,350 --> 00:04:30,870 Now this particular string would be then assigned to the letter to frequency function and then we will 54 00:04:30,870 --> 00:04:35,040 get how much it is being used or how frequently it is being used. 55 00:04:35,070 --> 00:04:41,270 OK, then next we have is creating a dictionary of frequently counts and the letter list. 56 00:04:41,280 --> 00:04:45,510 So the second step in this is all this function is to create a dictionary. 57 00:04:45,810 --> 00:04:52,260 That is the frequency to let Oresteia, whose keys are the frequency count and whose values are the 58 00:04:52,260 --> 00:04:59,340 list of letters with those frequency counts, whereas the letter to frequency ACR, which is a. 59 00:04:59,750 --> 00:05:07,960 Redmap Lecoq used to frequency values the frequency to let Orestiada, which we have that Maxey frequency 60 00:05:07,960 --> 00:05:15,430 keys to the list of the letter values, so we will need to flip the key and the values in later to frequency 61 00:05:15,430 --> 00:05:21,580 dictionary will flip the keys and values because the multiple letters would have the same frequency 62 00:05:21,580 --> 00:05:23,170 count be N.W.. 63 00:05:23,170 --> 00:05:29,380 Both would have a frequency count, for example, Silvani to put them in a dictionary, said 30 Colombe. 64 00:05:29,380 --> 00:05:36,010 And because the order dictionary key must be unique, otherwise dictionary values will look like something 65 00:05:36,010 --> 00:05:41,950 like 30 Colombe another 30 colon w which is wrong, which will simply overwrite one of these key value 66 00:05:41,950 --> 00:05:42,900 pair with another. 67 00:05:43,060 --> 00:05:48,760 So to make the frequency to little dictionary, we have created a blank dictionary first over here. 68 00:05:48,760 --> 00:05:51,550 That is your frequency to letter estab. 69 00:05:51,880 --> 00:05:56,740 Then we have a for loop saying four letters are in your constant letters this year. 70 00:05:56,890 --> 00:06:04,270 If the frequency is still at the index letter is not in your frequency to let Oresteia then we are saying 71 00:06:04,570 --> 00:06:08,050 frequency two letter instead of the index of letter to frequency. 72 00:06:08,050 --> 00:06:15,130 Asgeir letter instead is equal to last year is we are saying frequency two letters are the index of 73 00:06:15,130 --> 00:06:18,640 negative frequency StarTalk upending the value of letters. 74 00:06:19,060 --> 00:06:25,960 So in this particular loop we are looping over all the letters and letters and then the if statement 75 00:06:25,960 --> 00:06:33,850 checks whether the letter frequencies or the frequency are already exist as a the frequency two letters. 76 00:06:34,420 --> 00:06:36,430 If not, then it adds this. 77 00:06:36,430 --> 00:06:39,040 Give the list of letters as the value. 78 00:06:39,130 --> 00:06:45,820 And if the letters frequency already exist and the key in the frequency to letters, it simply updates 79 00:06:45,820 --> 00:06:47,920 the letter to the end of the list. 80 00:06:48,010 --> 00:06:50,970 Already in the letter to frequency and stamp. 81 00:06:51,280 --> 00:06:57,970 Now using the example value of the letter, the frequency are created using some particular string. 82 00:06:58,330 --> 00:07:03,910 The frequency two letters should now return something which will have like although we had everything 83 00:07:03,910 --> 00:07:06,660 to zero, but now we will have a control, key value. 84 00:07:06,670 --> 00:07:13,330 But now if we move on to the next thing that this sorting the letter list in reverse order. 85 00:07:13,480 --> 00:07:21,370 Now the third step in this get frequency involves sorting the letter strings in each list of frequency. 86 00:07:21,370 --> 00:07:22,420 Two letters, dear. 87 00:07:22,720 --> 00:07:28,600 So we recall that the frequency two letters are evaluates to a list of letters that has a frequency 88 00:07:28,600 --> 00:07:29,770 count of frequency. 89 00:07:30,040 --> 00:07:35,140 We will use a list because it's possible for two or more letters to have the same frequency count, 90 00:07:35,140 --> 00:07:40,080 in which case it would list would have strings made up of two or more letters. 91 00:07:40,270 --> 00:07:45,130 So when multiple letters have the same frequency commas, we want to sort that letters in the reverse 92 00:07:45,130 --> 00:07:49,150 order compared to the order in which they appear in the old string.