Professional Documents
Culture Documents
Adv C187
Adv C187
● Student Resources
0 Use gmail login credentials
○ Earphone with mic (optional)
○ Notepad and Pen
Class structure Warm Up 5 Mins
Teacher-Led Activity 15 Mins
Student-Led Activity 35 Mins
Wrap Up 5 Mins
Start the video call from H2H
1
Step 1: In the previous class we learnt how to Open Teacher-Activity-3-
Warm up encrypt the data and store the and download the
(5 mins)
data in the firebase database. class_187_Complete_enc
rytion_decryption.py file
and run on the spyder
before class to check
everything is working fine
2
Q - What is the code to close a tkinter
window which is stored in the
root variable?
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private
Limited.
A - root.destory()
As root is the variable holding the
window and destroy() function closes
the window
3
Step 2: In today’s class we will learn how to
Teacher-Led get encrypted data from the firebase,
Activity decrypt it and display it on the
(15 mins) message window.
Till now we have created a chat application where we have encrypted the user
message and store it in the database.
In today class we will get the message from firebase database , decrypt the message
and display it to the user
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private
Limited.
4
The encryption and decryption is used to maintain the privacy or secrecy of a message.
TEACHER-ACTIVITY-1
NOTE - ALL THE BELOW IMAGES ARE PRESENT IN .
TEACHER-ACTIVITY-1
PLEASE OPEN WHILE EXPLAINING
5
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
- Before the chat begins the person who will be having an encrypted conversation
should exchange each other's codes.
The data in firebase is stored in key - value format.
Therefore these codes will be the key and the message you send will be the value.
Therefore to access the message sent by the your friend we will require the key of your
friend who will be sending the messages
We will enter the key that I will be using to send data in “Your code” entry element and
the key your friend will be using to send the data in “Your Friends code” entry element.
This way we can get both our and our friends data from firebase database and display
on our root window
6
Start”“ button
Enter the details and press
When clicked onStart
“ ” button the login screen will be closed and the message window
will be opened
7
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
8
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
hello. Therefore my
Here I had sent name: hello is displayed on the textarea and my
friend (courteney) has senthi” which
“ is also displayed in the textarea.
We are able to get our friends message because we had our friends321 , that is
code
using which we got the message from the firebase database
9
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
Data stored in firebase database
As you can see the data stored in the firebase database is not readable, that is the data
is stored in encrypted format. This keeps your data secured , even if the hacker tries to
access the database to get your messages he/she won’t be able to access the data as it
has been encrypted.
We all have used whatsApp , whatsapp does a similar thing, it encrypts the message
and stores it in their database to maintain the confidentiality of the messages sent.
10
NOTE - ASK THE STUDENT TO CONTINUE CODING IN THE PREVIOUS CLASS
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
FILE ITSELF
11
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
12
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
13
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
14
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
15
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
16
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
17
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
1. DefinegetData()
function. The functionality of this function is to get the
messages from firebase database , decrypt the message and show on root
window
18
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
19
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
our_code
● Definey with global keyword which is defined outside the
function
● Defineyour_friends_code
with global keyword which is defined outside
the function
● Get the data from the firebase database. To get the data from the firebase
database we will usegthe et() function.get() function is from the firebase
library that we have installed and imported in the previous class.
Syntax:
firebase.get(path , key
)
We use the module name( firebase ) with dot operator g et() function
and
- Path - path or url from which we want to get the data from the
database. We will be getting the data directly from the root
directory(folder). Which is denoted by “/”. Therefore we will pass “/”
as a parameter.
20
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
- Key - Using this key we can access the message stored inside the
firebase. As firebase stores data in key:value format.
- We had stored messages in the same format, like -
- your_code : message
- your_friends_code : message
- Where your_code will be our key, and your_friends_code
will be the key or your friend who is sending a message.
- Hence we will be using your_code key to get our message, and
your_friends_code key to get our friend's message.
- 1st we will get our data
Now why are we getting our data?
You have used whatsapp right, when we send a message your
message is also displayed on the screen right. Similarly to be able
to view the entire conversation we need to display our message
and our friends' messages as well.
So first we will get the message we have just sent. To get the
message we have sent we will need our code, the code we used to
send the data is stored your_code
in variable
Therefore here the key will your
be code that you have entered on
the login window which is stored your_code
in variable.
21
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
This will give the encrypted hexadecimal string from firebase database
and we will storegin variable
et_your_data
et_your_data
● Printg variable which holds encrypted hexadecimal string
from the firebase database on console.
Q -We have stored the encrypted data in which form in the firebase
database?
A - We have stored the data in firebase database in encrypted format
22
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
The decrypt() function takes the input in bytes so that it can
convert the encrypted message and gives the original message in
bytes. But as we know the message coming from firebase is in
hexadecimal format.
● Hence we need to first convert this hexadecimal into bytes format.
Q - Do you remember which function is used to convert hexadecimal
string to a bytes string?
A - bytes.fromhex() function is used to convert hexadecimal string to
bytes string.
23
A - decrypt() function takes 2 parameters:
- Key - This key should be the same key that is used to encrypt the
data. We used string “AIM” as our key to encrypt the data ,
therefore we will use the same string as a key to decrypt the data.
Always use the same key to encrypt and decrypt the data. If you
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
24
ever used one key for encryption and another key for decryption
you won’t be able to get the same data. This makes the encryption
more strong.
- Message - The text which you would like to decrypt. The text that
we want to decrypt is storedbyte_str
in a variable.
● Now to convert the string from bytes to get the data in plain text that is
b and ‘ single quote from the original
remove the characters , wedata
25
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
26
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
- start_index - We would like to add the text at the end of any string
that is at the end of the existing data in textarea so give END where
END means the last character or index in the text area
- text- The text that is to be added or displayed in the text area. We
want to display the decrypted text which is stored in variable
final_message.
Variable final_message holds the decrypted message. And then
we will concatenate “\n” string. “\n” means a new line. And we are
adding a new line so that the next message that is sent by our
friend should be added on the next line and not the same line.
● Now we have to get the message sent by another person, that is our
friend and display it in the text area.
Q -Which function is used to get the data from the firebase database?
A -To get the data from the firebase database we will get()use the
function from the firebase library that we have installed and imported.
Syntax:
path , key
firebase.get( )
We use the module name( firebase
) with dot operator and
get() function
27
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
- Path - path or url from which we want to get the data from the
database. We will be getting the data directly from the root
directory(folder). Which is denoted by “/”. Therefore we will pass “/”
as a parameter.
- Key - Using this key we can access the message stored inside the
firebase. As we had stored our key in your_code and your friends
key in your_friends_code we will be using those codes to get our
message and your friend’s messages from the firebase database
We have already written code to get our data now we want to get
the message sent by your friend. To get the message sent by your
friend we have to use the your friends code which is stored in
your_friends_code variable
Therefore here the key will your_friends_code
be that you have
entered on the login window which is ystored
our_friends_code
in
variable.
This will give the encrypted hexadecimal string from the firebase database
of the message sent by our friend which isgstored
et_friends_data
in
variable.
28
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
● Now when getting the data sent by our friend we are not sure if our friend
has actually sent any new message or not. And if our friend hasn’t sent
any message at all then get_friends_data variable will be empty. As we
get the data sent by our friend, but as there is no message the
get_friends_data variable will sayNone
“ ” that is there was no message.
And in the assumption that this variable holds encrypted hexadecimal
value and if we try to decrypt it will give an error. So to avoid this error, we
will first checkget_friends_data
if variable is not “None” using the if
statement. Andget_friends_data
if variable is not “None” means it
contains the encrypted hexadecimal message sent by our friend so we
can go ahead and decrypt.
29
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
30
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
31
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
○ Now that we have our encrypted string in bytes we will decrypt the
string to get the original string dusing
ecrypt()function.decrypt()
function takes two parameters
Q -What are the 2 parametersdthat function takes?
ecrypt()
A-
- Key- This key should be the same key that is used to
encrypt the data. We used string “AIM” as our key to encrypt
the data , therefore we will use the same string as a key to
decrypt the data. Remember to always use the same key to
encrypt and decrypt the data. If you ever used one key for
encryption and another key for decryption you won’t be able
to get the same data. This makes the encryption more
strong.
32
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
original .
And store it in variable
Thedecrypt()function gives the decrypted data but in
bytes. Therefore variable original will have decrypted data in
bytes like this - b’ decrypted data’
○ So to convert the string from bytes to get the data in plain text that
b and ‘ single quote
is remove the characters from the original
data, we will decode uit tf-8(unicode
to transformation format)
using thedecode()
function. Like this
33
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
34
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
35
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
36
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
37
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
38
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
2. This getData() function should be called everytime we send new data. Therefore
we will call getData() function inside the sendData() function
39
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
40
After you have completed coding,
start screen recording and record
the output using loom and submit After the student has
the video link on the student panel. completed coding, guide
the student to start
screen recording and
record the output using
loom as per
Teacher-Activity-Referen
ce-1, and submit the
video link on the student
panel.
41
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
get_friends_data variable is
A - get_friends_data != None
42
Reference activity for
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
increasing their
knowledge. This should
also be done
For the solution of all the Additional Activity open Teacher-Activity-3 and
navigate to class number C187
Additional Activity 1 -
Run Student-Activity-2 from the panel
The TASK and HINTS are mentioned on the website itself.
Additional Activity 2 -
Run Student-Activity-3 from the panel
The TASK and HINTS are mentioned on the website itself.
Additional Activity 3 -
Run Student-Activity-4 from the panel
The TASK and HINTS are mentioned on the website itself.
Additional Activity 4 -
Run Student-Activity-5 from the panel
The TASK and HINTS are mentioned on the website itself.
Additional Activity 5 -
Run Student-Activity-6 from the panel
The TASK and HINTS are mentioned on the website itself.
43
Teacher Clicks
44
CODE https://curriculum.whitehatjr.com/ADV+Ass
Teacher Activity 1 DIAGRAM et/CODE+DAIGRAM_C187.pdf
45