plz help me in my assignment
We want to encode text files to keep the data private. Write a program that does the following:
â€¢ Read a text file (check for exceptions) and print the contents of the file (as one long string)
â€¢ Analyse the encoding instructions
â€¢ Apply the encoding instructions to the contents of the file
â€¢ Write the contents to a new file
â€¢ Open the new file and print its contents
The encoding instructions will be given in the form “ae;ea;s3”.
For this example this would mean to change â€˜aâ€™ to â€˜eâ€™, change â€˜eâ€™ to â€˜aâ€™ and change â€˜sâ€™ to â€˜3â€™.
Your program needs to also work with any other encoding instructions provided.
The new file must have the old filename with the word â€œEncodedâ€ added to the basic name.
For example, â€œmessage.txtâ€ will become â€œmessageEncoded.txtâ€.
The first line of your main function must look like this:
def encode(pattern, filename) :
An example output would look like this:
>>> encode(“ae;ea;s3”, “F:\message.txt”)
This is a test message
Change a to e
Change e to a
Change s to 3
Thi3 i3 e ta3t ma33ega