In this assignment you will be writing several functions that process files and dictionaries to encrypt and decrypt messages. A dictionary will be used to create a random substitution cypher. Each letter of the alphabet will be mapped to another random letter in the alphabet. No letter will map or be mapped to any duplicate letter. For example given the partial dictionary below you can encrypt a message. Be sure to use the starter file provided so you can see the appropriate outputs. Be sure to download and place the appropriate text files in the same directory as your python file. You only need to submit your python file. Partial Dictionary: {d : a, e: f, h : b, l : p, l : e, o : j, r: m, w: i} originalMessage = “hello world” → encryptedMessage = “bfeej ijmea” Part 1 - Encrypt a Message: You will write 2 functions to build a dictionary and encrypt a message Function buildCypher() → dict: This function is to build a dictionary that can be used to create a random substitution cypher. Your goal is to assign a random mapping of each lower case letter of the alphabet to another letter. Return the dictionary created. *Hint all characters are mapped to an integer value from 97 - 122. See the ASCII chart linked here You can convert an integer to a character using the chr() function. But there are many ways to do this so find something that works for you. This random cipher should be different each time it is executed. Function encryptMessage(text: str, cypher: dict) → str: This function should convert all characters of parameter text to lowercase letters and then encrypt each character according to the cypher parameter. Each character in the text should be converted to the value based upon the key in the cypher parameter. If the character does not exist in the keys of the cypher it should not be encrypted. These characters will be spaces, quotes, new lines, etc. See the example of the partial dictionary above. The function should return a string of the text in encrypted form. Part2 - Decrypt a Message: You will write 2 functions to load a dictionary from a pickled file and decrypt a message using that dictionary. Function decryptMessage(text: str, cypher: dict) → str: This function will do the reverse of the encryption function above. It will go through each character of the text parameter which is an encrypted message. Each character is a value in the cypher dictionary and needs to be replaced by the associated key from the dictionary. It will only decrypt lower case letters and leave all other characters in their original form (spaces, quotes, etc) It will return a string representing the decrypted message. ** You’ll know when you have it correct. Function loadCypher(filename: str) → dict: This function will open a binary file with the passed filename parameter. It will load it’s contents and return the dictionary from the file cipher.py import pickle import random def openEncryptedMessage(filename="EncryptedMessage.txt"):     """Loads the encrypted text file and returns its contents"""     infile = open(filename)     contents = infile.read()     infile.close()     return contents def buildCipher() -> dict:     pass  # Remove pass instruction and write your function definition here def encryptMessage(text: str, cipher: dict):     pass  # Remove pass instruction and write your function definition here def loadCipher(fileName: str):     pass  # Remove pass instruction and write your function definition here def decrypt(text: str, cipher: dict):     pass  # Remove pass instruction and write your function definition here def main():     """ Test Area         Remove or add comments for functions to test     """     print("TESTING PART 1")     #### Remove comments to test buildCypher function ####     # cipher = buildCipher()     # print(cipher)  # displays your cypher and should be different each time it is run     #### Remove comments to test encryptMessage Function ####     # message = "The Quick Brown Fox, Jumps Over the lazy Dog"     # encryptedMessage = encryptMessage(message, cipher)     # print(encryptedMessage)     # Part 2     print("\nTesting Part 2")     #### Remove Comments to test decrypt function ####     # decryptedMessage = decrypt(encryptedMessage, cipher)     # print(decryptedMessage)     #### Remove comments to test loadCypher Function ####     # new_cipher = loadCipher("cipher.dat")     # print(decrypt(openEncryptedMessage(), new_cipher)) if __name__ == '__main__':     main() cipher.dat   i need it to decrypt an file called  encriptedMessage.txt

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

In this assignment you will be writing several functions that process files and dictionaries to encrypt
and decrypt messages. A dictionary will be used to create a random substitution cypher. Each letter
of the alphabet will be mapped to another random letter in the alphabet. No letter will map or be
mapped to any duplicate letter. For example given the partial dictionary below you can encrypt a
message.
Be sure to use the starter file provided so you can see the appropriate outputs. Be sure to download
and place the appropriate text files in the same directory as your python file. You only need to submit
your python file.
Partial Dictionary: {d : a, e: f, h : b, l : p, l : e, o : j, r: m, w: i}
originalMessage = “hello world” → encryptedMessage = “bfeej ijmea”

