CMSC 246 Systems Programming
Due: Friday October 4, 2019 11:59PM
If you are attending Grace Hopper, send me an email for a 48 hour extension
All code should following the style guidelines in https://cs.brynmawr.edu/Courses/cs246/fall2019/style.html
Book Code Cipher
The only provably secure method of encryption is the "book" cypher in which a "book" is used to create a cypher key. To explain the book cypher, first consider the Caesar cypher.
The Caesar cypher is one of the oldest known encryption techniques; it is attributed to Julius Caesar. It involves replacing each letter in a message with another letter that is a fixed number of positions later in the alphabet. For example, if each letter is replaced by one that is two positions after it, an A will be replaced by a C, an L by an N, etc. If the replacement goes past the letter Z, the cipher wraps around to the beginning of the alphabet. Thus, with the same shift (of two), a Y will be replaced by an A, and Z by B. More generally, the formula for Caesar encryption, assuming that the only thing encrypted is upper case letters, is ((ch-'A') + OFFSET) % 26 + 'A'.
The Book code cypher replaces the fixed offset of the Caesar cypher with an offset that is determined by the character in a text (classically the text is taken from a book, hence the name). The idea is that you and the person you are sending a message to agree on the book ahead of time. Then the encryptor picks a location in the book to start and encrypts the message. The encryptor sends the encrypted message to you along with the starting location in the book.
For example, suppose that the book is "The quick brown fox jumps over the lazy dog". Further suppose that you have agreed to skip over all non letters in the book and that any lower case letters should be changed to upper case in both the book and the text. Hence, the actual book to be used is
THEQUICKBROWNFOXJUMPSOVERTHELAZYDOGUnder these assumptions, the formula for a book code encryption is ((ch-'A') + (BOOKLETTER-'A')) % 26 + 'A'
For example, suppose that the text to be encoded is "GEOFF"
The table below shows 3 encryptions, the Caesar cypher with an offset of 5, the book cypher starting at 5 and the book cypher starting at 10:
|Original||Caesar||Book, start=5||Book, start=10|
|Text||formula||Result||Encrypted||BOOK Letter||formula||Value||Encrypted||BOOK Letter||formula||Value||Encrypted|
cryptor 1 sample.txt book.txt 241 > crypt.out cryptor 0 crypt.out book.txt 241 > decrypt.outthen text in decrypt.out and sample.txt should be the same except as given by the rules above.
void encryptA(char * nameOfFileToBeEncrypted, int bookLength, char book[bookLength], int bookStartingPosition);Hence, you might have an encryption formula like: ((ch-'A') + (book[i]-'A')) % 26 + 'A'
void encryptP(char * nameOfFileToBeEncrypted, int bookLength, char * book, int bookStartingPosition);Hence, you might have an encryption formula like: ((ch-'A') + (*book-'A')) % 26 + 'A'
Scripting in Linux
Once done, you will need to show the sample runs of programs, as required below. In order to record the runs, you can use the Linux command
Go to your Assignment directory and enter the command:
You will get your command prompt back. Next, run each of the above programs as you normally would. Once done, enter the command:
exit (or CTRL-D)
This will end your script session. If you now look a the contents of the session file, you will see that the entire interaction has been recorded in it (as a script!).
/home/gtowell/bin/submit -c 246 -p 4 -d a4This will package up everything in the directory a4 and submit it under your login name along with a timestamp of your submission date.
Back to CMSC246 Home page