1 00:00:00,330 --> 00:00:08,130 So now the world sees this particular fight scene drive and let us see which by the name. 2 00:00:10,960 --> 00:00:13,690 Substitution cipher Benmore. 3 00:00:18,950 --> 00:00:20,510 Not Levi. 4 00:00:21,620 --> 00:00:28,340 In the same folder, you'll see it and now let us try and execute them or you find it is double is equal 5 00:00:28,340 --> 00:00:28,880 to here. 6 00:00:29,630 --> 00:00:36,290 So again, let us save it and try to run this in an error or this implicit fine. 7 00:00:36,320 --> 00:00:37,430 Let us check this. 8 00:00:37,530 --> 00:00:38,490 What is the error? 9 00:00:38,900 --> 00:00:43,990 Let's see if the key that we have taken is proper and it should not be repeated. 10 00:00:44,030 --> 00:00:46,640 So let us just validate that key first. 11 00:00:47,090 --> 00:00:53,210 So here, the key that we have taken is L.F. w o a ViiV. 12 00:00:53,720 --> 00:01:04,550 Then you have you I s we he and then you have a, b, b, d, c are. 13 00:01:05,300 --> 00:01:09,910 Then you have g, d, q he said. 14 00:01:10,460 --> 00:01:14,530 So as far as we see that is more characters repeating over here. 15 00:01:15,140 --> 00:01:17,930 So let us check what we have passed. 16 00:01:18,320 --> 00:01:19,400 He is what it is. 17 00:01:19,670 --> 00:01:29,060 We have the Michy orbit and when in this particular function that this is what it is, we are passing 18 00:01:29,060 --> 00:01:32,480 the list asdf that's equal to the list. 19 00:01:32,750 --> 00:01:34,310 Start here and let us. 20 00:01:34,310 --> 00:01:38,150 This list is equal to the letter this year that we have created. 21 00:01:38,150 --> 00:01:44,960 And the list as you are sorting it, and this is also something, then we are returning the test which 22 00:01:44,960 --> 00:01:46,880 is equal to that of this test. 23 00:01:47,160 --> 00:01:53,600 OK, so if this is coming us valuable here, then we are giving a system. 24 00:01:53,600 --> 00:01:55,180 Not in that case. 25 00:01:55,760 --> 00:02:02,540 Now what are we supposed to do is we have missed here, if not valid, then I'm going to give an ETA 26 00:02:02,900 --> 00:02:06,440 if it is valid, because this would if it is regarding this, are valid. 27 00:02:07,070 --> 00:02:11,240 So if it is a valid ticket, then we are moving for encryption. 28 00:02:11,420 --> 00:02:15,590 So now if we try to execute this, we get the encrypted message. 29 00:02:16,460 --> 00:02:23,930 Now we would copy down this message here and paste it or substitute that over here. 30 00:02:23,960 --> 00:02:29,200 So let's add it below my message of. 31 00:02:30,490 --> 00:02:41,530 They start here and we will just come into this for the time, let's save this and let us execute one 32 00:02:41,530 --> 00:02:42,600 more mistake we made. 33 00:02:43,090 --> 00:02:46,130 This is not and this is different. 34 00:02:46,570 --> 00:02:49,030 Save it and run it. 35 00:02:49,510 --> 00:02:51,850 So this is all we are decrypting. 36 00:02:51,850 --> 00:02:54,590 It got the same message that we from within. 37 00:02:54,850 --> 00:02:55,220 Right. 38 00:02:55,600 --> 00:02:59,510 So now let us understand the food that we have written here. 39 00:02:59,800 --> 00:03:06,940 First thing is we are importing the paperclip system and random modules and the letters are variable 40 00:03:06,940 --> 00:03:13,210 is set to a string of all the uppercase letters, which is this implicit for a simple substitution cipher 41 00:03:13,210 --> 00:03:13,660 program. 42 00:03:14,200 --> 00:03:20,590 Then we have the main function, which is similar to the main function of cipher program in which we 43 00:03:20,590 --> 00:03:27,880 basically call when the program is run first and it contains variable that stores the messages and immodesty 44 00:03:27,880 --> 00:03:29,410 are used for the program. 45 00:03:29,740 --> 00:03:36,310 Now the keys for a simple substitution cipher are easy to get wrong because it's fairly long and need 46 00:03:36,310 --> 00:03:38,680 to have every letter in the alphabet. 47 00:03:38,980 --> 00:03:45,850 So, for example, it is easy to enter a key that is missing, a key that has the same letter twice, 48 00:03:45,850 --> 00:03:53,080 for example, and then check that if your key is valid function, make sure the keys usable by the encryption 49 00:03:53,290 --> 00:03:55,900 decryption functions so the function exists. 50 00:03:55,900 --> 00:03:58,930 A program with an error message of the key is not valid. 51 00:03:59,470 --> 00:04:06,360 Now in this case, if this particular statement returns false, then the murkiest is contains an invalid 52 00:04:06,610 --> 00:04:12,610 and the program is terminated all over Europe and we are checking whether the mind is still variable, 53 00:04:12,610 --> 00:04:18,640 is said to encrypt or decrypt, and we accordingly, given particular methods, will adhere to the total 54 00:04:18,640 --> 00:04:24,160 value of this particular method would be a string which is encrypted or decrypted message that is stored 55 00:04:24,160 --> 00:04:26,710 in your translated Istria variable. 56 00:04:27,100 --> 00:04:35,500 Now after that, we are copying the value over here, using our copy method on the label so the encrypted 57 00:04:35,500 --> 00:04:39,510 or the decrypted message is printed to the screen and also copied to the clip. 58 00:04:40,420 --> 00:04:47,080 Now after that now next, we will look at how the key is whether this function uses this sort of method 59 00:04:47,080 --> 00:04:49,180 to test whether the key is valid. 60 00:04:49,570 --> 00:04:53,440 So, first of all, we will see understand what is this awfullest material. 61 00:04:53,830 --> 00:04:59,820 Now, the list have a sort of a code that rearranges the list items into numerical order. 62 00:05:00,160 --> 00:05:06,400 And this ability to sort items in the list comes in handy when you have to check whether Doulis contains 63 00:05:06,400 --> 00:05:09,970 the same items, but don't list them in the same order. 64 00:05:10,360 --> 00:05:16,180 So in this particular program, a simple substitution key string value is valid only four times each 65 00:05:16,180 --> 00:05:20,320 time it goes in the symbols set with no duplicate or missing letters. 66 00:05:20,650 --> 00:05:25,600 We can check whether the string value is a valid key by sorting it and checking whether it's equal to 67 00:05:25,600 --> 00:05:27,150 the sorted list or letters. 68 00:05:27,610 --> 00:05:31,410 But we can only list and not strings. 69 00:05:31,690 --> 00:05:36,410 OK, we'll open list of origin of the string values by passing them to the list method. 70 00:05:36,880 --> 00:05:42,250 Then after sorting this list, we can compare the two to see whether or not they are equal. 71 00:05:42,430 --> 00:05:47,380 Now, although later this year is already in the alphabetical order, we will sort it because we will 72 00:05:47,380 --> 00:05:50,160 expand it to contain other characters later. 73 00:05:50,680 --> 00:05:57,280 So hence we are saying string key is passed on to the list method here and the list value written is 74 00:05:57,280 --> 00:05:59,170 stored in the variable named list. 75 00:06:00,490 --> 00:06:07,180 Then the letters constant that we have created this past on again to the list method in the next line, 76 00:06:07,420 --> 00:06:10,670 which is on the list in again all sorted order. 77 00:06:10,690 --> 00:06:17,080 That is again in ABCDE that now after this we are doing here the list in the list. 78 00:06:17,080 --> 00:06:23,770 SDR and the letters list are then sorted in the alphabetical order by calling the sort list method on 79 00:06:23,770 --> 00:06:23,990 them. 80 00:06:24,370 --> 00:06:30,310 Now note that similar to the appendix method, short list also modifies the list in the place and doesn't 81 00:06:30,310 --> 00:06:31,400 have a written value. 82 00:06:31,840 --> 00:06:39,160 So when the list and the letter list SDR values should be the same because he lists SDR will simply 83 00:06:39,160 --> 00:06:42,130 be correct later this year with an order scramble. 84 00:06:42,610 --> 00:06:50,710 So when we check whether the values of Aschiana letters this year are equal, the values are then after 85 00:06:50,710 --> 00:06:55,450 checking it, they are basically written values, then passed on to the matter there. 86 00:06:55,840 --> 00:07:02,740 So over here, in case this returns true if they are equal and have no duplicates, but if your list 87 00:07:02,740 --> 00:07:04,930 is there and that does, it still doesn't match. 88 00:07:04,940 --> 00:07:10,890 The key is invalid and it is written for what's now coming to the wrapper function. 89 00:07:11,110 --> 00:07:15,310 The encryption or the decryption code in the program are almost identical. 90 00:07:15,310 --> 00:07:20,320 If you can see here when you have two similar pieces of code, it's best to put them into a function 91 00:07:20,320 --> 00:07:23,070 and call it twice rather than enter the court. 92 00:07:23,650 --> 00:07:29,060 So not only does this save your time, but also more importantly, it avoids introducing books like 93 00:07:29,060 --> 00:07:29,590 Copying and. 94 00:07:30,740 --> 00:07:38,420 So it's also advantageous because that is very small every quarter and you have to only fix one book 95 00:07:38,420 --> 00:07:41,510 at a time instead of looking at for multiple places. 96 00:07:41,810 --> 00:07:47,510 So this rappel function helps you avoid having to enter duplicate code by wrapping the code of another 97 00:07:47,510 --> 00:07:49,540 function and returning the value. 98 00:07:49,550 --> 00:07:56,120 The wrapped function with often the wrapper function makes a slight change to the arguments of the return 99 00:07:56,120 --> 00:07:57,940 values of the wrapper function. 100 00:07:58,160 --> 00:08:02,750 Otherwise, there would be no need for wrapping because you could just call the function directly.