1.2 Cipher 1
1.2 Cipher 1
md 2023-11-24
Objective: The objective of this assignment is to develop a console-based application for encryption
and decryption using Java and object-oriented programming principles. The application should
include two different ciphers that both implement a common interface.
Task: You are tasked with building a Java program that can perform encryption and decryption using
two different ciphers. You only need to consider letters from A to Z (and a to z), that is you don't
need to handle ÅÄÖ or other non-English letters. The program should perform the following tasks:
1. Implement a common interface Cipher that includes methods for encrypting and decrypting
text.
2. Create a class ShiftCipher that implements the Cipher interface. This cipher should shift
each letter in the text by a fixed number of positions. If the shift number is 1, A becomes B and
Z becomes A.
3. Create a class ReplacementCipher that also implements the Cipher interface. This cipher
should replace each letter in the text with a corresponding replacement letter. If the
replacement letters are "BYZ...", the message "CBA" will be encypted to "ZYB". You need
replacement letters for all letters that your cipher should handle, which in this case is A to Z.
4. In the Main class, instantiate objects of both the cipher classes. These objects should be
initiated with a shift number and replacement letters respectively.
5. Use the objects to perform encryption and decryption operations on sample texts.
Example Output: Below is an example of the expected console output for your program:
Grading Criteria:
Properly implement the interface, the two cipher classes, and a Main class to test the ciphers.
Both ciphers correctly perform encryption and decryption operations.
The program produces output that displays the original, encrypted, and decrypted texts.
The main program should only use the individual cipher types at instantiation, after that the
interaction with these objects should use the Cipher interface.
1/2
1.2-cipher.md 2023-11-24
1. Allow user input for the text and cipher parameters (shift, replacement letters, etc.).
2. Implement additional ciphers, such as Vigenère Cipher or Playfair Cipher, using the same
interface.
Submission: Submit your Java source code files (.java) in CodeGrade with the right amount of
comments that explain your code. Follow the instructions on Canvas for CodeGrade submission.
Hints:
to build a string from characters, you could either use string concatenation with the plus sign,
as in "AB" + "BA". Or you could you the StringBuilder class which has a handy append(str)
method and a toString() method to convert it back to a string.
to get an array of all the characters inside a string, use str.toCharArray()
to get one character from a string, use str.charAt(pos)
to test individual characters for lowercase or uppercase, use Character.isUpperCase(ch) or
Character.isLowerCase(ch)
remember that characters are numbers and can be used for addition and subtraction
to get the index of a specified character in a string, use str.indexOf(ch)
2/2