Julius Caesar used a simple encryption scheme to encrypt military messages. His military orders (written in Latin) were encoded by translating an 'A' to 'D', B to E etc.
Typically a secret is encoded using an offset of 13, so this encoding is known as 'ROT13'. (A Puzzle for you: what's special about 13? Cryptic Clue:13+13=26). Today, this substitution algorithm is still used to hide passwords from casual reading.
Your assignment is to create a Java program, CaesarCipher.java, that encodes and decodes text messages. Here's a description of what your program will initially do:
For the reverse engineering task you will have to look at the following test cases and recognize what pattern is being used.
public void testPositionShift() {
CheckInputOutput
.setInputCaptureOutput("999\nThere are two ways to write error-free programs, but only the third one works.\n\n");
String expected = "Please enter the shift value (between -25..-1 and 1..25)\n"
+ "Using position shift\n"
+ "Please enter the source text (empty line to quit)\n"
+ "Source :There are two ways to write error-free programs, but only the third one works.\n"
+ "Processed:TIGUI GYM DHA KPOJ MI SOGSE GUVTX-NAOP CFDWISFM, YSS PPOC ZOM DSUER EEW QJNHQ.\n"
+ "Please enter the source text (empty line to quit)\n"
+ "Bye.\n";
CaesarCipher.main(new String[0]);
int line = CheckInputOutput.checkCompleteOutput(expected);
if (line > 0)
fail("Review incorrect output on line " + line);
}
public void testDecodePositionShift() {
CheckInputOutput
.setInputCaptureOutput("-999\nTIGUI GYM DHA KPOJ MI SOGSE GUVTX-NAOP CFDWISFM, YSS PPOC ZOM DSUER EEW QJNHQ.\n\n");
String expected = "Please enter the shift value (between -25..-1 and 1..25)\n"
+ "Using position shift\n"
+ "Please enter the source text (empty line to quit)\n"
+ "Source :TIGUI GYM DHA KPOJ MI SOGSE GUVTX-NAOP CFDWISFM, YSS PPOC ZOM DSUER EEW QJNHQ.\n"
+ "Processed:THERE ARE TWO WAYS TO WRITE ERROR-FREE PROGRAMS, BUT ONLY THE THIRD ONE WORKS.\n"
+ "Please enter the source text (empty line to quit)\n"
+ "Bye.\n";
CaesarCipher.main(new String[0]);
int line = CheckInputOutput.checkCompleteOutput(expected);
if (line > 0)
fail("Review incorrect output on line " + line);
}
* Example Output 1: (User enters 0\n26\n3\nABCD EFGHIJKLMNOPQRSTUVWXYZ!\n\n) Please enter the shift value (between -25..-1 and 1..25) 0 is not a valid shift value. Please enter the shift value (between -25..-1 and 1..25) 26 is not a valid shift value. Please enter the shift value (between -25..-1 and 1..25) Using shift value of 3 Please enter the source text (empty line to quit) Source :ABCD EFGHIJKLMNOPQRSTUVWXYZ! Processed:DEFG HIJKLMNOPQRSTUVWXYZABC! Please enter the source text (empty line to quit) Bye. * Example Output 2: (User enters -3\ndefg hijklmnopqrstuVWXYZABC!\n\n) Please enter the shift value (between -25..-1 and 1..25) Using shift value of -3 Please enter the source text (empty line to quit) Source :DEFG HIJKLMNOPQRSTUVWXYZABC! Processed:ABCD EFGHIJKLMNOPQRSTUVWXYZ! Please enter the source text (empty line to quit) Bye.