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. 2. A message that is to be encoded. 3. A file name for output of the encoded version of the message. 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 I/O (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 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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Topic Video
Question

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.
2. A message that is to be encoded.
3. A file name for output of the encoded version of the message.
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 I/O (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
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 Solution
steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Instruction Format
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education