Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Intro to Java Programming Please use source code from previous assignment. Source code from previous assignment below: import java.util.Scanner; public class ShiftCipher { static char[]

Intro to Java Programming

Please use source code from previous assignment.

image text in transcribed

Source code from previous assignment below:

import java.util.Scanner;

public class ShiftCipher {

static char[] shiftedAlphabet(int n) { final String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char alphabetArray[] = new char[26]; for (int i = 0; i

static String encrypt(String plainText, int n) { char newAlphabet[] = shiftedAlphabet(n); final String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; String cipherText = ""; for (int i = 0; i

static String decrypt(String cipherText, int n) { char newAlphabet[] = shiftedAlphabet(-n); final String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; String plainText = ""; for (int i = 0; i For this part, we will turn the code from the previous String lab (here is its solutioninto a class that we can use from other code. In fact, we will re-use this class in our programming.project. The program for this assignment will be called TestShiftCipher). It will contain a second java file with the class implementing the shift cipher. Since this is a multi-file project, hand in a .zip file of your project's src directory (src.zip -- zip the directory and not just the two files). Your class should meet the following requirements 1. Its name will be ShiftCipher 2. It will belong to the package edu.xxx) where xxx is your IU school as typically abbreviated. For me, the package is edu.ius 3. Its constructor will accept a single argument, the integer parameter n for the key of the cipher 4. The alphabet shifted by nwill be stored as an Array of char as an instance variable in the class. 5. An (encrypt method that takes a String plaintext as an argument and returns a String ciphertext (plainText shifted by n ). Notice how n doesn't have to be an argument to this method since it is part of the class. In the previous lab we had to provide n as a parameter. It's stored now in the class as an instance variable named key 6. A decrypt method that takes a (String ciphertext as an argument and returns a String of plaintext (cipherText shifted by -n). Once again, n, does not need to be an argument to this method Finally, program the static main method of TestShiftCipher to demonstrate your Shiftcipher class works by allowing the user to enter a message (that is converted to upper case) and a key. TestshiftCipher) should print the (ciphertext and verify that the decrypted (ciphertext recovers the plaintext Please enter a plain text message for encryption: informatics Please enter the shift value (key) for the cipher: 3 The ciphertext is: LQIRUPDWLFV To verify, the decrypted encrypted text is below: INFORMATICS

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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions