Now, let's have a look at random shuffle function now with the foundation in how the references work,
we can now understand how the random dot shuffle function that we will be using next.
Worx The random note shuffle function is a part of the random module and it accepts a list of argument
whose items or whose items is randomly rearranges.
We will enter certain code in the interactive shell and see how the random dot shuffle works.
So over here the first thing we will have to do is import random then will create over.
That's equal to zero.
One, two, three, four, five, six, seven, eight, nine.
And we will try to put in the value of where we get all the values printed.
Then we will choose random dot shuffle and will parse the same variable as the parameter to it.
And then we will try to bring the value of it as randomly shuffle it again.
If we say random dot shuffle again follows the same variable in the parameter and again try to print
the values again.
It has been shuffled with some random values.
So an important detail to note is that shuffle does not return on list value.
Instead, it changes the list value that is passed to it because Shuffle modifies the list directly
from the list reference values that is past the shuffle function modifies the list in place, which
is why we execute random dot shuffle and we pass the variable instead of saying the variable is equal
to random shuffle and again the variable will be passed.
So coming on to randomly scrambling a particular string.
So if we return to our code in the more 14. be right over here.
If you see we are using the messages, jihad is equal to list in the messages here and seeing random
dot shuffle the value of messages together.
Now the return value from the list is a list of which value, which one character strength of each character
in the string that is pastorate.
So reassigning the message to be a list of its characters.
Next, we'll shuffle.
That randomise is the order of the items in the message and the program.
Convert the list of string back to a string value using the joint method over here.
Now this shuffling of a message string allows us to test many different messages.
So now coming to testing each message over here in the print one, now that the random message has been
made, the program test, the encryption and the decryption functions with it now will have the program
put in some feedback so that we see what's going while at this testing.
Hence we have given this print.
Come on now here we have called the print that displays which test number the program is on.
So we have added one to I over here because by default it starts from zero and the test number should
start at one because the string in the message to start can be long.
We are using a string slicing to show only the first 50 characters.
Hence we are not displaying the whole message is yet, but only the first 50 characters of the message.
Now, next, we also use string interpolation.
The value that I plus one evaluate to replace the forced percentage is in the string and the value that
message is Starkel and 50 evaluates to replace the second percentage is when using the string interpolation.
Be sure that the number of percentage is in the string matches the number of values that are between
the parentheses after now.
Next we will test all the possibilities.
Although the key for a Caesar cipher would be an integer between zero to sixty five, the length of
the symbol or something like that.
And the key for the transposition cipher can be between one and a half hour the length of the message.
So the for loop here runs the test code with the key one up to the length of the message.
Hence we have run this for Lapua.
That is half of the length of the message.
So then we are creating two variables that is encrypted and decrypted.
So the encrypt the string in a message using the method that is encrypted message is that we have inside
the file the more standard Beevor.
So we need to r the demo then filename that is repeated sign at the end and are functioning.
So the encrypted string that is returned from this encrypted messages is then passed on to the decrypted
hestia or decrypted messages.
Now the return value from the decrypt messages is stored in the variable name Decrypt.
And if the function walks the string, the message should be the same as the string and the decrypted.
Now we will look at the program that checks for this.
So over here, after we have encrypted and decrypted the message, we need to check whether both the
processes worked correctly.
So to do that, we simply need to check whether the original message is the same as the decrypted message.
Hence, we have written this particular code.
When we test whether the message is clear and the victory protesters are equal and if they are in,
then Python displays an error message on the next line that prints the key, the message and the decrypted
value as the feedback to help us figure out what went wrong and then the program would exit.
So normally the program exists when the execution reaches the end of the code and there are no more
lines of execute.
However, when we see System X, it is called the program ends immediately and stop testing the new
messages because we will have to fix your cipher program even if one test fails.
But if the value in the message is clear and the decrypted are equal, the program execution skips the
if statement blocks and call to the system or exit program continuous looping until it finishes running
all of the test.
And after the loop ends, the program runs, which, you know, in the outside of the loop here and
come here on the last print statement, which prints the transposition ciphertext has passed successfully.
So after this will come on to calling the main function.
So as with our other programs, we want to check whether the program is being important as a module
or being run as the main file.
So we are checking whether the special variable underscored name the is set to meet and if so, we are
calling the main function.
Now let's see, testing our test program that we have now.
We have written a program that test the transposition cipher programs.
But how do we know that the test program works?
If the test program has a book and it just indicates that the transposition cipher programs work when
they really don't, then we can test this program by purposefully adding a book to the encryption on
the decryption function.
Thus, if the test program doesn't detect the problem, we would know that it isn't running as expected.
Now, to add a bug in the particular program, we would go to our demo tendered by file and we would
add a certain line of code there.
So let us go to our C demo, then be right.
And let us add over here the current idea plus is equal bulkiest year plus one.
Let us save this.
And now let us again open our demo 14..
And now let's try to.
Run the motive, it mismatch with GISTARO one and the given particular message decrypted this.
So now that is not proper.
So we have got the error message.
When we faced a program, we get an error message that we have printed so that this program has to fail
at the first message after we purposefully inserted a bug.
So we know that isn't working exactly as we have planned.
So now if you just go back there, go to your demo, then you remove this bug, you save it.
Now, let us close this demo, then go back to our demo 14 and again, try to run the audio normal again.
You will not have any error automatically execute successfully.
So that is how we have actually added a bug and even tested if that airport was executing in our given
Python program.
So with this, we have concluded our testing of the transposition cipher with multiple key values.
So that's it from this particular session.
Hope you have understood with the help of the example that we have done.
Thank you very much.