Write a program that uses a dictionary to assign “codes” to each letter of the alphabet. For example: codes = { ‘A’ : ‘%’, ‘a’ : ‘9’, ‘B’ : ‘@’, ‘b’ : ‘#’, etc . . .} Using this example, the letter A would be assigned the symbol %, the letter a would be assigned the number 9, the letter B would be assigned the symbol @, and so forth. The program should open a specified text file, read its contents, then use the dictionary to write an encrypted version of the file’s contents to a second file. Each character in the second file should contain the code for the corresponding character in the first file. Write a second program that opens an encrypted file and displays its decrypted contents on the screen.
USING PYTHON
File Encryption and Decryption
USING PYTHON Write a
example:
codes = { ‘A’ : ‘%’, ‘a’ : ‘9’, ‘B’ : ‘@’, ‘b’ : ‘#’, etc . . .}
Using this example, the letter A would be assigned the symbol %, the letter a would be assigned
the number 9, the letter B would be assigned the symbol @, and so forth.
The program should open a specified text file, read its contents, then use the dictionary to write
an encrypted version of the file’s contents to a second file. Each character in the second file
should contain the code for the corresponding character in the first file.
Write a second program that opens an encrypted file and displays its decrypted contents on the
screen.
find below 2 files that are text documents to be used for the program
1. FILE NAME : text.txt
No one is unaware of the name of that famous English shipowner, Cunard.In 1840 this shrewd industrialist founded a postal service between Liverpool and Halifax, featuring three wooden ships with 400-horsepower paddle wheels and a burden of 1,162 metric tons.Eight years later, the company's assets were increased by four 650-horsepower ships at 1,820 metric tons, and in two more years, by two other vessels of still greater power and tonnage.In 1853 the Cunard Co., whose mail-carrying charter had just been renewed, successively added to its assets the Arabia, the Persia, the China, the Scotia, the Java, and the Russia, all ships of top speed and, after the Great Eastern, the biggest ever to plow the seas.So in 1867 this company owned twelve ships, eight with paddle wheels and four with propellers.If I give these highly condensed details, it is so everyone can fully understand the importance of this maritime transportation company, known the world over for its shrewd management.No transoceanic navigational undertaking has been conducted with more ability, no business dealings have been crowned with greater success.In twenty-six years Cunard ships have made 2,000 Atlantic crossings without so much as a voyage canceled, a delay recorded, a man, a craft, or even a letter lost.Accordingly, despite strong competition from France, passengers still choose the Cunard line in preference to all others, as can be seen in a recent survey of official documents.Given this, no one will be astonished at the uproar provoked by this accident involving one of its finest steamers.
FILE 2:
FILENAME: codes.txt
codes =
{'A':')','a':'0','B':'(','b':'9','C':'*','c':'8',\
'D':'&','d':'7','E':'^','e':'6','F':'%','f':'5',\
'G':'$','g':'4','H':'#','h':'3','I':'@','i':'2',\
'J':'!','j':'1','K':'Z','k':'z','L':'Y','l':'y',\
'M':'X','m':'x','N':'W','n':'w','O':'V','o':'v',\
'P':'U','p':'u','Q':'T','q':'t','R':'S','r':'s',\
'S':'R','s':'r','T':'Q','t':'q','U':'P','u':'p',\
'V':'O','v':'o','W':'N','w':'n','X':'M','x':'m',\
'Y':'L','y':'l','Z':'K','z':'k','!':'J','1':'j',\
'@':'I','2':'i','#':'H','3':'h','$':'G','4':'g',\
'%':'F','5':'f','^':'E','6':'e','&':'D','7':'d',\
'*':'C','8':'c','(':'B','9':'b',')':'A','0':'a',\
':':',',',':':','?':'.','.':'?','<':'>','>':'<',\
"'":'"','"':"'",'+':'-','-':'+','=':';',';':'=',\
'{':'[','[':'{','}':']',']':'}'}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps