Question
Java Problem: I need help with a Hierachy class (class Symmetric Cipher). This program is about Encryption. Please read and help me. Thank you so
Java Problem: I need help with a Hierachy class (class Symmetric Cipher). This program is about Encryption. Please read and help me. Thank you so much. Tester cases are provided at the bottom.
Object | +--Alphabet (finished) +--AlphabetException (finished) | | | +--BadIndexAlphabetException (finished) | | | +--MissingCharAlphabetException (finished) | +--Cipher (abstract) | +--MorseCipher | +--SymmetricCipher (abstract) (HELP !!!) | +--CaesarCipher | +--VigenereCipher
---------------------------------Here is the task that I need help------------------------
class Cipher
Class Cipher is an abstract class and all of its methods are abstract. This parent class represents any object that can encrypt and decrypt strings.
Methods
public abstract String encrypt(String s);
public abstract String decrypt(String s);
class SymmetricCipher
Class SymmetricCipher is an abstract class that inherits from class Cipher. Not all of its methods are abstract.
Fields
protected Alphabet alphabet: The alphabet that this cipher works on. Characters that are to be encrypted/decrypted that do not exist in the alphabet will cause problems. In such cases, a MissingCharAlphabetException should be raised.
Methods
public SymmetricCipher(Alphabet alphabet). The constructor initializes the data member.
public int wrapInt(int i). Given an index value that may be outside the range of valid indexes into the alphabet, wrap it back around to a valid index.
public int rotate(int index, int shift). Given an index into the alphabet, rotate it around shift times to the resulting valid index into alphabet. When the index is out of bounds in either direction, we wrap around until it's back in range. No matter what index and shift value is given, we should be able to return an answer (assuming the alphabet has a non-zero length! Which it always should).
Hint: doesn't this sound a bit like modular arithmetic?
public Alphabet getAlphabet(). Returns alphabet.
protected abstract char encrypt1(char c). Child classes must provide an implementation of this; it provides a way to encrypt a single character. Child class implementations will throw MissingCharAlphabetException if any character is found that isn't in the alphabet.
protected abstract char decrypt1(char c). Child classes must provide an implementation of this; it provides a way to decrypt a single character. Child class implementations will throw MissingCharAlphabetException if any character is found that isn't in the alphabet.
public String encrypt(String s). Implement this method based upon the encrypt1 definition (below), which encrypts a single character (think of the Caesar Cipher for an understanding). Throws MissingCharAlphabetException if any character is found that isn't in the alphabet.
Manual Inspection Criteria (5%): encrypt/decrypt methods correctly invoke encrypt1/decrypt1 as part of their solution.
public String decrypt(String s). Implement this method based upon the decrypt1 definition, which decrypts a single character (think of the Caesar Cipher for an understanding). Throws MissingCharAlphabetException if any character is found that isn't in the alphabet.
Manual Inspection Criteria (same as above): encrypt/decrypt methods correctly invoke encrypt1/decrypt1 as part of their solution.
-------------------------------------Here is the tester cases----------------------
Tester cases for Class SymmetricCipher: https://paste.ee/p/aVCsy
-----------------------------------Addtional Info-----------------------------
Since this program is about Hierarchy. The task that I need help with required the first 3 classes of the program.
Here is the link of java codes of the first 3 tasks that I have finished: https://paste.ee/p/33qTc
Here is the link to the first 3 tasks of the program (class Alphabet and AlphabetException)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started