Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that reads and encrypts a text file. Encryption is the science o

ID: 3783871 • Letter: W

Question

Write a program that reads and encrypts a text file. Encryption is the science of hiding the contents of the file from users that are not allowed to read its contents. Your program will first read the data from a text file called data.txt and save the information in an array of strings. The first line of the text file has an integer value that indicates the number of lines in the text file. This number will allow you to create a dynamic array of the correct number of strings, where each element in the array of strings will hold a single line of text. After the data is read and saved in the array, the next step is to encrypt the data Modify the contents of the array by encrypting its contents one element at a time. A very simple way of encrypting data is going through a string one character at a time, and adding 7 to the ASCII code of the character. After you are done with the text encryption, write the contents of the array in reverse order to a text file called. For example, let us assume that the content of is the following CMPsc 122: Intermediate Programming This is an example of encrypting text. The integer value 2 in the first line indicates that the file is composed of two lines of strings. You will then create a dynamic array of two strings where the first element of the array will hold the following string "CMPS 122: Intermediate Programming" while the second element will hold "This is an example of encrypting text. "The next step is to encrypt the contents of the array and save it in a file called. The contents of the file should now look like Where the first encrypted line refers to "This is an example of encrypting text." In addition to the main function, your program should have the following functions: A function that reads the input from the text file (data.txt) and saves it in an array A function that encrypts the contents of the array of strings A function that saves the encrypted data to the output file

Explanation / Answer

//Code is writen in python

with open(data.txt) as inputFile:

    EachLineList=[tuple(line.split('/n')) for line in inputFile.readlines()] //Splits the line into a Array list

LineCount= EachLineList[0]                                                 //First element is the no of line in file

for i in range(1,LineCount):

    LineStr=EachLineList[i].split()                                     //Split the sentences into individual characters

    foreach x in LineStr:

        LineStr[i]=chr(ord(LineStr[i])+7)                           // Add 7 to the ASCII value of every character

    LineStr=''.join(LineStr)

    with open('encryt.txt','a') as NewFile:    // Create a new text file and append the new data every time

    NewFile.write(LineStr)

Note:- Follow the indentation as done in the code

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote