Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do I write a (very simple) second program that opens this encrypted file and displays its ---decrypted--- contents on the screen? def main(): #

How do I write a (very simple) second program that opens this encrypted file and displays its ---decrypted--- contents on the screen?

def main():

# dictionary

codes = {'A' : '%', 'a' : '9', 'B' : '@', 'b' : '#', 'C' : '$', 'c' : '&', 'D' : '^', 'd' : '*','E' : '1', 'e' : '2', 'F' : '3', 'f' : '4', 'G' : '5', 'g' : '6', 'H' : '7', 'h' : '8', 'I' : '10', 'i' : '!', 'J' : '~', 'j' : '+', 'K' : '=', 'k' : '+', 'L' : '?', 'l' : '>', 'M' : '<', 'm' : '.', 'N' : '-', 'n' : '_', 'O' : ':', 'o' : '|', 'P' : '[', 'p' : ']', 'Q' : '{', 'q' : '}', 'R' : ';', 'r' : '12', 'S' : '13', 's' : '14', 'T' : '15', 't' : '16', 'U' : '#', 'u' : '!', 'V' : '@', 'v' : '$', 'W' : '%', 'w' : '^', 'X' : '&', 'x' : '*', 'Y' : '+', 'y' : '~', 'Z' : '{', 'z' : '>' }

# opening the file to be encrypted

file1 = open('text.txt', 'r')

file_read = file1.read()

file1.close()

# Create file for encrpyted message

encrypted_file = open('encrypted.txt', 'w')

# start loop

for ch in file_read:

if ch in codes:

encrypted_file.write(codes[ch])

else:

encrypted_file.write(ch)

encrypted_file.close()

main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Write a program to check an input year is leap or not.

Answered: 1 week ago

Question

Write short notes on departmentation.

Answered: 1 week ago

Question

What are the factors affecting organisation structure?

Answered: 1 week ago

Question

What are the features of Management?

Answered: 1 week ago

Question

Briefly explain the advantages of 'Management by Objectives'

Answered: 1 week ago