Skip to content

Final-TakeHome

This is the final assignment. This homework will replace the final exam.

Due Date: Tuesday, May 5th before midnight.

Note that if you submit late you will receive a ZERO. I recommend that you try to submit by Sunday, May 3rd.

Download:

The take-home crypto_template.

Your Task:

Your objective is to fill the provided method templates to accomplish the tasks described below. The way we will grade this is as usual: the more asserts you pass, the better.

Assignment Objective:

The provided template provides the structure for a simple encryption/decryption machine. Its purpose is to convert an input human-readable text (called plaintext) into an encrypted text (called ciphertext) and vice-versa. If you want a short primer on simple encryption/decryption, check this link.

The Class CryptoTool

The class called Crypto will allow you to encrypt and decrypt a message by combining the caesar cipher and some list and string manipulations.
We will refer to a Caesar cipher offset of 1 one that obtains the "next letter in the alphabet". So if the input is an 'a', the output is a 'b'; an offset of 2 would mean an input of 'a' would get an output of 'c', and so on.
For this project, we will use the rule that we will only apply Caesar cipher to lowercase letters. All uppercase letters and symbols will be left the same.

Encrypting will be done (stored in a String) by doing the following steps:

  • Initialize a CryptoTool object with a plaintext and an offset
    • (example text:"Oh Hello World!" offset: 1)
  • Convert the text into a linked list of words:           [“Oh”]->[“Hello”]->[“World!”]
  • Reverse every word in the list:                                 [“hO”]->[“olleH”]->[“!dlroW”]
  • Apply the caesar Offset (1) to each word:              [“iO”]->[“pmmfH”]->[“!emspW”]
  • Rotate the list forward by ‘offset’ (1) moves:         [“!emspW”]->[“iO”]->[“pmmfH”]
  • Convert plaintext to ciphertext:                               "!emspW iO pmmfH"

Note that I represent a list by using square brackets (nodes) separated by arrows ("next" references).

Decrypting is doing the opposite sequence:

  • Convert the ciphertext into a linked list of words:           [“!emspW”]->[“iO”]->[“pmmfH”]
  • Rotate the list Backward by ‘offset’ (1) moves:                  [“iO”]->[“pmmfH”]->[“!emspW”]
  • Apply the reverse caesar Offset (1) to each word:            [“hO”]->[“olleH”]->[“!dlroW”]
  • Reverse every word in the list:                                             [“Oh”]->[“Hello”]->[“World!”]
  • Convert ciphertext to plaintext:                                           "Oh Hello World!""

Check Encrypt-Decrypt to see the description in more detail.

The Methods

The methods in class CryptoTool are combined to accomplish the encrypt and decrypt actions. Look at the main to see the order in which you should complete them. Complete the methods in the order in which they are called by the asserts.

  • public CryptoTool()
    Class empty constructor. Should set default text: "It ain’t over till it’s over!"  and a caesarOffset of 0.
  • public CryptoTool(String text, int offset)
    Class constructor. Should set input text and caesarOffset
  • public boolean setPlainText (String text)
    Set the base plaintext
  • public boolean setCipherText (String text)
    Set the base ciphertext
  • public boolean setCaesarOffset (int offset)
    Sets the Caesar-cypher offset and calls buildTable
  • public boolean checkOffset(int offset)
    Checks that the offset value is in [0 to 26]
  • public boolean buildTable(int offset)
    Build the Caesar table using the offset

    • First row (0) has the base plain chars: a -> z
    • Second row (1) has the offset cipher chars: a+offset -> z+offset
    • Use the method getCipherLetter (provided) for each plainLetter.
  • public boolean textToList (String text)
    Extract words from text and insert into our linked list (it overwrites it!) Note: check text.split(" ").
  • public String listToText ()
    Extract words from the linked list and return a string with them (with spaces in between but not at the end).
  • public String invertWord(String word)
    Get the reverse of an input String example: pupils -> slipup
  • public boolean invertAllWordsInList()
    Apply invertWord to each word in the list
  • public rotateListFwd (int offset)
    Rotates the linked list forward by an offset example ab->cde->fg->h becomes h->ab->cde->fg
  • public boolean rotateListBwd (int offset)
    Rotates the linked list backward by an offset example ab->cde->fg->h becomes cde->fg->h->ab
  • public String applyCaesarToWord(String word, boolean isEncrypt)
    Apply the Caesar offset to the String (for encrypt or decrypt) For each letter, if it is a lowercase letter,  apply getLetterFromTable (provided) to build the output word
  • public boolean applyCaesarToList(boolean isEncrypt)
    Apply the Caesar offset to every word in the List
  • public boolean encrypt ()
    Convert text from plaintext to ciphertext Note: it overwrites ciphertext and linkedList.
  • public boolean decrypt ()
    Convert text from ciphertext to plaintext Note: it overwrites plaintext and linkedList.

Note that several methods have been provided, including getters, print methods,  and two caesar-cipher related methods which you should read and understand.


Notes and grading: Your implementations must compile to get any credit. All of the required methods must compile, even if they don't work. Please develop these in small chunks. Don't program everything, and hope it will work. Write each method separately, and test it separately. Your implementation will get credit proportional to how many assertions they pass. Make sure to submit your .java file, and that CryptoTool.java has the correct class name. Your main method will not be invoked, so do not assume that it executes.

If you simply implement your methods in such a way that they are customized to the specific test cases we provide (i.e. by returning the desired string, but not having any of the logic required by the assignment), you'll receive no credit.

Submission: Please submit your .java file via blackboard.


Plagiarism: all submissions will be automatically compared with each other for plagiarism. This checking can distinguish copied code even when variable names and spacing is altered. If your work is flagged and there is no credible explanation for identical code structures, you will receive an F and might face harsher consequences. We will also check against code found online. Easiest way to avoid trouble: DO NOT COPY.