Uploaded by Jerimiah Miranda

CoE 167 Lab 3 Specifications

advertisement
CoE 167 1st Sem 2021-2022 THU2 Laboratory 3
Cryptography in Python
Objectives:
- Get accustomed to cryptography techniques such as hashing and encryption in python
Cryptography is the study of secure communications techniques that allow only the sender and
intended recipient of a message to view its contents. In this exercise, we are to use two
techniques of cryptography called Hashing and Encryption. Hashing is an algorithm that calculates
a fixed-size bit string value from a file whereas Encryption is a means of securing digital data using
one or more mathematical algorithms, along with a password or “key” used to decrypt the
information.
Requirements:
Python compiler or Integrated Development Environment (IDE) and terminal.
General Specifications:
Create a python program that can hash and encrypt/decrypt.
Guide Questions (10% each):
Submit a PDF document supported by SCREENSHOTS on each of the following questions.
1) Is cryptography important? Why or why not?
2) Explain step-by-step how hashing is done using the algorithm used in this exercise. (from
what happens to the input to become the expected output)
3) Explain step-by-step how encryption is done using the algorithm used in this exercise. (from
what happens to the input to become the expected output)
4) Explain step-by-step how decryption is done using the algorithm used in this exercise. (from
what happens to the input to become the expected output)
5) Where can we use hashing and encryption? Give at least 2 examples EACH.
6) Explain at least 2 different cryptography techniques other than hashing and
encryption/decryption and give an example where they are used.
7) What are the advantages of hashing over encryption? Give at least 2.
8) What are the advantages of encryption over hashing? Give at least 2.
9) What are other algorithms of hashing other than what we have used in this exercise? Give
at least 2 examples and explain each.
10) What are other algorithms of encryption other than what we have used in this exercise?
Give at least 2 examples and explain each.
1
1. Download necessary files:
a. Download the hashing.py and encryption.py in UVLE.
b. Put them on the same folder so you can access them easily.
2. Run the Programs
a. For hashing, open your terminal and run hashing.py.
Based on the example code, we used sha-256 as the hash function under the hashlib
library. There are other hashing algorithms available under the same library. (discussed in
guide questions 2 and 9)
The terminal should output the message to be hashed and the hash value with the
hexadecimal equivalent, digest size, and block size.
b. For encryption, open your terminal and run the following command:
sudo pacman -Sy python-rsa
2
This will install the RSA (Rivest-Shamir-Adleman) encryption python library. There are other
encryption algorithms which are stored in the cryptography python library. (discussed in
guide questions 3, 4, and 10)
(OPTIONAL) Other Arch linux machines may have to update their operating system to
download/use necessary packages. You may run the following command to update your
operating system. Just take note of the memory it would take to install all the packages. If
the “rsa” package is already working without updating the operating system, we highly
suggest NOT to update your operating system as this could cause compatibility problems
afterwards.:
sudo pacman -Syu
Other Operating Systems (non-Arch linux) may have other names for the “python-rsa” library
such as “rsa” or installed through “pip install rsa”. Double check your dependencies and
libraries for your own Operating System and make sure you have installed the correct library.
c. Run encryption.py.
Based on the example code, we have used RSA (Rivest-Shamir-Adleman) encryption.
The terminal should output the message to be encrypted and the decrypted message
together with their public and private keys.
Download