Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started