CIT 590 Assignment 12: Caesar Cipher
  Fall 2016, David Matuszek

Purposes of this assignment

General idea

The Caesar cipher is one of the oldest encryption techniques, and certainly one of the easiest to break.

The idea of a Caesar cipher is this: you encode a message by shifting each letter some number of places. Thus, if the shift is 2, then A becomes C, B becomes D, and so on. It is end around, so Y becomes A and Z becomes B. Like this:


For an accurate Caesar cipher, we would discard all punctuation, and group the text into blocks of five letters. We won't do that here; we will retain all spacing and punctuation, and all capitalization. This will enable us to decipher messages to get exactly the original message.


Name your project Caesar, and your package cipher. Create a class Caesar containing at least the following two methods:
String encipher(int shift, String plainText)
Enciphers the message, using the shift. Allow the shift to be any integer value; use the mod operator to cut it down to a value between 0 and 25.
String decipher(String cipheredText)
Given any message enciphered using a Caesar cipher, decipher it and return the deciphered message.
You may provide a main method if you feel like it, but it isn't required.

Code hints

In Java, a char is another type of integer value, so you can do arithmetic with it. However, the result will not be a char, but an int, so you have to cast it back to a char, like this: (char)('a'+1) gives 'b'.

You should work directly with characters in your program, don't write them as numbers. You can rely on the fact that the lowercase letters all have consecutive numeric values, and so do the uppercase letters.


Write unit tests for the above methods, and for any other I/O free methods you write. Name your test class CaesarTest.

How to do it

Download and save the word list at

A message will be correctly deciphered when it consists of mostly English words. It doesn't have to be entirely English words-that's too strict a test. The message may contain other things, such as the names of people or places.

Due date

Zip your Scala project and turn the zip file in to Canvas. Due by 11:59pm Tuesday, November 29.