Question

File Encryption and Decryption chapter 9 programming exercise #3 Design and write a python program to...

File Encryption and Decryption

chapter 9 programming exercise #3

Design and write a python program to successfully complete chapter 9 programming exercise #3.

File Encryption and Decryption

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

****This requires some effort so please drop a like if you are satisfied with the solution*****

I have taken a sample text and providing screenshots of execution and files created so please go through them for reference and better understanding..

encryptor.py:

import os.path
Path="C://Users/THE__INFINITY/Desktop"
sampleFilePath=os.path.join(Path,"sample.txt")
encryptionFilePath=os.path.join(Path,"excryption.txt")

f=open(encryptionFilePath,'w+')
s=open(sampleFilePath,'r')

samplecontent=s.read()

letterdict={'h':'%','a':'!','p':'#','y':'$',' ':'^','c':'&','e':'*','g':'(','i':')','n':'-','1':',','2':'+','3':'`'}
for i in range(len(samplecontent)):
    f.write(letterdict[samplecontent[i]])
f.close()
s.close()

decryption.py:

import os.path
Path="C://Users/THE__INFINITY/Desktop"
encryptionFilePath=os.path.join(Path,"excryption.txt")
decryptionFilePath=os.path.join(Path,"decryption.txt")

e=open(encryptionFilePath,'r')
d=open(decryptionFilePath,'w+')
encryptedContent=e.read()
letterdict={'%':'h','!':'a','#':'p','$':'y','^':' ','&':'c','*':'e','(':'g',')':'i','-':'n',',':'1','+':'2','`':'3'}

for i in range(len(encryptedContent)):
    d.write(letterdict[encryptedContent[i]])

e.close()
d.close()

Add a comment
Know the answer?
Add Answer to:
File Encryption and Decryption chapter 9 programming exercise #3 Design and write a python program to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • program must be written in python and have commentary. thank you 3. File Encryption and Decryption...

    program must be written in python and have commentary. thank you 3. File Encryption and Decryption Write a program that uses a dictionary to assign "codes" to each letter of the alphabet. For example: codes-{A':'8','a' :'9', 'B' : e','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 e, and so forth. The program should open a...

  • Java Programming Part 1 File encryption is the science of writing the contents of a file...

    Java Programming Part 1 File encryption is the science of writing the contents of a file in a secret code. Your encryption program should work like a filter, reading the contents of one file, modifying the data into a code, and then writing the coded contents out to a second file. The second file will be a version of the first file, but written in a secret code. Although there are complex encryption techniques, you should come up with a...

  • In Python, write a program that assigns “codes” to each letter of the alphabet. For example,...

    In Python, write a program that assigns “codes” to each letter of the alphabet. For example, codes = {“a”: “%”, “b”:”9”, “c”:”?”,….} Write a function that takes in this dictionary and a sentence to encrypt the sentence. Write another function that takes the encrypted sentence and decrypt it.

  • In Python, do a basic encryption of a text file in the following manner. The program...

    In Python, do a basic encryption of a text file in the following manner. The program encrypt.py will read in the following text file and rearrange the lines in the file randomly and save the rearranged lines of txt to another file called encrypted.txt. It will also save another file called key.txt that will contain the index of the lines that were rearranged in the encrypted file, so for example if the 4th line from the original file is now...

  • Kindly follow the instructions provided carefully. C programming   Project 6, Program Design One way to encrypt...

    Kindly follow the instructions provided carefully. C programming   Project 6, Program Design One way to encrypt a message is to use a date’s 6 digits to shift the letters. For example, if a date is picked as December 18, 1946, then the 6 digits are 121846. Assume the dates are in the 20th century. To encrypt a message, you will shift each letter of the message by the number of spaces indicated by the corresponding digit. For example, to encrypt...

  • python Programming Exercise 4.7 Write a script that decrypts a message coded by the method used...

    python Programming Exercise 4.7 Write a script that decrypts a message coded by the method used in Project 6. Method used in project 6: Add 1 to each character’s numeric ASCII value. Convert it to a bit string. Shift the bits of this string one place to the left. A single-space character in the encrypted string separates the resulting bit strings. An example of the program input and output is shown below: Enter the coded text: 0010011 1001101 1011011 1011011...

  • Lab #10 C++ Write a C++ program that reads text from a file and encrypts the...

    Lab #10 C++ Write a C++ program that reads text from a file and encrypts the file by adding an encryption factor (EF) to the ASCII value of each character. The encryption factor is 1 for the first line and increases by 1 for each line up to 4 and then starts over at 1. So, for the 4 th line the EF is 4, for the 5th line it is 1, for the 10th line it is 2. In...

  • MASM Assembly language -- Message Encryption Pgm You are to write a program to input a...

    MASM Assembly language -- Message Encryption Pgm You are to write a program to input a text and a key and encrypt the text. I will supply you an encryption key consisting of multiple characters. Use this key to encrypt and decrypt the plain text by XOR-ing each character of the key against a corresponding byte in the message. Repeat the key as many times as necessary until all plain text bytes are translated. Suppose, for example, the key were...

  • C Program In this assignment you'll write a program that encrypts the alphabetic letters in a...

    C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...

  • 1.     This project will extend Project 3 and move the encryption of a password to a...

    1.     This project will extend Project 3 and move the encryption of a password to a user designed class. The program will contain two files one called Encryption.java and the second called EncrytionTester.java. 2.     Generally for security reasons only the encrypted password is stored. This program will mimic that behavior as the clear text password will never be stored only the encrypted password. 3.     The Encryption class: (Additionally See UML Class Diagram) a.     Instance Variables                                                i.     Key – Integer...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT