Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

COSC 1306 Spring 2021 Assignment 11: Dictionary [1] Objectives: The purpose of this assignment is to practice dictionary usage and file reading and writing. The assignment will give you another chance...

1 answer below »
COSC 1306
Spring 2021
Assignment 11: Dictionary

[1] Objectives: The purpose of this assignment is to practice dictionary usage and file reading and
writing. The assignment will give you another chance to use files for input and output. Since this
is the last assignment, we will keep it very simple and short.

[2] Description: There are two files to read from: a codebook and a message file. The codebook
will encrypt a letter with another letter. Use the codebook to encrypt the message. The codebook
and the paragraph to be encrypted will be given in two separate files. You can hardwire the two
input file name in the program and output the encrypted paragraph to the console. If a letter is
not given in the codebook, leave it as-is in the encrypted paragraph. For example, if the codebook
includes three lines below:
a:e
e:c
c:a
If the paragraph to be encrypted is “It’s a nice day!”. The encrypted output should be: “It’s e
niac dey!”.

The following is what the algorithm should look like in the main program.
 Build the codebook (as a dict)
 Print the codebook in a table form
 Read the message
 Print the message
 Encrypt the message
 Print the encrypted message

[3] Requirements: Clearly, you will need to write four functions according to the algorithms
above. Assume the codebook is co
ect, i. e., you will be able to decode the message. Decoding
is NOT a requirement of this assignment. No e
or checking is required.

[3] Input and Output: See the sample output. The TA may test the program with a different
codebook or message.

[4] Deadline: Midnight, Monday, May 3, XXXXXXXXXXNo late assignment will be accepted for this one.

code_book.txt message.txt
a:f
f:c
c:d
d:l
l:a
:e
e:g
g:h
h:b
y:i
i:s
s:t
t:y
A:X
X:O
O:S
S:A
n:p
p:n
t:o
o:t
An operating system (OS) is system software that manages
computer hardware, software resources, and provides
common services for computer programs.

*** Letter to Code
a -> f
f -> c
c -> d
d -> l
l -> a
-> e
e -> g
g -> h
h -> b
y -> i
i -> s
s -> t
t -> o
A -> X
X -> O
O -> S
S -> A
n -> p
p -> n
o -> t
*** Original message:
An operating system (OS) is system software that manages
computer hardware, software resources, and provides
common services for computer programs.
*** Encrypted message:
Xp tngrfosph titogm (SA) st titogm ttcowfrg obfo mfpfhgt
dtmnuogr bfrlwfrg, ttcowfrg rgtturdgt, fpl nrtvslgt
dtmmtp tgrvsdgt ctr dtmnuogr nrthrfmt.
Answered 2 days After Apr 29, 2021

Solution

Neha answered on May 01 2021
162 Votes
82422 - python code/code.py
print("*** Letter to code")
code_dict = {}
with open("code_book.txt") as file:
for line in file:
(key, val) = line.rstrip("\n").split(":")
code_dict[key] = val
for key, value in code_dict.items():
print(key,"->",value)
print("*** Original message: ")
file = open("message.txt", "r")
print(file.read())
with...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here