Question: The Python code needs to be expressed as two functions as shown above. This is the link to the text: https://www.gutenberg.org/cache/epub/5200/pg5200.txt We will implement a

 The Python code needs to be expressed as two functions as

shown above. This is the link to the text: https://www.gutenberg.org/cache/epub/5200/pg5200.txt We will

The Python code needs to be expressed as two functions as shown above. This is the link to the text: https://www.gutenberg.org/cache/epub/5200/pg5200.txt

We will implement a very simple encryption scheme that closely resembles the one-time-pad. You have probably seen this method used in movies like Unknown. The idea is that you and your counterparty share a book whose words you will use as the raw material for a codebook. In this case, you need Metamorphosis, by Franz Kafka. Your job is to create a codebook of 2-tuples that map to specific words in the given text based on the line and position the words appears in the text. The text is very long so there will be duplicated words. Strip out all of the punctuation and make everything lowercase For example, the word let appears on line 1682 in the text as the fourth word (reading from left-to-right). Similarly, the word us appears in the text on line 1760 as the fifth word. Thus, if the message you want to send is the following: let us not say we met late at the night about the secret Then, one possible valid sequence for that message is the following [ (1682,4), (1760,5), (165e,2), (304,7), (1190,4), (2327,2), (731,4), (988,4), (1091,6), (958,7), (564,10), (1923,9), (849,2)] Your counterparty receives the above sequence of tuples, and, because she has the same text, she is able to look up the line and word numbers of each of the tuples to retrieve the encoded message. Notice that the word the appears twice in the above message but is encoded differently each time. This is because re- using codewords (i.e., 2-tuples) destroys the encryption strength. In case of repeated words, you should have a randomized scheme to ensure that no message contains the same 2-tuple, even if the same word appears multiple times in the message. If there is only one occurrence of a word in the text and the message uses that word repeatedly so that each occurrence of the word cannot have a unique 2-tuple, then the message should be rejected. Your assignment is to create an encryption function and the corresponding decryption function to implement this scheme. Note that your downloaded text should have 2362 lines and 25186 words in it. We will implement a very simple encryption scheme that closely resembles the one-time-pad. You have probably seen this method used in movies like Unknown. The idea is that you and your counterparty share a book whose words you will use as the raw material for a codebook. In this case, you need Metamorphosis, by Franz Kafka. Your job is to create a codebook of 2-tuples that map to specific words in the given text based on the line and position the words appears in the text. The text is very long so there will be duplicated words. Strip out all of the punctuation and make everything lowercase For example, the word let appears on line 1682 in the text as the fourth word (reading from left-to-right). Similarly, the word us appears in the text on line 1760 as the fifth word. Thus, if the message you want to send is the following: let us not say we met late at the night about the secret Then, one possible valid sequence for that message is the following [ (1682,4), (1760,5), (165e,2), (304,7), (1190,4), (2327,2), (731,4), (988,4), (1091,6), (958,7), (564,10), (1923,9), (849,2)] Your counterparty receives the above sequence of tuples, and, because she has the same text, she is able to look up the line and word numbers of each of the tuples to retrieve the encoded message. Notice that the word the appears twice in the above message but is encoded differently each time. This is because re- using codewords (i.e., 2-tuples) destroys the encryption strength. In case of repeated words, you should have a randomized scheme to ensure that no message contains the same 2-tuple, even if the same word appears multiple times in the message. If there is only one occurrence of a word in the text and the message uses that word repeatedly so that each occurrence of the word cannot have a unique 2-tuple, then the message should be rejected. Your assignment is to create an encryption function and the corresponding decryption function to implement this scheme. Note that your downloaded text should have 2362 lines and 25186 words in it

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!