Question: Java Program single Task : Please help if you can. I need help with a single task (class) in this program ( class VigenereCipher only

Java Program single Task: Please help if you can.

I need help with a single task (class) in this program (class VigenereCipher only) that will be extended from class SymmetricCipher (provided). This program is about Encryption (Hierarchy). All required classes to be used to extend will be provided below (links). Tester cases for this class is also at the bottom. Please read and help me. Thank you so much.

- Here is an overview of this program.

Object | +--Alphabet (finished) +--AlphabetException (finished) | | | +--BadIndexAlphabetException (finished) | | | +--MissingCharAlphabetException (finished) | +--Cipher (abstract) --> Provided | +--MorseCipher | +--SymmetricCipher (abstract) (Finished) | +--CaesarCipher | +--VigenereCipher (Help !!!) 

-----------------Java codes----------------------

Here is the link to the java codes for class Alphabet, AlphabetException, BadIndexAlphabetExceptionandMissingCharAlphabetException that I have finished (Will be used to inheret for this CaesarCipher class):https://paste.ee/p/19qsM

Here is the link to the java codes for class SymmetricCipher (will be used to extend):https://paste.ee/p/PIkkA

Note:

Encryption/Decryption

This is a bit trickier here, as Vigenere ciphers are stateful during encryption: they need to track which password integer to use for each position of the message. It is tempting to override encrypt()/decrypt() and write your own loops for this. Resist this urge and take the following approach:

Use an internal field associated with each instance of the class to track the position in the password array

Override encrypt() to set this field to 0, then call the parent method's version of encrypt()

In encrypt1() use the field to determine how much shifting is to be done. Then update the internal password position by incrementing it

Take a similar approach for decryption: override decrypt() to set the password position to 0 and use that position during decrypt1().

class VigenereCipher--------------------

Fields

protected String password The password, used to generate shift values.

protected int passwordPos; Records the current location in a String that is being crypted. This is the 'state' that is used in successive encrypt1calls by encrypt (similarly for decrypting).

Methods

public VigenereCipher(String password,Alphabet alphabet) The constructor initializes the data members. This includes the data member in the parent class SymmetricCipher.

public VigenereCipher(String password). The constructor initializes the data members. This includes the data member in the parent class SymmetricCipher, which is initialized to the DEFAULT Alphabet.

public String getPassword(). Returns password.

protected char encrypt1(char c). Relies upon password and passwordPos to encrypt a single char. Must increment passwordPos. Will throw MissingCharAlphabetException if any character is found that isn't in the alphabet.

Manual Inspection Criteria (5%): implement encrypt1/decrypt1 methods but rely on the inherited encrypt/decrypt methods fromSymmetricCipher.

protected char decrypt1(char c). Relies upon password and passwordPos to decrypt a single char. Must increment passwordPos. Will throw MissingCharAlphabetException if any character is found that isn't in the alphabet.

Manual Inspection Criteria (same as above): implement encrypt1/decrypt1 methods but rely on the inherited encrypt/decrypt methods from SymmetricCipher.

public String encrypt(String s). We can't wholly use the inherited version, because we need to know at what position in the string we're encrypting. Initializes passwordPos to 0, and then invokes the parent class's version of encrypt (which in turn uses this class's encrypt1 definition). When characters not in the alphabet are encountered, a MissingCharAlphabetException is thrown.

public String decrypt(String s). We can't wholly use the inherited version, because we need to know at what position in the string we're decrypting. Initializes passwordPos to 0, and then invokes the parent class's version of decrypt (which in turn uses this class's decrypt1 definition). When characters not in the alphabet are encountered, a MissingCharAlphabetException is thrown.

public String toString(). Return a string representation of the cipher in the following format

Vigenere Cipher (password='Cats') 

where the value associated with password is taken from the internal field of the class.

--------------------------Here is the link to the tester cases--------------------

Tester cases: https://paste.ee/p/aLj3o

---------------------------Additional Info--------------------------------

Summary of the whole Program (all tasks--clases): https://paste.ee/p/oyr5d

Introduction of this program (encryption): https://paste.ee/p/6iJER

Please check with the tester cases: Thank you so much

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!