Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN PYTHON!!! Part 2: File I/O We will be reading encoded messages and encodings from the following types of files 1. Encoding Files-these files contain

IN PYTHON!!!

image text in transcribed

Part 2: File I/O We will be reading encoded messages and encodings from the following types of files 1. "Encoding Files"-these files contain "maps" between symbols, for example, the dictionary ", "b", "bd": "c", ": "l" } could be stored in a file that looked like " { "ab": ": "d", 2,1 ab, b Notes The numbers on the first line are the number of characters for the keys/values respectively The comma can be part one of the items encoded/ decoded, so you'll want to be careful. Encoding files will always store encoding dictionaries (never decoding dictionaries). 2. "Secret Files" - these files contain secret messages to be decoded and are in different formats for each of the ciphers. More details will be covered in encode to file() Helper Functions read mapping file(file name): This function accepts a the file name of an encoding file and returns an encoding dictionary mapping. write mapping file (file_name, mapping): This function accepts a encoding dictionary (mapping) and writes it out as a valid encoding file (to the file specified by the file name). Cipher Encoding Functions encode to file (cipher_name, cipher info, file_name): This function accepts a cipher name, a tuple of information for the cipher, and a file name to write to. The cipher name will be "substitution", "caesar", " vigenere", or "rail". Depending on what cipher you are asked to write out, you will do one of the following: For a substitution cipher: cipher info will be a tuple with two items: an encoding dictionary and a message (in that order). You'l1 need to write out an encoding file (named "encoding_" +file name), encode the message, and write the encoded message in a second file (named file name). This second file is a "secret file" for a substitution cipher and its format is substitution file name of encoding file.txt dsf serf sg rd gdgrr sgs Notes: "substitution" at the top of the file should be that exact word * file_name_of_encoding file.txt should be replaced with the name of the encoding file you wrote to * everything after the file name is the encoded message (e.g. dsf serf sg rgd gdgrr sgsg) For a Caesar cipher: cipher info will be a tuple with two items: a shift and a message (in that ord). You'11 need to encode the message using the shift specified and store the encoded message in a file (named file_name). This file isa "secret file" for the Caesar cipher which looks like caesa 5 dsf serf sg red gdgrr sgs Notes: "caesar" at the top of the file should be that exact word 5 should be replaced with the shift value for the Caesar cipher you used * everything after the shift is the encoded message (e.g. dsf serf sg rgd gdgrr sgsg) Part 2: File I/O We will be reading encoded messages and encodings from the following types of files 1. "Encoding Files"-these files contain "maps" between symbols, for example, the dictionary ", "b", "bd": "c", ": "l" } could be stored in a file that looked like " { "ab": ": "d", 2,1 ab, b Notes The numbers on the first line are the number of characters for the keys/values respectively The comma can be part one of the items encoded/ decoded, so you'll want to be careful. Encoding files will always store encoding dictionaries (never decoding dictionaries). 2. "Secret Files" - these files contain secret messages to be decoded and are in different formats for each of the ciphers. More details will be covered in encode to file() Helper Functions read mapping file(file name): This function accepts a the file name of an encoding file and returns an encoding dictionary mapping. write mapping file (file_name, mapping): This function accepts a encoding dictionary (mapping) and writes it out as a valid encoding file (to the file specified by the file name). Cipher Encoding Functions encode to file (cipher_name, cipher info, file_name): This function accepts a cipher name, a tuple of information for the cipher, and a file name to write to. The cipher name will be "substitution", "caesar", " vigenere", or "rail". Depending on what cipher you are asked to write out, you will do one of the following: For a substitution cipher: cipher info will be a tuple with two items: an encoding dictionary and a message (in that order). You'l1 need to write out an encoding file (named "encoding_" +file name), encode the message, and write the encoded message in a second file (named file name). This second file is a "secret file" for a substitution cipher and its format is substitution file name of encoding file.txt dsf serf sg rd gdgrr sgs Notes: "substitution" at the top of the file should be that exact word * file_name_of_encoding file.txt should be replaced with the name of the encoding file you wrote to * everything after the file name is the encoded message (e.g. dsf serf sg rgd gdgrr sgsg) For a Caesar cipher: cipher info will be a tuple with two items: a shift and a message (in that ord). You'11 need to encode the message using the shift specified and store the encoded message in a file (named file_name). This file isa "secret file" for the Caesar cipher which looks like caesa 5 dsf serf sg red gdgrr sgs Notes: "caesar" at the top of the file should be that exact word 5 should be replaced with the shift value for the Caesar cipher you used * everything after the shift is the encoded message (e.g. dsf serf sg rgd gdgrr sgsg)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

ISBN: 1285427106, 978-1285427102

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago