1 00:00:00,420 --> 00:00:08,070 Now, let's see another option in all of I forget, that is a definition which is encrypted messages 2 00:00:08,070 --> 00:00:09,330 to decrypt messages. 3 00:00:09,960 --> 00:00:16,680 So now, because the decryption and encryption code is mostly the same, will create to wrapper functions 4 00:00:16,680 --> 00:00:18,360 that this one is able to encrypt. 5 00:00:18,370 --> 00:00:19,650 Messages still function. 6 00:00:19,950 --> 00:00:20,910 Another is over. 7 00:00:20,910 --> 00:00:28,830 Decrypt messages and for the function that is of a translated message which we are going to use or which 8 00:00:28,830 --> 00:00:31,200 will hold the actual code to encrypt. 9 00:00:32,130 --> 00:00:37,490 So over here we are just calling that particular method or call it a method transfer. 10 00:00:37,510 --> 00:00:41,890 Was it instead understanding the value which has been returned by the particular method? 11 00:00:42,090 --> 00:00:48,680 So the translated messages still function versus the encrypted or decrypted string one character at 12 00:00:48,690 --> 00:00:55,350 a time and the list in translated are stored these characters so they can be joined when the string 13 00:00:55,350 --> 00:00:56,730 building is done. 14 00:00:56,970 --> 00:01:03,990 So if we come to the translated messages, start them moment we have here the blank string and the string 15 00:01:03,990 --> 00:01:07,920 Asgeir, which is we are converting it to the uppercase value. 16 00:01:08,130 --> 00:01:14,910 So keep in mind that Evgenia for this just this is a cipher, except a different key is used depending 17 00:01:14,910 --> 00:01:17,140 on the position of the letter in the message. 18 00:01:17,400 --> 00:01:24,480 So the key IDEX variable which keeps track of which suppy to use, starts at zero by default because 19 00:01:24,480 --> 00:01:30,920 the letter used to encrypt decrypt the first character of the messages steer the index zettl. 20 00:01:31,230 --> 00:01:37,380 So the program assumes that the key is in all uppercase letters to make sure the key is valid. 21 00:01:37,950 --> 00:01:41,730 So we call the function there and the rest of the code. 22 00:01:41,730 --> 00:01:45,350 In the translated message, Asgeir is similar to your Caesar cipher. 23 00:01:45,930 --> 00:01:50,190 So we are sitting here for a while and the message is still voted. 24 00:01:50,250 --> 00:01:55,050 No one is equal to the letter tested or to find and convert it to Apple check. 25 00:01:55,050 --> 00:01:58,190 If no one is not equal to one, then you check. 26 00:01:58,200 --> 00:02:03,400 If it is equal to encrypt, then find it and appended to the given letters. 27 00:02:03,570 --> 00:02:09,450 Similarly, if it is decrypt, subtract the value from the letter Oresteia and at the end then we are 28 00:02:09,450 --> 00:02:13,260 seeing it do more and add value to the letter. 29 00:02:13,310 --> 00:02:20,010 So after the for loop it sets the characters in the message to the variable SVM that the symbol on each 30 00:02:20,010 --> 00:02:26,040 iteration of the loop and it finds the index of the uppercase version of Cimolino letters now, which 31 00:02:26,040 --> 00:02:28,480 is how we translate a letter into one number. 32 00:02:28,710 --> 00:02:34,580 So if no one isn't set to minus one, the uppercase symbol was found in the letters. 33 00:02:34,580 --> 00:02:41,520 This still meaning that symbol is a particular letter and the key variable keeps track of which subcu 34 00:02:41,520 --> 00:02:42,120 to use. 35 00:02:42,120 --> 00:02:47,040 And the is always what Yawkey of the index of evaluates to. 36 00:02:47,450 --> 00:02:50,310 So of course this is just a single letter string. 37 00:02:50,310 --> 00:02:56,240 We need to find this letters index in the letters as to how to convert this up to an individual. 38 00:02:56,250 --> 00:03:02,440 And this individual is then added if encrypted encrypting in symbols number or subtracted is grappling 39 00:03:02,460 --> 00:03:03,440 with this enormous number. 40 00:03:03,840 --> 00:03:10,920 And in the seas, I reject whether the new value of the number was less than zero, in which case we 41 00:03:10,920 --> 00:03:16,350 added then the length of letters is still to it, or whether the new value of number one was the length 42 00:03:16,350 --> 00:03:20,280 of letters is still greater in which we subtracted the value from it. 43 00:03:20,700 --> 00:03:23,550 So these check handles the wraparound cases. 44 00:03:23,860 --> 00:03:27,690 However, there is a simpler way to handle both of these cases. 45 00:03:27,960 --> 00:03:35,190 If we more the integer stored in the number one by the length of the letter this year, we can accomplish 46 00:03:35,190 --> 00:03:37,460 the same calculation in a single line of code. 47 00:03:37,740 --> 00:03:42,700 Hence we have done this over here saying no more is equal to length of letters this year. 48 00:03:43,200 --> 00:03:48,710 For example, see if numbers minus eight we would want to add twenty six. 49 00:03:48,720 --> 00:03:55,860 That is the length of the start to get B and that can be expressed as minus eight modulo twenty six 50 00:03:55,860 --> 00:04:02,310 which evaluates to eighty or if numbers thirty one we would want to subtract twenty six to get five 51 00:04:02,610 --> 00:04:09,420 and thirty one modulo twenty six evaluates to five new modular arithmetic hander's voted up or down 52 00:04:09,420 --> 00:04:09,950 cases. 53 00:04:10,320 --> 00:04:16,100 The encrypted order, the decrypted character exist in the letters as the index of number. 54 00:04:16,220 --> 00:04:24,050 However, if we want the encrypted or the decrypted characters case to match the original case of symbol, 55 00:04:24,330 --> 00:04:26,010 hence we are checking over here. 56 00:04:26,010 --> 00:04:33,810 If symbol that is converted to uppercase and appended if it is in law, then converted to lowercase 57 00:04:33,810 --> 00:04:34,230 and then. 58 00:04:34,860 --> 00:04:41,790 So if the symbol is in an uppercase, then if the condition is true, it upends the letters of the characters 59 00:04:41,790 --> 00:04:47,610 at letters index number to the translated Asgeir because all the characters are already in uppercase. 60 00:04:47,730 --> 00:04:54,240 However, if the symbolism, the lowercase letter, the condition is true instead in the next line it 61 00:04:54,240 --> 00:04:59,700 up in the lowercase form of the letters at the index number two translated is. 62 00:05:00,170 --> 00:05:06,920 So this is how the encrypted all the decrypted message match the original message, now that we have 63 00:05:06,920 --> 00:05:13,770 translated this email, we want to ensure that on the next iteration of the loop, we use the next subject. 64 00:05:14,090 --> 00:05:20,840 Hence, we increment the key idea by one in the next line over here thinking X plus is equal to one 65 00:05:21,290 --> 00:05:21,980 click here. 66 00:05:21,980 --> 00:05:26,360 If the key idea is equal to the left of is make it again zero. 67 00:05:26,810 --> 00:05:31,540 So how about if we vote on the last supporting the give X then the key. 68 00:05:31,550 --> 00:05:38,660 All the GST are the X would be equal to the length of the USDA, hence this check condition and we the 69 00:05:38,890 --> 00:05:46,950 it back to zero if that's the case, so that the key to the index of X points back to the first subcu. 70 00:05:47,390 --> 00:05:54,020 Now after this, if we see here, the indentation indicates that the statement is spelled with the if 71 00:05:54,020 --> 00:06:00,440 statement which just started in the for loop after something no one is equal to let Orestiada fine. 72 00:06:00,770 --> 00:06:05,220 So here the code executes if the symbol was not found in the letters. 73 00:06:05,630 --> 00:06:11,570 Now this happens if symbolism no other punctuation mark like say a number, anything like six, seven 74 00:06:11,570 --> 00:06:15,090 something or a punctuation say like a question mark or something like that. 75 00:06:15,170 --> 00:06:21,630 So in that case, it upends the unmodified symbol directly to the translator SDR variable. 76 00:06:21,920 --> 00:06:29,270 So now that we are done building a string and translated Asgeir, we call the joint letter here on the 77 00:06:29,270 --> 00:06:30,050 blank string. 78 00:06:30,290 --> 00:06:35,960 So this line makes the functions work on the whole encrypted order, decrypted message when the function 79 00:06:35,960 --> 00:06:36,950 is called. 80 00:06:37,340 --> 00:06:44,240 Hence after this we just see the lines that cause the main function of the program was run by itself 81 00:06:44,240 --> 00:06:51,710 rather than by being imported by another program that wants to use its encrypt message or decrypt messages 82 00:06:51,710 --> 00:06:52,780 to functions. 83 00:06:53,000 --> 00:06:59,860 So with this, we have understood how the particular Virginia cipher demo executes and what is the core 84 00:06:59,870 --> 00:07:01,860 meaning that we have already written. 85 00:07:02,240 --> 00:07:06,770 So let's continue with the next part or the next session in this advanced course. 86 00:07:06,770 --> 00:07:11,230 That is our frequency analysis in this frequency analysis. 87 00:07:11,780 --> 00:07:17,780 You will learn how to determine the frequency of each English letter in a particular text. 88 00:07:18,140 --> 00:07:24,890 You will then compare this frequency to the frequencies of your ciphertext to get information about 89 00:07:24,890 --> 00:07:29,060 the original plaintext, which will help you break the encryption.