Python Basic Workbook OWTP
Python Basic Workbook OWTP
Python (Basic)
www.azureskynet.com | +91-1244275997
Encryption and Decryption:
In this chapter, we’re going to take a closer look at how encryption and decryption takes place and why
they are important during the communication between two nodes.
So, this script will take only one message as an input and accordingly it will result you the encrypted and
decrypted message as shown below.
Input to be entered by
the user
Encrypted Message
Decrypted Message
Before you start with this make sure that you have already downloaded and installed python 3.x on
your system.
Encryption:-
Key=9
Asking for plaintext from the user
Now you have to create a variable to take input from user and use it as a message that
needs to be securely transmitted from one node to the other followed by the encryption.
for i in message:
if i in alphabet:
position=alphabet.find(i) #checking the
indexing of each alphabet
in the message in the dictionary
newposition=(position + key)%26
#changing the indexing according to the
dictionary and 26 is it’s length
newmessage+=alphabet[newposition]
#storing the message step by step after
encryption
else:
newmessage+=i #use this when
alphabet in the message didn’t matched with
any alphabet in dictionary
print(“Encrypted message:”,newmessage)
So you have successfully encrypted the input message and now it’s time to decrypt the
message to the original message as entered by the user
Decryption:-
For the conversion of your cipher text into the plain text as normal we need the same values
of the dictionary and the key number as we have previously taken for the process of
encryption.
Decrypt=””
Now it’s time to again start checking each alphabet in the message but this time your
message that needs to be checked will be the message that was encrypted in the previous
process of encryption and further we have to check for the indexing in the dictionary
containing all the alphabets so that we can decrypt the message back to the original text.
for i in newmessage:
if i in alphabet:
pos=alphabet.find(i)
newpos=(pos-key)%26
decrypt+=alphabet[newpos]
else:
decrypt+=i
Now display the decrypted message so as to verify that we are getting the original message
or not.
print(“Decrypted message:”,decrypt)
Login panel to store the username and password in csv format:
In this chapter, we’re going to take a closer look at how a login panel works and how you are able to
access your profile after a successful login and how it will ask you to re-enter your login credentials in
case of incorrect username or password.
So, this script will take two inputs from the user one will be the user name and the other will be the
password and accordingly you will be able to access your profile in case of successful login or it will ask
you to re-enter the login credentials in case of wrong username/password.
Output
In the above function we are creating two variables and both as a global
variable and further we are taking inputs from user and storing those
inputs in these variables, followed by the calling of the second function
,i.e., check() which will verify the credentials.