Part 1 - Encrypt a Message: You will write 2 functions to build a dictionary and encrypt a message
Function buildCypher() → dict:
This function is to build a dictionary that can be used to create a random substitution cypher. Your
goal is to assign a random mapping of each lower case letter of the alphabet to another letter.
Return the dictionary created. *Hint all characters are mapped to an integer value from 97 - 122.
See the ASCII chart linked here You can convert an integer to a character using the chr()
function. But there are many ways to do this so find something that works for you. This random
cipher should be different each time it is executed.
Function encryptMessage(text: str, cypher: dict) → str:
This function should convert all characters of parameter text to lowercase letters and then encrypt
each character according to the cypher parameter. Each character in the text should be
converted to the value based upon the key in the cypher parameter. If the character does not exist
in the keys of the cypher it should not be encrypted. These characters will be spaces, quotes,
new lines, etc. See the example of the partial dictionary above. The function should return a
string of the text in encrypted form.

Part2 - Decrypt a Message: You will write 2 functions to load a dictionary from a pickled file and
decrypt a message using that dictionary.

Function decryptMessage(text: str, cypher: dict) → str:
This function will do the reverse of the encryption function above. It will go through each character
of the text parameter which is an encrypted message. Each character is a value in the cypher
dictionary and needs to be replaced by the associated key from the dictionary. It will only decrypt
lower case letters and leave all other characters in their original form (spaces, quotes, etc) It will
return a string representing the decrypted message. ** You’ll know when you have it correct.
Function loadCypher(filename: str) → dict:
This function will open a binary file with the passed filename parameter. It will load it’s contents
and return the dictionary from the file

cipher.py

import pickle
import random


def openEncryptedMessage(filename="EncryptedMessage.txt"):
    """Loads the encrypted text file and returns its contents"""
    infile = open(filename)
    contents = infile.read()
    infile.close()
    return contents


def buildCipher() -> dict:
    pass  # Remove pass instruction and write your function definition here


def encryptMessage(text: str, cipher: dict):
    pass  # Remove pass instruction and write your function definition here


def loadCipher(fileName: str):
    pass  # Remove pass instruction and write your function definition here


def decrypt(text: str, cipher: dict):
    pass  # Remove pass instruction and write your function definition here


def main():
    """ Test Area
        Remove or add comments for functions to test
    """
    print("TESTING PART 1")
    #### Remove comments to test buildCypher function ####
    # cipher = buildCipher()
    # print(cipher)  # displays your cypher and should be different each time it is run

    #### Remove comments to test encryptMessage Function ####
    # message = "The Quick Brown Fox, Jumps Over the lazy Dog"
    # encryptedMessage = encryptMessage(message, cipher)
    # print(encryptedMessage)

    # Part 2
    print("\nTesting Part 2")
    #### Remove Comments to test decrypt function ####
    # decryptedMessage = decrypt(encryptedMessage, cipher)
    # print(decryptedMessage)

    #### Remove comments to test loadCypher Function ####
    # new_cipher = loadCipher("cipher.dat")
    # print(decrypt(openEncryptedMessage(), new_cipher))


if __name__ == '__main__':
    main()

cipher.dat

 

i need it to decrypt an file called  encriptedMessage.txt
 
