1 00:00:00,360 --> 00:00:07,160 Now, let's have a look at random shuffle function now with the foundation in how the references work, 2 00:00:07,290 --> 00:00:12,870 we can now understand how the random dot shuffle function that we will be using next. 3 00:00:12,870 --> 00:00:20,940 Worx The random note shuffle function is a part of the random module and it accepts a list of argument 4 00:00:21,150 --> 00:00:24,870 whose items or whose items is randomly rearranges. 5 00:00:25,170 --> 00:00:30,320 We will enter certain code in the interactive shell and see how the random dot shuffle works. 6 00:00:30,660 --> 00:00:36,970 So over here the first thing we will have to do is import random then will create over. 7 00:00:37,020 --> 00:00:38,850 That's equal to zero. 8 00:00:38,940 --> 00:00:43,080 One, two, three, four, five, six, seven, eight, nine. 9 00:00:43,410 --> 00:00:47,850 And we will try to put in the value of where we get all the values printed. 10 00:00:48,180 --> 00:00:55,200 Then we will choose random dot shuffle and will parse the same variable as the parameter to it. 11 00:00:55,680 --> 00:01:00,870 And then we will try to bring the value of it as randomly shuffle it again. 12 00:01:00,870 --> 00:01:09,300 If we say random dot shuffle again follows the same variable in the parameter and again try to print 13 00:01:09,300 --> 00:01:10,530 the values again. 14 00:01:10,530 --> 00:01:12,700 It has been shuffled with some random values. 15 00:01:13,050 --> 00:01:17,850 So an important detail to note is that shuffle does not return on list value. 16 00:01:17,880 --> 00:01:25,080 Instead, it changes the list value that is passed to it because Shuffle modifies the list directly 17 00:01:25,080 --> 00:01:31,860 from the list reference values that is past the shuffle function modifies the list in place, which 18 00:01:31,860 --> 00:01:38,790 is why we execute random dot shuffle and we pass the variable instead of saying the variable is equal 19 00:01:38,790 --> 00:01:41,940 to random shuffle and again the variable will be passed. 20 00:01:42,270 --> 00:01:46,320 So coming on to randomly scrambling a particular string. 21 00:01:46,650 --> 00:01:52,070 So if we return to our code in the more 14. be right over here. 22 00:01:52,080 --> 00:01:59,640 If you see we are using the messages, jihad is equal to list in the messages here and seeing random 23 00:01:59,640 --> 00:02:01,780 dot shuffle the value of messages together. 24 00:02:02,310 --> 00:02:09,270 Now the return value from the list is a list of which value, which one character strength of each character 25 00:02:09,270 --> 00:02:10,950 in the string that is pastorate. 26 00:02:11,250 --> 00:02:15,600 So reassigning the message to be a list of its characters. 27 00:02:16,020 --> 00:02:17,550 Next, we'll shuffle. 28 00:02:17,550 --> 00:02:22,290 That randomise is the order of the items in the message and the program. 29 00:02:22,290 --> 00:02:27,840 Convert the list of string back to a string value using the joint method over here. 30 00:02:28,500 --> 00:02:33,910 Now this shuffling of a message string allows us to test many different messages. 31 00:02:34,350 --> 00:02:41,580 So now coming to testing each message over here in the print one, now that the random message has been 32 00:02:41,580 --> 00:02:47,970 made, the program test, the encryption and the decryption functions with it now will have the program 33 00:02:47,970 --> 00:02:51,810 put in some feedback so that we see what's going while at this testing. 34 00:02:51,960 --> 00:02:53,520 Hence we have given this print. 35 00:02:53,520 --> 00:03:00,210 Come on now here we have called the print that displays which test number the program is on. 36 00:03:00,420 --> 00:03:08,460 So we have added one to I over here because by default it starts from zero and the test number should 37 00:03:08,460 --> 00:03:12,310 start at one because the string in the message to start can be long. 38 00:03:12,330 --> 00:03:17,820 We are using a string slicing to show only the first 50 characters. 39 00:03:18,070 --> 00:03:24,030 Hence we are not displaying the whole message is yet, but only the first 50 characters of the message. 40 00:03:24,390 --> 00:03:28,110 Now, next, we also use string interpolation. 41 00:03:28,110 --> 00:03:35,200 The value that I plus one evaluate to replace the forced percentage is in the string and the value that 42 00:03:35,310 --> 00:03:42,960 message is Starkel and 50 evaluates to replace the second percentage is when using the string interpolation. 43 00:03:42,960 --> 00:03:49,020 Be sure that the number of percentage is in the string matches the number of values that are between 44 00:03:49,020 --> 00:03:51,510 the parentheses after now. 45 00:03:51,510 --> 00:03:54,360 Next we will test all the possibilities. 46 00:03:54,360 --> 00:04:00,180 Although the key for a Caesar cipher would be an integer between zero to sixty five, the length of 47 00:04:00,180 --> 00:04:01,560 the symbol or something like that. 48 00:04:01,770 --> 00:04:07,640 And the key for the transposition cipher can be between one and a half hour the length of the message. 49 00:04:07,830 --> 00:04:13,920 So the for loop here runs the test code with the key one up to the length of the message. 50 00:04:13,920 --> 00:04:15,810 Hence we have run this for Lapua. 51 00:04:16,110 --> 00:04:18,420 That is half of the length of the message. 52 00:04:18,900 --> 00:04:23,910 So then we are creating two variables that is encrypted and decrypted. 53 00:04:24,210 --> 00:04:32,910 So the encrypt the string in a message using the method that is encrypted message is that we have inside 54 00:04:32,910 --> 00:04:35,550 the file the more standard Beevor. 55 00:04:36,060 --> 00:04:43,830 So we need to r the demo then filename that is repeated sign at the end and are functioning. 56 00:04:44,250 --> 00:04:52,260 So the encrypted string that is returned from this encrypted messages is then passed on to the decrypted 57 00:04:52,420 --> 00:04:54,340 hestia or decrypted messages. 58 00:04:55,140 --> 00:04:59,880 Now the return value from the decrypt messages is stored in the variable name Decrypt. 59 00:05:00,430 --> 00:05:06,310 And if the function walks the string, the message should be the same as the string and the decrypted. 60 00:05:06,910 --> 00:05:09,750 Now we will look at the program that checks for this. 61 00:05:10,000 --> 00:05:16,320 So over here, after we have encrypted and decrypted the message, we need to check whether both the 62 00:05:16,330 --> 00:05:18,070 processes worked correctly. 63 00:05:18,400 --> 00:05:24,490 So to do that, we simply need to check whether the original message is the same as the decrypted message. 64 00:05:24,760 --> 00:05:26,850 Hence, we have written this particular code. 65 00:05:27,250 --> 00:05:34,820 When we test whether the message is clear and the victory protesters are equal and if they are in, 66 00:05:35,080 --> 00:05:42,760 then Python displays an error message on the next line that prints the key, the message and the decrypted 67 00:05:42,760 --> 00:05:49,160 value as the feedback to help us figure out what went wrong and then the program would exit. 68 00:05:49,630 --> 00:05:56,020 So normally the program exists when the execution reaches the end of the code and there are no more 69 00:05:56,020 --> 00:05:57,070 lines of execute. 70 00:05:57,700 --> 00:06:07,210 However, when we see System X, it is called the program ends immediately and stop testing the new 71 00:06:07,210 --> 00:06:13,330 messages because we will have to fix your cipher program even if one test fails. 72 00:06:13,750 --> 00:06:21,580 But if the value in the message is clear and the decrypted are equal, the program execution skips the 73 00:06:21,580 --> 00:06:29,230 if statement blocks and call to the system or exit program continuous looping until it finishes running 74 00:06:29,230 --> 00:06:30,460 all of the test. 75 00:06:30,700 --> 00:06:37,510 And after the loop ends, the program runs, which, you know, in the outside of the loop here and 76 00:06:37,510 --> 00:06:45,320 come here on the last print statement, which prints the transposition ciphertext has passed successfully. 77 00:06:45,730 --> 00:06:49,050 So after this will come on to calling the main function. 78 00:06:49,330 --> 00:06:54,790 So as with our other programs, we want to check whether the program is being important as a module 79 00:06:54,790 --> 00:06:56,840 or being run as the main file. 80 00:06:57,160 --> 00:07:03,040 So we are checking whether the special variable underscored name the is set to meet and if so, we are 81 00:07:03,040 --> 00:07:04,640 calling the main function. 82 00:07:05,050 --> 00:07:08,820 Now let's see, testing our test program that we have now. 83 00:07:08,860 --> 00:07:13,120 We have written a program that test the transposition cipher programs. 84 00:07:13,420 --> 00:07:16,300 But how do we know that the test program works? 85 00:07:16,570 --> 00:07:23,830 If the test program has a book and it just indicates that the transposition cipher programs work when 86 00:07:23,830 --> 00:07:30,280 they really don't, then we can test this program by purposefully adding a book to the encryption on 87 00:07:30,280 --> 00:07:31,440 the decryption function. 88 00:07:32,140 --> 00:07:38,810 Thus, if the test program doesn't detect the problem, we would know that it isn't running as expected. 89 00:07:39,190 --> 00:07:44,950 Now, to add a bug in the particular program, we would go to our demo tendered by file and we would 90 00:07:44,950 --> 00:07:47,020 add a certain line of code there. 91 00:07:47,530 --> 00:07:52,060 So let us go to our C demo, then be right. 92 00:07:52,630 --> 00:07:58,750 And let us add over here the current idea plus is equal bulkiest year plus one. 93 00:07:59,350 --> 00:08:00,520 Let us save this. 94 00:08:00,910 --> 00:08:05,060 And now let us again open our demo 14.. 95 00:08:06,010 --> 00:08:08,020 And now let's try to. 96 00:08:09,380 --> 00:08:17,430 Run the motive, it mismatch with GISTARO one and the given particular message decrypted this. 97 00:08:17,460 --> 00:08:19,030 So now that is not proper. 98 00:08:19,280 --> 00:08:20,990 So we have got the error message. 99 00:08:21,170 --> 00:08:27,230 When we faced a program, we get an error message that we have printed so that this program has to fail 100 00:08:27,230 --> 00:08:31,070 at the first message after we purposefully inserted a bug. 101 00:08:31,520 --> 00:08:34,530 So we know that isn't working exactly as we have planned. 102 00:08:35,210 --> 00:08:42,180 So now if you just go back there, go to your demo, then you remove this bug, you save it. 103 00:08:42,650 --> 00:08:52,490 Now, let us close this demo, then go back to our demo 14 and again, try to run the audio normal again. 104 00:08:52,490 --> 00:08:56,740 You will not have any error automatically execute successfully. 105 00:08:57,620 --> 00:09:04,160 So that is how we have actually added a bug and even tested if that airport was executing in our given 106 00:09:04,520 --> 00:09:05,420 Python program. 107 00:09:05,900 --> 00:09:12,450 So with this, we have concluded our testing of the transposition cipher with multiple key values. 108 00:09:12,830 --> 00:09:14,900 So that's it from this particular session. 109 00:09:15,200 --> 00:09:18,320 Hope you have understood with the help of the example that we have done. 110 00:09:18,650 --> 00:09:19,570 Thank you very much.