PYTHON
CRYPTOGRAPHY – BOOK CIPHER

 

 

DESCRIPTION


You will write code related to the Book cipher that can be used in encrypting/decrypting messages.


THE BOOK CIPHER

 

The Book cipher is a cipher that utilizes a book to encrypt a message.  The same book is needed to decrypt the message.  The book needs to be big enough to cover almost all needed words. 

 

The process of encrypting and decrypting is simple enough – though time consuming I imagine.  Essentially, you replace each word with its page,line and word number location in the book. 

 

The person decrypting the message needs to know the book and then can simply look up each word one at a time.

WORK

 

QUESTION 1

Consider the book called The Great Song Book.  It has the page number on the first line of every page and a separating line of = symbols to demark the beginning/end of pages.

 

Do the following work in a file called Book:

a)     Write a function named book_contains_word that checks to see if a provided word is in the book.  It should return true or false.

b)     Write a function named book_contains_text that checks to see if all words in a provided message is in the book.  It should return true or false.

c)     Write a function named location_word that gets a word and returns a string of form #,#,# where the numbers symbols are the page number, line number and word number where the word is found.  The string “” should be returned if the word is not in the book.

d)     Write a function named location_text that gets a plaintext message (several words) and returns the location of every word in the plaintext each on a separate line (separated by \n).  This is effectively creating a the ciphertext.

e)     Write the function named enc that will get a message as parameter and check if all words are in the book.  If they are, it returns the ciphertext.  If they aren’t, it returns the word “error”.

 

QUESTION 2

 

Write the function dec that will decrypt a book ciphertext.  Essentially, it looks up all words based on the #,#,# addressing scheme used by book ciphers.

 

QUESTION 3

 

The following cyphertext has been encrypted using the Book cipher.  The book used is The Great Song Book (same as above).  Decrypt it using your program.

 

7,13,3

6,9,10

3,4,4   

7,3,5

2,9,3

7,13,3

4,15,2

3,30,5

9,27,6

5,25,8