Prof. Tashfeen
CS 2163: Java
Assignment 3
During the Gallic Wars, Julius Caesar was tired of his military messages being intercepted when en route
to his generals. He soon started writing the messages of military importance in different ciphers. E. g., he
would substitute Greek letters for each of their Roman counter parts so "computer science” would have
been something like koµτvtep σkɩevke. However, a cipher more commonly attributed to him is called the
Caesar cipher. He would substitute each letter in the message by the one that comes 3 places after it in
the alphabet. Similarly, his generals would shift each letter of the cipher text back 3 places to read the
original message. Letters at the end of the alphabet may wrap around.
This way, even if the messenger was captured by the Gauls and the contents of the message exposed,
they would look like utter garbage.
Take, e. g., ATTACK AT DAWN.
Original ABCDEFGHI
Shifted
DEFGHI
J
JKLMNOPQRSTUVWXYZ
KLMNOPQRSTUVWXY
TABLE 1. Caesar cipher with a key of k = 3.
Shifted three places using the table 1, we get: DWWDFN DW GDZQ.
Question 1. Use the table 1 to decipher LW KDSSHQV WRQLJKW, what do you get?
Question 2. Use the table 1 to encrypt BURN THE BOATS, what do you get?
Z
ABC
Question 3. If you were a Gallic general and knew Caesar's shifting technique, could you decipher,
CVBSVPY, J'LZA WVBCVPY without knowing the key? What does it mean? Answering No, I could'nt. is
fine.
Question 4. What does the print statement System.out.println((char)('a'+3)) print in Java?
Question 5. Read the relevant parts of the textbook as described in the online classroom. Implement
Caesar Cipher with a key of -25 ≤ k ≤ 25 as a Java class CaesarCipher.java. Use this class in another
file called LastnameFirstname.java. LastnameFirstname.java should interactively prompts the user for
a string and then a key. It then outputs the shifted (cipher) text. When the user inputs a “q” the program
should exit gracefully. You may get started with the starter code found here.
5.1. REQUIREMENTS
Note that these are not merely suggestions. You will lose points (possibly all of them) if you don't fulfil
these. Even if your program works.
1) You must close your scanner.
2) If the user inputs “q” for the string, your program should gracefully exit.
3) Your program must only shift the 26 letters in the English alphabet. I. e., leave the punctuation
etc. alone.
4) If you obtain a cipher text using a key of k, then your program should give the original text when
fed the cipher text but with a key of −k.
5) You must design the code as described, i. e., write a class in CaesarCipher.java and a REPL (Read-
Eval-Print Loop) in the main method of LastnameFirstname.java. If you used the provided code
then don't forget to change the name where appropriate.
6) Your program must compile and run from the command line using javac and java commands.
7) If you've been asked to demonstrate your program to the professor then you'll need to do so in his
office hours or make an appointment. If you've been asked to demo your program and you fail to
do so, you will receive a zero in the assignment.
1 5.2. EXAMPLE EXECUTIONS
code --zsh - 80×24
[tfn@othello [ code ] % javac CaesarCipher.java
[tfn@othello [ code ] % javac TashfeenAhmad.java
[tfn@othello [ code ] % java TashfeenAhmad
[TXT] ATTACK AT DAWN
[KEY] 3
[ENC] DWWDFN DW GDZQ
[TXT] DWWDFN DW GDZQ
[KEY] -3
[ENC] ATTACK AT DAWN
[TXT] q
tfn@othello [ code ] %
2
FIGURE 1. Example execution for the assignment
SUBMISSION INSTRUCTIONS
program.
1) A PDF document containing the answers to all the questions. For question 5, include a screenshot
like the one in figure 1. Please enlarge the font-size of your terminal such that it is not hard to read.
2) Submit your LastnameFirstname.java and CaesarCipher.java files. Note that these are not the
bytecode files.
You will not receive any credit if any of the files to be submitted are missing.
OKLAHOMA CITY COMMUNITY COLLEGE