This question concerns the use of a book cypher to encode a message. Write a program...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
This question concerns the use of a book cypher to encode a message. Write a program called 'bookcypher.py' that accepts: 1. The file name for a Project Gutenberg book text. A message that is to be encoded. 3. A file name for output of the encoded version of the message. 2. The program will create an encoded version of the message by replacing its words with the locations of words in the book. Say, for example, the message is 'meet me at the usual time and place', and the Gutenberg text is 'The Importance of Being Earnest' by Oscar Wilde. There is an occurrence of 'meet' as the 5th word on the 493rd line of the book text. There is an occurrence of 'me' as the 9th word on the 190th line of the text. There is an occurrence of 'at' as the 6th word on the 8th line of the text. And so on. Representing a word position as a conjunction of the line number and the index of the word within the line, we can encode the message as 493-5, 190-9, 8-6, etc. Sample 1/0 (user input in bold): Enter the book filename: ImportanceOfBeingEarnest.txt Enter the message: Meet me at the usual time and place Enter the output filename: secret.txt BEGIN 492-5 129-9 4-10 1-1 174-3 71-1 4-13 253-6 END CONTINUED Version: 2020/06/07 13:04 The program will output results to the given file ('secret.txt' in the example) AND to the screen. The first line of results will consist of the word 'BEGIN'. Subsequent lines will consist of word encodings, one per line. A word encoding will consist of a line number, a hyphen, and a word index. The last line of results will consist of the word 'END'. NOTE: You can assume the message does not contain punctuation. If a word match cannot be found, the program should output the word itself instead of a line number and word index encoding. You can use the string 'split()'method to split a sentence up into words e.g. >>> 'how now, brown cow.'.split() ['how', 'now,', 'brown', 'cow. '] >>> The result is a list of strings, one for each word. To clean up the results of split(),i.e. to get rid of bits of punctuation stuck to words, you can use the string 'strip ()'method e.g. >>> 'eh?'.strip ('?!.,;:) ([]{}\'" \n') 'eh' >>> "('ello!)".strip ('?!.,;:) ([]{}\'" \n') 'ello' >>> The parameter to the strip () method is a string containing instances of all the characters we want to remove. This question concerns the use of a book cypher to encode a message. Write a program called 'bookcypher.py' that accepts: 1. The file name for a Project Gutenberg book text. A message that is to be encoded. 3. A file name for output of the encoded version of the message. 2. The program will create an encoded version of the message by replacing its words with the locations of words in the book. Say, for example, the message is 'meet me at the usual time and place', and the Gutenberg text is 'The Importance of Being Earnest' by Oscar Wilde. There is an occurrence of 'meet' as the 5th word on the 493rd line of the book text. There is an occurrence of 'me' as the 9th word on the 190th line of the text. There is an occurrence of 'at' as the 6th word on the 8th line of the text. And so on. Representing a word position as a conjunction of the line number and the index of the word within the line, we can encode the message as 493-5, 190-9, 8-6, etc. Sample 1/0 (user input in bold): Enter the book filename: ImportanceOfBeingEarnest.txt Enter the message: Meet me at the usual time and place Enter the output filename: secret.txt BEGIN 492-5 129-9 4-10 1-1 174-3 71-1 4-13 253-6 END CONTINUED Version: 2020/06/07 13:04 The program will output results to the given file ('secret.txt' in the example) AND to the screen. The first line of results will consist of the word 'BEGIN'. Subsequent lines will consist of word encodings, one per line. A word encoding will consist of a line number, a hyphen, and a word index. The last line of results will consist of the word 'END'. NOTE: You can assume the message does not contain punctuation. If a word match cannot be found, the program should output the word itself instead of a line number and word index encoding. You can use the string 'split()'method to split a sentence up into words e.g. >>> 'how now, brown cow.'.split() ['how', 'now,', 'brown', 'cow. '] >>> The result is a list of strings, one for each word. To clean up the results of split(),i.e. to get rid of bits of punctuation stuck to words, you can use the string 'strip ()'method e.g. >>> 'eh?'.strip ('?!.,;:) ([]{}\'" \n') 'eh' >>> "('ello!)".strip ('?!.,;:) ([]{}\'" \n') 'ello' >>> The parameter to the strip () method is a string containing instances of all the characters we want to remove.
Expert Answer:
Answer rating: 100% (QA)
Screenshot Program def main Get input filename inputFileNameinputEnter ... View the full answer
Related Book For
Posted Date:
Students also viewed these databases questions
-
The use of a bank contributes significantly to good internal control over cash. Is this true? Why?
-
A manufacturer claims that through the use of a fuel additive, automobiles should achieve, on average, an additional 5 miles per gallon of gas. A random sample of 100 automobiles was used to evaluate...
-
This question concerns the items and the amounts that two entities, Nashua Co., and Ditka Hospital, should report in their financial statements. During September, Ditka provided Nashua with medical...
-
Suppose \(x\) is a linked-list Node. What is the effect of the following code fragment? \[x \cdot \text { next }=x \cdot \text { next } . \text { next; }\]
-
A continuous and aligned fiber-reinforced composite is to be produced consisting of 30 vol% aramid fibers and 70 vol% of a polycarbonate matrix; mechanical characteristics of these two materials are...
-
The stockholders' equity of Shoreside Occupational Therapy, Inc. on December 31, 2023, follows: E (Click the icon to view the data.) A (Click the icon to show additional information.) Read the...
-
An advanced engineering computer was purchased for $\$ 22,750$ and its expected life is 4 years. It is estimated the company could sell the computer for $\$ 500$ after 5 years. Compute and compare...
-
Garden Grove Corporation made a sale to a foreign customer on September 15, Year 1, for 100,000 foreign currency units (FCU). Payment was received on October 15, Year 1. The following exchange rates...
-
Over the past year private equity firms have been extremely active in financing management buyout of under performing and undervalued businesses. What options would be available to a private equity...
-
Erica and Bob participate in a friendly Hackathon that allows each to solve one question a day out of the three offered. There will be one easy, one medium and one hard question, with points awarded...
-
Question 01:- 1. Restate the significance of the Valence Band in the electronic structure of semiconductors. 2. Group semiconductor materials based on their electronic properties and applications. 3....
-
The quality inspection team at a plant for medium size vehicles intends to compare the acceptable thickness of two types of brake pads. The expected thickness of the brake pads is 12 milli meters. A...
-
The following accounts and amounts (balances are normal balances) were taken from the records of Prider Manufacturers Ltd at 30 June 2019. Required (a) Prepare a cost of goods manufactured statement...
-
Using the information from project 2 and information found on the internet, write a one-page paper on why these types of advertisements are used. Support your answer with information provided in the...
-
On 30 June 2019 the following information appeared in the accounting records of Ndung and Mkoka. Balance of Accounts Receivable Control account, $3725 Total of schedule of accounts receivable,...
-
The following is a set of data from a sample of n = 7: a. Calculate the first quartile (Q1), the third quartile (Q3), and the interquartile range. b. Find and list the five-number summary. c....
-
Wildhorse tested the equipment for impairment on December 3 1 , 2 0 2 4 , after recording the annual depreciation expense. It was determined that the equipments recoverable amount was $ 3 4 9 , 0 0 0...
-
Briefly discuss the implications of the financial statement presentation project for the reporting of stockholders equity.
-
What is a decision tree and how is it used?
-
Settler Company sells a number of products to many restaurants in the area. One product is a special meat cutter with a disposable blade. Blades are sold in a package of 12 at $20 per package. It has...
-
What role is played by activities in assigning costs to products using ABC? How does this differ from traditional costing?
-
Enter up a columnar purchases day book with columns for the various expenses for J. Still for the month from the following information on credit items. 2016 January f 1 Bought goods from H. Graham...
-
A Enter up a columnar purchases day book with columns for the various expenses for F. Graham for the month from the following information on credit items. 2016 June Bought goods from J. Syme 4 Bought...
-
Enter up the relevant accounts in the purchases and general ledgers from the columnar purchases day book you completed for Review Question 20.4A. Data From Review Question 20.4A 20.4A Enter up a...
Study smarter with the SolutionInn App