Professional Documents
Culture Documents
Adv C186
Adv C186
● 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
1
Note: This document is the original copyright of WhiteHat Education Technology Private
Limited.
2
encrypted
3
Q - Which function is used to
decrypt the text and what
parameters does it take?
A - decrypt() function is used to
encrypt the text. This function takes 2
parameters:
Key - Using which the text is
decrypted. This should be the same
as the key used for encrypting this
message
Value - The text which is to be
encrypted
4
bytes
5
We are creating a chat application where we will encrypt the user message and store it
in the database. And when we get the message from firebase database we will decrypt
the message and display it to the user
The encryption and decryption is used to maintain the privacy or secrecy of a message.
6
This is the start screen or login screen of the application
Which contains the username , your code and your friend’s code
- Username will be your name
- Your code will be your code
- And your friend’s code, will be your friend’s code whole you want to chat with
So before the chat begins you should exchange your code with your friend.
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 your friend we will require the key of your
friend who will be sending the messages.
© 2020 - WhiteHat Education Technology Private Limited.
7
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
We will enter the key that I will be using to send data in “Your code” entry element and
the key that your friend will be using to send the data in “Your Friends code” entry
element.
This way we can get both our and the your friend’s data from firebase database and
display on our root window
Start
Enter the details and press ” button
“
When clicked S
ontart
“ ” button the login screen will be closed and the message window
will be opened
8
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
9
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
10
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
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.
11
SAME FILE WHEN STUDENT ACTIVITY STARTS.
Predefined code:
12
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
The predefined code contains the complete GUI for this application
1. Code to create a basic GUI template for login window in tkinter
2. Function which will be called on click of the “Start” button which is placed on the
login window. On click of this button it will create another window that is the
message window on which the message from firebase database is displayed and
we can send encrypted messages to firebase database.
13
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
3.
Then code to create and place a label on the login window. The label to prompt
the user that the entry element beside it is where they are supposed to enter
their name.
4.
Then code to create and place an entry on the login window. The entry element
will get the user name.
5.
Then code to create and place a label on the login window. The label to prompt
the user that the entry element beside it is where they are supposed to their chat
code.
14
6. Then code to create and place an entry on the login window. The entry element
will get their chat code.
7. Then code to create and place a label on the login window. The label to prompt
the user that the entry element beside it is where they are supposed to enter
your friends code.
8. Then code to create and place an entry on the login window. The entry element
will get your friends chat code.
9. Then code to create and place buttons on the login window. This button will call
the enterRoom() function defined in step 2 which creates another tkinter window
that is message window with various other GUI elements
10.Then end statement which will execute the code and run our application
Student has to add the following marked code in the predefined code:
© 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.
16
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.
When you start your activity at that time I will show how to install firebase
library
18
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
2. Initialize the firebase. That is we will create a connection between the firebase
and python and store it in a variable. Using this variable we can store and get the
data from the firebase database.
19
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
When you start your activity at that time I will guide you about how create
firebase database and get the firebase database link
20
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
3. Then we will declare all the variables required. We are defining these variables
outside the function as these variables will be used in other functions as well and
to access the variables in any of the functions, they have to be declared outside
the function.
● username - This variable will be used to hold the name of the user who is
sending the encrypted messages, we will define this variable outside the
function with an empty string .
● your_code - This variable will be used to hold the code of the user who is
sending the encrypted messages, we will define this variable outside the
function with an empty string.
● your_friends_code - This variable will be used to hold your friend’s code
who is sending the encrypted messages, we will define this variable
outside the function with an empty string.
● message_text - This variable holds the textarea of the message window.
As the message window is created on click of start button. That is,
textarea is created inside enterRoom()
the function which is called on the
click ofstart button.
21
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
But we also want to use this variable in other functions as well (that is
when we get the data we will be using this variable to display the
messages from the firebase database) therefore we will define this
variable outside the function with an empty string.
● message_entry - This variable holds the entry (input field) of the
message window. As the message window is created on click of start
button. That is, the entry element is created inside the enterRoom()
function which is called on the click of start button.
But we also want to use this variable in other functions as well (that is
when we send the data we will be using this variable to get the data
entered by the user) therefore we will define this variable outside the
function with an empty string.
22
● Define all the variables using a global keyword so that we can use the
variables defined outside the function.
● Define username with global keyword which is defined outside the
function
● Defineyour_code
with global keyword which is defined outside the
function
23
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
● Defineyour_friends_code
with global keyword which is defined outside
the function
● Definemessage_entry
with global keyword which is defined outside the
function
● Definemessage_text
with global keyword which is defined outside the
function
24
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
25
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
sendData() function
26
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
5. Now we will define the sendData function. The functionality of this button is to
encrypt the message and store it in the firebase database.
● Define sendData() function.
● Define username with global keyword which is defined outside the
function
● Get the message entered by the user in the message entry element using
the get() function. Entry element where the user enters the message is
stored in the message_entry variable.
Q - Can you tell me the code to get the data from the entry element which
is stored in the message_entry variable?
A - message_entry.get() function is used to get the data entered in the
27
message_entry element
We will be concatenating the username with the message in the following
format before encrypting it
Username : message
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
Therefore we will concatenate the username which is stored in variable
username with “ : ” string and then concatenate the message from the
entry element and store it in a variable
We will be encrypting the username and message so that the viewer won’t
even know who is the sender of this message as well
Q - Which function from the simplecrypt library is used to encrypt the
message?
A - To encrypt the message we will use encrypt() function from
simplecrypt library
Q -How many parameters does encrypt() function take and what are those
parameters?
A - encrypt() function takes 2 parameters:
28
As now even though the attacker/hacker knows the
algorithm(technique or procedure in which data is encrypted) used
for encryption they won’t be knowing the key used to encrypt the
data. Thus it will be difficult for the attacker to decrypt the data. In
this case we are using “AIM” as key you can use any string/word
but remember use the same string/word as key while decrypting the
data
- Message - The text which you would like to encrypt. The text that
we want to encrypt is stored in a message variable.
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
29
● Theencrypt() function encrypts the data in bytes. We want the encrypted
data in hexadecimal value. We are converting the encrypted bytes string
to hexadecimal because as we will be also be getting the message on
thunkable , and bytes data is not readable from thunkable thunkable can
read hexadecimal value.Therefore we are converting encrypted bytes
string to hexadecimal. Therefore to convert bytes to hexadecimal we will
hex() function and store hitex_string
be using the in variable. We stored
the encrypted bytes message in variable cipher code.
30
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.
Student-Activity-1- CODE
DIAGRAM
Please don't share, download or copy this file without permission.
32
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
33
Now, it's your turn. Show me how you Student-Activity-2-
will create this application. PREDEFINED CODE
Step 4: You did great today as well. (Give at least 2 hats off)
Wrap-Up Great! You have two hats off. Press the Hats Off Icon for
(3 mins) Creatively Solving
Activities
Q - Which library is used to send the
data into the firebase
database? And what is the code to
import the library in our code?
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
34
A - from firebase import firebase Press the Hats Off Icon for
Great Question
35
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private Limited.
the next module. And
some challenging
concepts are coming
ahead.
For the solution of all the Additional Activity open Teacher-Activity-3 and
navigate to class number C186
Additional Activity 1 -
Run Student-Activity-3 from the panel
The TASK and HINTS are mentioned on the website itself.
Additional Activity 2 -
Run Student-Activity-4 from the panel
The TASK and HINTS are mentioned on the website itself.
Additional Activity 3 -
Run Student-Activity-5 from the panel
The TASK and HINTS are mentioned on the website itself.
36
Additional Activity 4 -
Run Student-Activity-6 from the panel
The TASK and HINTS are mentioned on the website itself.
37
Additional Activity 5 -
Run Student-Activity-7 from the panel
The TASK and HINTS are mentioned on the website itself.
Teacher Clicks
38
Note: This document is the original copyright of WhiteHat Education Technology Private
Limited.
-001.zip
39
© 2020 - WhiteHat Education Technology Private Limited.
Note: This document is the original copyright of WhiteHat Education Technology Private
Limited.
40