Now, we'll move to the last session in our first week in that level of python hacking that is encrypting
and decrypting using files now in the previous session, we have all created programs that have only
worked on small messages that we tied directly into the code files as some string values.
Now, the Saiful programs will make in this session will allow you to encrypt and decrypt the entire
file, which can have millions of characters insights.
Also, along with this, the following topics would be covered in the session that is using the open
function, reading and writing files, using the right close and read file object methods, using the
stockpot dot exit function, using law and title string methods.
Using this starts with and with string methods.
Also the time module and the time or time function.
Now, understanding what our plain text files, the transposition file cipher program, encrypt and
decrypt the plain text files.
Now these are the kind of files that only have some text data and usually have ordered the text as the
file extension.
You can write your own text files with programs such as Notepad on Windows or text edit on Mac OS or
G.
Edit on Linux.
Now you can even use the Idalis file ed by saving the file within the next extension instead of the
usual DOT by extension.
Now we'll use some simple text files in this particular session which will have certain characters or
data already there, which we are only using for encrypting it and again to decrypt it.
So in this particular session where we'll be covering the module, but also if you just look at our
python hacking beginner folder.
So in this python hacking big enough, although we are having this the to fight, which is having some
text data into it, which we are going to use in our session for encrypting and again for decrypting
it also.
So we will first of all, create the program for transposition file cipher for encrypting it and decrypting
it.
So let us go back here and we'll go for a new file.
And here we will have to again import our Lemington and then we'll talk in here also.
But and before that, we will say import time.
Safeway's slash sis slash our demo then and demo 30.
And after this, we define the main method wherein we give the input file name SDR as equal to our dummy
dog, the X, and we have placed this in the same folder where we are to save the current fight.
Otherwise be careful to give the whole back if it is not existing again.
If the file is not existing, you will get an error.
So be sure that the files existing in your particular folder.
Now this is the input filename that we have given.
Similarly, we also require some output filename SDR and here we would be giving, say, dummy dot.
Encrypted dot the just to make it a difference that the earlier one is a normal file and this is our
encrypted file, hence we have given the file name, got encrypted, got the then we give the same A
that's equal to.
Let's give our kids it then and say my Modesta SDR is equal to we are first of all doing it and so forth.
Time when we are doing it and we are setting to enter if we want to decrypt said this value to decrypt.
So we will do that later on when we would really gripping it the coming to the next one.
Now if the file input does not exist, the program would dominate.
So for that we are checking, if not the OS dot, the part does not exist.
And in this you give the FI input file name as DIA parameter.
So if it is not existing, we are giving an appropriate message to the user seeing the file zipless
and which is C does not exist and quiting.
The program
and the audio give in person format the value of the input filename SDR, after which we say here this
does not exist, which will exit the particular program totally.
And if the output file already exists, give the user a chance to quit.
So, again, the output file should also be not existing because we are creating the file there.
So for that, we will check in another if seeing if this dot, dot, dot exist and here we give the
output file name is still variable.
Then we give your print message as see this will.
Over right.
OK, the fine print here wasn't s and in this we give C.
Continue or in fact, kill for fuckwit, give this to the user as a message and put in their output
filename STF, then whatever the response, the user gives your distorted in the response, your variable
by taking the input and.
And then after which we say, if not, the response is still dot law, dot starts with B, C, C, then
you say start, exit again.
Otherwise, if everything is proper, then we'll go here and create another file or SDR and we will
open the file that we are passed to input filename still.
So if the file is there, everything is proper, then you pass that to the file object.
And again, the value for content SDR would be your file object.
SDR not using the Rudimental and the file or SDR dot.
Don't forget to close it after it has read it successfully.
So once that is done, we go on for print and in this we say print and percentage see assaying.
But in the valley of say my more now here that is my mode.
Still not see item.