1 00:00:00,720 --> 00:00:05,700 Let's look at an example of using the proper functioning of a code and understand how they basically 2 00:00:05,700 --> 00:00:12,460 look now, in our case, we are having the functions and trip message is and the message is, which 3 00:00:12,480 --> 00:00:14,650 are basically as a wrapper functions. 4 00:00:14,970 --> 00:00:21,000 Now, each of these functions called the method that is translated, my suggestion, which is wrapped 5 00:00:21,000 --> 00:00:26,540 function and return, don't value that particular task that the message is written now. 6 00:00:26,840 --> 00:00:32,880 We will look at this translated message is still a qualitative decision, but because both Apple functions 7 00:00:32,880 --> 00:00:39,150 use the same function, we need to modify only one function instead of two functions, which is encrypt 8 00:00:39,150 --> 00:00:40,570 messages and decrypt. 9 00:00:40,950 --> 00:00:47,130 Now with this Reppel functions, someone will import a program that we have created and call a particular 10 00:00:47,130 --> 00:00:54,470 function name and message Asgeir or decrypt messages just as they can with all the other cipher programs, 11 00:00:54,490 --> 00:01:00,600 programs, Apple functions, have clear names and tell others who basically use the function that will 12 00:01:00,600 --> 00:01:03,580 do the function without having to look at the code. 13 00:01:03,930 --> 00:01:08,580 So as a result, if we want to share our code, others can also use it more easily. 14 00:01:08,970 --> 00:01:14,700 And other programs can encrypt the message in various silos by importing the Saiful programs and calling 15 00:01:14,700 --> 00:01:21,190 the encrypt messages functions as we can do it, like importing the program and seeing the program name 16 00:01:21,190 --> 00:01:22,590 both the encrypt messages. 17 00:01:23,250 --> 00:01:29,070 So naming consistency is helpful because it makes it easier for someone familiar with one of the Saiful 18 00:01:29,070 --> 00:01:31,350 programs to use other Saiful programs. 19 00:01:31,620 --> 00:01:37,920 For example, you can see that we can see the first parameter is always a second parameter is always 20 00:01:37,920 --> 00:01:41,810 a message, which is the convention used for most of the Saiful programs. 21 00:01:42,030 --> 00:01:44,580 So using a translated message is still a function. 22 00:01:44,580 --> 00:01:50,490 Instead of a separate encryption, the group functions would be inconsistent with other programs. 23 00:01:50,790 --> 00:01:55,900 Now let us look at the code that we have given for translate message ASDF function. 24 00:01:56,220 --> 00:02:01,680 Now the translated message is still function is used for both the encryption and decryption. 25 00:02:01,680 --> 00:02:09,930 But notice that the transmitted message Asgeir has a parameter for key messages and also a third parameter 26 00:02:09,930 --> 00:02:11,280 named Modesta. 27 00:02:11,530 --> 00:02:17,550 Now when we try calling translated message Astarte, call in the encrypt function passes and encrypt 28 00:02:18,130 --> 00:02:19,740 string to Monastir. 29 00:02:19,980 --> 00:02:25,060 Similarly, from the decrypt function, it is passing the string decrypt for Modesta. 30 00:02:25,370 --> 00:02:31,670 Now this is how we translate messages gitanos whether it should be encrypted or decrypt the given message. 31 00:02:32,010 --> 00:02:37,860 So the actual encryption process is simple for each letter in the message parameter function, lookup, 32 00:02:37,860 --> 00:02:41,540 start letters index in your letter this year and replace it. 33 00:02:41,550 --> 00:02:45,210 That connected with the letter at the same index in the key parameter. 34 00:02:45,390 --> 00:02:47,090 So decryption does the opposite. 35 00:02:47,100 --> 00:02:52,110 It looks up the index in keys and replaces the characters with the character that the same index in 36 00:02:52,110 --> 00:02:59,790 letters is now instead of using letters and the program uses of variables that even and B1, which allows 37 00:02:59,790 --> 00:03:06,120 it to replace the letters in CAD even with letters, add the same index and not even being able to change 38 00:03:06,120 --> 00:03:08,240 which values are assigned to add even. 39 00:03:08,240 --> 00:03:12,900 And Beevor makes it easy for the program to switch between encrypting and decrypting. 40 00:03:13,290 --> 00:03:19,280 So here we are sending the characters in that, even to characters in letters, and then connect those 41 00:03:19,290 --> 00:03:21,390 and be one to the characters in the keys. 42 00:03:21,390 --> 00:03:27,480 If we can look over here now, keeping in mind that the goal in this particular method always replaces 43 00:03:27,480 --> 00:03:31,010 the characters, even with characters in the same index and Beevor. 44 00:03:31,350 --> 00:03:36,960 So when we swap the values, the code does the decryption process instead of the encryption process. 45 00:03:37,170 --> 00:03:43,170 And then the next line in the program finds the indexes to use the encryption and the decryption. 46 00:03:43,390 --> 00:03:49,190 Now we have a for loop here, which says the symbol or the same variable to a character in the message 47 00:03:49,200 --> 00:03:52,140 is the string on each iteration through the loop. 48 00:03:52,320 --> 00:03:59,010 And if the uppercase form of this symbol exists in God, even then it finds the index of the uppercase 49 00:03:59,010 --> 00:04:05,270 form uppercase form of the symbol in Cat A1 and same index variable stores this index. 50 00:04:05,530 --> 00:04:11,700 Now we already know that defined method would never return, minus because we are from defined matter. 51 00:04:11,700 --> 00:04:14,420 It means that argument could be found in the string. 52 00:04:14,430 --> 00:04:21,420 So because of the if statement guarantee suggests it will not exist in even otherwise, we won't have 53 00:04:21,420 --> 00:04:22,470 been executed. 54 00:04:22,890 --> 00:04:29,190 So in each encrypted or decrypted symbol to build the string that is only translated message is still 55 00:04:29,190 --> 00:04:29,730 function. 56 00:04:29,970 --> 00:04:34,740 But because the key and the letters are both only in uppercase, we need to check whether the original 57 00:04:34,740 --> 00:04:39,990 symbol and message was then adjusted or the encrypted symbol lowercase. 58 00:04:40,350 --> 00:04:45,100 Now, for doing this, we have to learn to string methods, which is is apparent is lower. 59 00:04:45,450 --> 00:04:48,540 So moving on to is opponent is lower string methods. 60 00:04:48,870 --> 00:04:52,400 The store methods check whether the string is in the application lowercase. 61 00:04:52,410 --> 00:04:55,050 Now more specifically, it is a postering method. 62 00:04:55,050 --> 00:04:59,780 Returns to evoke the conditions are meant that a string has at least one uppercase letter. 63 00:05:00,200 --> 00:05:06,410 Australia does not have any lowercase letters and is lobstering method written through both of the conditions 64 00:05:06,410 --> 00:05:12,070 are met that this strain has at least one lowercase on the string, doesn't have any uppercase letters. 65 00:05:12,380 --> 00:05:17,930 So this nonlocal little characters in the string doesn't affect whether this method semitone true or 66 00:05:17,930 --> 00:05:18,380 false. 67 00:05:18,650 --> 00:05:27,020 Although both the letters evaluate to force, if only non existent does not reject this. 68 00:05:27,170 --> 00:05:33,890 Suppose we just go to the interactive shell here and we try to enter in this see python. 69 00:05:34,430 --> 00:05:40,810 Then Dot is Apple press and we get to all. 70 00:05:40,820 --> 00:05:42,470 We enter python. 71 00:05:44,450 --> 00:05:54,500 Hacking, one, two, three, dot, is Apple still related to all of the Internet and lowercase and 72 00:05:54,500 --> 00:05:55,280 check is. 73 00:05:57,720 --> 00:05:58,250 Law. 74 00:05:59,780 --> 00:06:04,960 We get it, or if we see one, two, three, vote is up. 75 00:06:05,540 --> 00:06:06,560 This will be false. 76 00:06:06,830 --> 00:06:12,770 Or if we see just a blank and saying is, look, this is also false. 77 00:06:13,250 --> 00:06:20,480 So in this, for example, returns true, OK, because all the characters has at least the text that 78 00:06:20,480 --> 00:06:23,710 we have written has at least one uppercase in it and all lowercase. 79 00:06:24,440 --> 00:06:27,140 The numbers in the string doesn't affect the evaluation. 80 00:06:27,440 --> 00:06:30,830 In the second one we have to check for is lower. 81 00:06:30,990 --> 00:06:37,070 OK, now this also returns true because a string python has at least one lowercase letters in it and 82 00:06:37,070 --> 00:06:37,790 no uppercase. 83 00:06:38,120 --> 00:06:44,480 And now let's return to our code, which we have written to see how to use these approaches, lower 84 00:06:44,480 --> 00:06:45,380 string methods. 85 00:06:45,650 --> 00:06:48,200 So if we come over here, we have checking. 86 00:06:48,210 --> 00:06:53,810 This is a portal is lower in the for loop in the same way right now. 87 00:06:53,810 --> 00:06:59,000 In the program that we have written, we have used here is appearance's lower string methods to help 88 00:06:59,000 --> 00:07:03,780 ensure that the cases of the plaintext are reflected in the ciphertext. 89 00:07:04,160 --> 00:07:11,990 So here we are checking that is we are checking it for this, converting to Upwood over here first and 90 00:07:11,990 --> 00:07:13,810 then we are checking if it doesn't appear. 91 00:07:13,820 --> 00:07:17,990 What are you supposed to do if it does not end up also develop? 92 00:07:18,710 --> 00:07:20,130 So then what you're supposed to do. 93 00:07:20,720 --> 00:07:26,750 So over here, we first check whether the symbol has an uppercase letter, if it does concatenate the 94 00:07:26,750 --> 00:07:31,910 uppercase version of the characters Addicott V1 to be translated Ostia. 95 00:07:32,330 --> 00:07:37,640 So this results in the uppercase version of the key character corresponding to the uppercase input. 96 00:07:37,910 --> 00:07:43,610 Now, if this symbol instead has a lowercase correct, then it concatenate the lowercase version of 97 00:07:43,610 --> 00:07:44,990 the characters from guys. 98 00:07:44,990 --> 00:07:47,220 We want to be translated next. 99 00:07:47,510 --> 00:07:53,090 OK, so if it is upper concatenate to Apple, if it doesn't look, concatenate to the lower one. 100 00:07:53,360 --> 00:07:59,540 So if the symbol is not a character in the symbol set, such as any number or a question mark or a comma, 101 00:07:59,750 --> 00:08:04,760 it would return false and would execute instead of executing this. 102 00:08:05,270 --> 00:08:09,680 So here it will just execute the next part of the statement. 103 00:08:09,980 --> 00:08:16,430 So if your symbols are not letters, then this means that we cannot and decrypt the character in the 104 00:08:16,430 --> 00:08:16,900 symbol. 105 00:08:17,150 --> 00:08:23,470 So we simply concatenate to the end of the translated acedia like over here we have done in this case. 106 00:08:23,780 --> 00:08:30,710 OK, so at the end your message is your function will return the value in the translated SDR variable, 107 00:08:30,710 --> 00:08:33,830 which contains the encrypted or the decrypted message. 108 00:08:34,130 --> 00:08:39,650 Now let's look at the GEGE random key function to generate a valid key for a simple substitution cipher. 109 00:08:40,070 --> 00:08:45,800 Now typing this particular matter for a key that contains each letter of the alphabet can be difficult 110 00:08:45,800 --> 00:08:46,790 to help this. 111 00:08:47,000 --> 00:08:53,720 We have this get a random key estar function which returns a valid to users I would randomly scramblers. 112 00:08:53,720 --> 00:08:57,110 The characters in the letters are constant mightly. 113 00:08:57,110 --> 00:08:59,390 We are seeing random for leakiest. 114 00:08:59,600 --> 00:09:01,400 OK, now do use this. 115 00:09:01,400 --> 00:09:09,200 You can just substitute said this particular method name that is get a random start and you can substitute 116 00:09:09,200 --> 00:09:11,450 this over here in Mikie. 117 00:09:11,450 --> 00:09:15,200 So let us just come into this and we would again write down. 118 00:09:15,560 --> 00:09:19,370 My guess is equal to say get random. 119 00:09:20,420 --> 00:09:22,190 Now let's check the output. 120 00:09:22,490 --> 00:09:28,730 OK, so now if we execute this thing, it is generating some random key and that is a decrypted message 121 00:09:28,730 --> 00:09:29,420 used for it. 122 00:09:29,690 --> 00:09:33,130 So in this way, we can also execute this particular part. 123 00:09:33,440 --> 00:09:40,440 And after this execution, the last part that we have is checking that at the end of the program. 124 00:09:40,460 --> 00:09:45,830 Call me if it is being run as a program instead of being imported as a model by another program. 125 00:09:46,070 --> 00:09:52,690 Hence we conclude that our simple substitution cipher program is very much easy as compared to others. 126 00:09:53,180 --> 00:09:58,910 Type of program that we have done is basically substituting this character by character with some different 127 00:09:58,910 --> 00:09:59,480 characters. 128 00:09:59,870 --> 00:10:04,700 OK, so that is how we have created the program and understood how the program has been created.