0 File
Edit View Git
Git Project Debug Test Analyze Jools
7-700 S.p.
cipher.dat
X
00000000 80 03 7D 71 00 28 58 01 00 00 00 61 71 01 58 01 )q. (X....aq.x.
..}q.
ee ee ee 62 71 03 58 01.yq.X....bq.X.
58 01 00 00 e0 67 71 05
67 72 85 ...cq.h.X....gq.
58 01 00 00 00 75 71 07
75 71 97 X....dq.X....ug.
58 01 00 00 e0 69 71 09 X....eq.x....iq.
58 01 00 00 00 6D 71 e8 x....fq.x....mq.
71 ec 58 01 ee ee ee 68 h.X....jq.X....h
71 BE 68 09 68 BA 68 BC q.x....lq.h.h.h.
58 01 00 00 00 68 71 10 X....vq.x....kq.
68 BE
68 E 68 01 68 08 58 01 x....rq.h.h.h.X.
00 00 00 6E 71 13 68 08 ...xq.x....nq.h.
58 0¹ еe еe ее 74 71 15 X....oq.x....tq.
58 01 0e ee ee 71 71 17 x....pq.x....qq.
58 01 ☺ ☺ ☺ 73 71 18 h.h.h.h.X....sq.
68 15 68 16 68 067 68 03 X....zq.h.h.h.h.
80 77 71 1A 68 13 68 12 h.h.X....wq.h.h.
68 1A 75 2E
h.h.h.h.h.u.l
00000010 ee ee ee 79 71 02 58 01
00000020 00 00 00 63 71 04 68 04
00000030 58 01 0e ee ee 64 71 06
00000040 58 01 00 00 00 65 71 08
00000050 58 01 00 00 00 66 71 A
000060 68 05 58
68 es 58 0¹ еe eе еe 6A
00070 71 80 58 01 00 00 00 6C
00000000
***Ø®Ø 58 01 ¸Ð ¸ Ð 76 71 OF
000000⁹0 58 01 ee ee ee 72 71 11
******* ** ** *e 78 71 12 58 01
Þeeëəbə 58 01 ee ee ee 6F 71 14
eeeeece 58 01 ee ee ee 70 71 16
eeeeeede 68 17 68 60 68 11 68 14
000000e0 58 01 00 00 00
58 01 eeee ee 7A 71 19
eeeeeefe 68 OF 68 10 58 01 00 00
00000100 68 06 68 02 68 18 68 19
Ready
=
Type here to search
(b)
Extensions Window Help Search (Ctrl+Q)
-▶ Attach.... D
5)
D
O
B
K
P Solution1
OVR
33°F Clear
MA
0
Live Share
Select Repository
^ GGỠ 4
4x)
8:34 PM
3/29/2023
X
☆
Ę
Transcribed Image Text:0 File Edit View Git Git Project Debug Test Analyze Jools 7-700 S.p. cipher.dat X 00000000 80 03 7D 71 00 28 58 01 00 00 00 61 71 01 58 01 )q. (X....aq.x. ..}q. ee ee ee 62 71 03 58 01.yq.X....bq.X. 58 01 00 00 e0 67 71 05 67 72 85 ...cq.h.X....gq. 58 01 00 00 00 75 71 07 75 71 97 X....dq.X....ug. 58 01 00 00 e0 69 71 09 X....eq.x....iq. 58 01 00 00 00 6D 71 e8 x....fq.x....mq. 71 ec 58 01 ee ee ee 68 h.X....jq.X....h 71 BE 68 09 68 BA 68 BC q.x....lq.h.h.h. 58 01 00 00 00 68 71 10 X....vq.x....kq. 68 BE 68 E 68 01 68 08 58 01 x....rq.h.h.h.X. 00 00 00 6E 71 13 68 08 ...xq.x....nq.h. 58 0¹ еe еe ее 74 71 15 X....oq.x....tq. 58 01 0e ee ee 71 71 17 x....pq.x....qq. 58 01 ☺ ☺ ☺ 73 71 18 h.h.h.h.X....sq. 68 15 68 16 68 067 68 03 X....zq.h.h.h.h. 80 77 71 1A 68 13 68 12 h.h.X....wq.h.h. 68 1A 75 2E h.h.h.h.h.u.l 00000010 ee ee ee 79 71 02 58 01 00000020 00 00 00 63 71 04 68 04 00000030 58 01 0e ee ee 64 71 06 00000040 58 01 00 00 00 65 71 08 00000050 58 01 00 00 00 66 71 A 000060 68 05 58 68 es 58 0¹ еe eе еe 6A 00070 71 80 58 01 00 00 00 6C 00000000 ***Ø®Ø 58 01 ¸Ð ¸ Ð 76 71 OF 000000⁹0 58 01 ee ee ee 72 71 11 ******* ** ** *e 78 71 12 58 01 Þeeëəbə 58 01 ee ee ee 6F 71 14 eeeeece 58 01 ee ee ee 70 71 16 eeeeeede 68 17 68 60 68 11 68 14 000000e0 58 01 00 00 00 58 01 eeee ee 7A 71 19 eeeeeefe 68 OF 68 10 58 01 00 00 00000100 68 06 68 02 68 18 68 19 Ready = Type here to search (b) Extensions Window Help Search (Ctrl+Q) -▶ Attach.... D 5) D O B K P Solution1 OVR 33°F Clear MA 0 Live Share Select Repository ^ GGỠ 4 4x) 8:34 PM 3/29/2023 X ☆ Ę
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education