1 00:00:00,240 --> 00:00:07,710 The transposition cipher uses an integer for a key which is stored in your Michy Istar variable, and 2 00:00:07,710 --> 00:00:16,770 the program accepts the more ETR variable which will store either in or decrypt to tell it to encrypt 3 00:00:16,770 --> 00:00:19,540 or decrypt the file input namaskar fine. 4 00:00:19,890 --> 00:00:27,810 But before we can read from the input finally Mystere, we need to check that it exist using the OS 5 00:00:27,840 --> 00:00:30,080 dot but not exist. 6 00:00:30,450 --> 00:00:37,170 So coming to checking whether a fire is existing, we are reading files is always harmless, but you 7 00:00:37,170 --> 00:00:40,710 need to be careful when writing to the files. 8 00:00:41,310 --> 00:00:47,790 So calling the open function in the right mode on a file name that already exist overrides the original 9 00:00:47,790 --> 00:00:48,310 content. 10 00:00:48,630 --> 00:00:55,980 So using the OS dot, dot, dot exist function in your program can check whether or not that file already 11 00:00:56,010 --> 00:01:01,090 exist, not understanding the overstored part, the DOT exist function. 12 00:01:01,350 --> 00:01:07,050 It takes a single string argument for a file name or a part or to a file and returns. 13 00:01:07,050 --> 00:01:10,220 True, if the file already exist and falls. 14 00:01:10,260 --> 00:01:17,850 If it doesn't, the always path don't exist function exist inside the part module which exists inside 15 00:01:17,850 --> 00:01:18,760 the OS module. 16 00:01:19,050 --> 00:01:23,530 So when we import the module, the path module is important also. 17 00:01:23,910 --> 00:01:32,130 So for example, if we just go to our interactive shell and here if we try to enter the same import 18 00:01:32,130 --> 00:01:36,930 OS first, then we say always stored but not exist. 19 00:01:37,260 --> 00:01:43,320 And here we give say ABC Dot, the 60 in the bracket. 20 00:01:43,320 --> 00:01:44,450 We get the value through. 21 00:01:44,940 --> 00:01:55,920 If we try to say overstored but not exist in bracket, we give your face equal numbers, then Windows 22 00:01:56,310 --> 00:02:02,490 CE System 32, then calc dot. 23 00:02:03,150 --> 00:02:06,300 Except for example, we get it through. 24 00:02:07,220 --> 00:02:13,500 Suppose you are not on Windows your own Mac OS, then you will have to write down something like No, 25 00:02:13,520 --> 00:02:20,130 I will execute this, but just showing you how the command would look like it will be slash, say USCIRF, 26 00:02:20,450 --> 00:02:28,130 then say local, then say Binn and then say, oh, fine name, which is there for Mac OS. 27 00:02:28,400 --> 00:02:37,220 And if you're on Linux then you will have to write down, say, user slash bin and slash the fine. 28 00:02:37,790 --> 00:02:43,910 That's how you can check the path existing on all the given operating systems now. 29 00:02:44,920 --> 00:02:51,580 In the particular example that we have checked for the function, it confirms that the TalkTalk file 30 00:02:51,580 --> 00:02:52,680 is there in Windows. 31 00:02:53,020 --> 00:02:57,850 Of course, you will only get the results if you are running Python on Windows. 32 00:02:58,210 --> 00:03:04,600 Now, remember to escape the backslash in the Windows file part by typing another backslash before it. 33 00:03:04,900 --> 00:03:09,940 If you're using Mac OS, only the Mac OS example will return to no. 34 00:03:10,180 --> 00:03:17,510 Coming back, we will check whether the input file exist with the oyster or part does not exist function. 35 00:03:17,770 --> 00:03:25,780 So when we are using this in our Demo 17 file to check whether the filename in the input file name is 36 00:03:25,780 --> 00:03:31,890 still exist, otherwise we have no file to encrypt or to decrypt it. 37 00:03:32,500 --> 00:03:39,100 So if we say if not always dot, dot, dot, exist the input, find the Mystere, then we are printing 38 00:03:39,310 --> 00:03:41,140 a message that is the file. 39 00:03:41,350 --> 00:03:47,060 The name does not exist, giving quiting and parsing that the input filename. 40 00:03:47,320 --> 00:03:54,100 So if the file doesn't exist, we display a message to the user and then with the particular program 41 00:03:54,490 --> 00:04:00,130 next, we are using the string methods to make user input more flexible. 42 00:04:00,550 --> 00:04:06,400 Now next, the program checks here whether a file with the same name as the output filename exist, 43 00:04:06,640 --> 00:04:13,780 and if so, it asks the user to type see if they want to continue running the program or to quit the 44 00:04:13,780 --> 00:04:21,310 program now because the user might type various responses, like a small C, a capital C or even the 45 00:04:21,310 --> 00:04:23,430 word continue with C capital. 46 00:04:23,680 --> 00:04:27,760 We want to make sure that the program will accept all of these versions. 47 00:04:28,240 --> 00:04:32,560 To do this, we are basically using more string methods here. 48 00:04:32,830 --> 00:04:36,370 That is upper lower title string methods. 49 00:04:36,640 --> 00:04:39,120 So that is over here that we're checking out. 50 00:04:39,310 --> 00:04:42,940 So the upper and lower string methods will return the string. 51 00:04:42,940 --> 00:04:49,810 They are called on in an upper case or lower case letters respectively, and enter the following into 52 00:04:49,810 --> 00:04:54,430 the interactive shell to see how the methods basically work on the same string. 53 00:04:54,670 --> 00:05:02,980 So, for example, if we go back to the python shell here and we try to enter, say, Python, Doc Apple, 54 00:05:04,660 --> 00:05:12,820 we get that all in the uppercase or we try to enter Python doc level, we get all in the lowercase. 55 00:05:13,060 --> 00:05:18,400 Now, just as the lower and the upper string methods return a string and lowercase or uppercase, the 56 00:05:18,400 --> 00:05:24,880 title string method returns string in the title keys title cases where the first character of every 57 00:05:24,880 --> 00:05:29,170 word is uppercase and the rest of the characters are in the lowercase. 58 00:05:29,440 --> 00:05:36,070 For example, if we enter something like Python Dot type it, we get it. 59 00:05:36,070 --> 00:05:39,180 First character in upo dressed all in small. 60 00:05:39,340 --> 00:05:46,090 Similarly, if you enter everything in some capital and still you title, it will be converted in the 61 00:05:46,090 --> 00:05:46,900 same manner. 62 00:05:47,260 --> 00:05:58,120 Or if you have, say, python hacking goes beginner level everything you'll want to convert to type 63 00:05:58,150 --> 00:05:58,400 them. 64 00:05:58,420 --> 00:06:03,100 So every word, the first character will be in capital. 65 00:06:03,490 --> 00:06:09,040 So we are using title a little later in the session to format messages we output for the user. 66 00:06:09,460 --> 00:06:16,810 Now on we would be coming with first as the using this starts with and the ends with string methods. 67 00:06:17,050 --> 00:06:19,390 So this start with method returns. 68 00:06:19,390 --> 00:06:27,130 True, if it's string argument is found at the beginning of the string, for example, if we see Python 69 00:06:27,550 --> 00:06:38,050 then thought starts with and here we give capital P for example, we get the values through, or in 70 00:06:38,050 --> 00:06:44,140 that case we see Python starts with and we give here. 71 00:06:44,980 --> 00:06:49,600 I get the values Foote's for this case. 72 00:06:49,850 --> 00:06:57,190 You can also take a variable, for example, C John is the value in the variable and we use this variable 73 00:06:57,290 --> 00:07:01,270 that starts with and we give your up. 74 00:07:02,230 --> 00:07:03,780 Still, the value would be true. 75 00:07:04,000 --> 00:07:10,210 So this starts with method is case sensitive and can also be used on strings with multiple characters. 76 00:07:10,450 --> 00:07:16,720 Similarly, we have the ends with string method, which is used to check whether a string value ends 77 00:07:16,720 --> 00:07:18,700 with another specified string value. 78 00:07:19,450 --> 00:07:29,620 For example, if we say here, python hacking dot C ends with in brackets, we give hacking. 79 00:07:30,400 --> 00:07:31,150 It is true. 80 00:07:31,570 --> 00:07:43,120 Or if we try to say again in single code five ten hacking ends would give your ex capital list everything. 81 00:07:43,120 --> 00:07:44,440 Same at this for. 82 00:07:44,890 --> 00:07:47,870 So the string values must match perfectly. 83 00:07:47,890 --> 00:07:55,350 Notice that the lack of exclamation mark or your capital letters will also cause an injury to return 84 00:07:55,570 --> 00:08:00,940 value as Foote's now will come to using these string methods in our program. 85 00:08:00,970 --> 00:08:03,100 So now let us go back to the more 17. 86 00:08:03,400 --> 00:08:10,820 As noted, we want the program to accept any response that starts with a capital C, regardless of capitalization. 87 00:08:10,840 --> 00:08:13,780 So this means that we want the file to be overridden. 88 00:08:14,050 --> 00:08:21,970 Whether the user types moisy continue in small C capital or another string that begins with C Soulsville 89 00:08:22,120 --> 00:08:28,090 use the string methods lower, starts to make the program more flexible when taking the user input. 90 00:08:28,450 --> 00:08:34,780 So over here, when we are checking over here, if the Oyster Bar don't exist, the output filename 91 00:08:34,780 --> 00:08:36,240 is still reprint. 92 00:08:36,280 --> 00:08:37,540 This will be overridden. 93 00:08:37,810 --> 00:08:42,180 Type C or Q4 quick and then reticular. 94 00:08:42,190 --> 00:08:52,210 The response saying response SDR is equal to input and use that the more than sine, if not response 95 00:08:52,210 --> 00:08:54,850 total overall starts with C, then you exit. 96 00:08:55,240 --> 00:09:02,170 So over here we are taking the first letter of the string and check whether at this C using this starts 97 00:09:02,170 --> 00:09:08,020 with method, starts with method that is used in case sensitive and checks for a Lawsie. 98 00:09:08,230 --> 00:09:14,500 So we have used a lower method to modify the response of the string capitalization to always be in the 99 00:09:14,500 --> 00:09:15,140 lowercase. 100 00:09:15,520 --> 00:09:21,450 So if the user didn't enter a response starting with C, then this starts with would return for it's 101 00:09:21,460 --> 00:09:28,870 not otherwise which will make the if statement to evaluate to true, because if not in the if statement, 102 00:09:29,080 --> 00:09:31,660 this is what it is called to end the program. 103 00:09:31,930 --> 00:09:34,540 So technically the user doesn't have to enter. 104 00:09:34,540 --> 00:09:35,340 Q Two quick. 105 00:09:35,650 --> 00:09:42,820 Any string that doesn't begin with C causes the system exists function to be called and with the program. 106 00:09:43,180 --> 00:09:44,510 That's it from the session. 107 00:09:44,710 --> 00:09:45,640 Thank you very much.