Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Tasks: I need help with a single task (a single class) in this program. This program is about Encryption . Please read and help

Java Tasks: I need help with a single task (a single class) in this program. This program is about Encryption. Please read and help me with class SymmetricCipher.

INTRODUCTION:

Encryption Introduction

Encryption plays a central role in the age of computing. Every online purchase, every social media post, every login to a remote server would carry drastically more risk without the ability to obscure the contents of a message from intervening parties and still enable the message recipient to make sense of the message contents.

In this project, you will construct a small class hierarchy involving different kinds of encryption. The hierarchy will illustrate one of the nice features of inheritance: that several child classes can share and use code from a parent class in a uniform way. The fact that all of the classes will descend from a common parent also means they may be used interchangeably: a program wishing to do encryption could select from any of the ciphers provided here and utilize them via a uniform interface.

Several classes are provided for you to use but it will take some work to understand how to use them. Two of the encryption algorithms you will implement, the Caesar Cipher and the Vigenere Cipher, are very easy to understand and will provide an introduction to how inheritance works. The third cipher, MorseCipher, is different but we show how we can still fit it into our structure.

Object | +--Alphabet (finished) +--AlphabetException (finished) | | | +--BadIndexAlphabetException (finished) | | | +--MissingCharAlphabetException (finished) | +--Cipher (abstract) | +--MorseCipher | +--SymmetricCipher (abstract) (HELP !!!) | +--CaesarCipher | +--VigenereCipher 

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)

---------------------------------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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Logic In Databases International Workshop Lid 96 San Miniato Italy July 1 2 1996 Proceedings Lncs 1154

Authors: Dino Pedreschi ,Carlo Zaniolo

1st Edition

3540618147, 978-3540618140

More Books

Students also viewed these Databases questions