Question: Complete the Poly - alphabetic cipher class within the provided code. The class must be capable of both encrypting and decrypting a plain text into
Complete the Polyalphabetic cipher class within the provided code.
The class must be capable of both encrypting and decrypting a plain text into a cipher text and back when the same key is passed to the encrypt and decrypt methods. Furthermore, the code must accept alphabets up to the lowercase, uppercase, and whitespace space and tab characters as valid elements of the Polybius square.I can't really determine if a given ciphertext is "correct" without being able to decrypt it back to the plaintext, so no partial credit. Your code must compile and run without throwing exceptions. Submitted code which does not compile or crashes due to any foreseeable error condition will receive a grade of zero. Here is the code we worked in class, i Just want to finish this code, he says its basivally done.
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.awt.Point;
public class PolyAlphaCipher extends Cipher
TODO: Create some data structure that stores the Polybius square
for each instance of the class
A pair of HashMap is the best solution
as you can create one for the plaintext key ciphertext
lookup and another for the cipher key plain lookup
I called mine PC and CP plain to cipher and cipher to plain
private HashMap PC new HashMap;
private HashMap CP new HashMap;
public PolyAlphaCipher
int size poly.length;
for int row ; row size; row
for int col ; col size; col
System.out.printpolyrowcol;
System.out.println;
System.out.println;
private void swapColcharalpha int idx int idx
for int i ; i alpha.length; i
char temp alphaiidx;
alphaiidx alphaidxi;
alphaiidx temp;
private void swapRowcharalpha int idx int idx
char temp alphaidx;
alphaidx alphaidx;
alphaidx temp;
public void generatePolyIterable alphas
String alphabet getAlphabetalphas;
int size alphabet.length;
char chars alphabet.toCharArray;
for int i o i size; i
PCputcharsi new HashMap;
for int j ; j size; j
PCgetcharsiputcharsja
char alphabets new charsizesize;
for int i ; i size; i
alphabetsi CaesarCipher.encryptalphabet i alphabet,false, falsetoCharArray;
for int i ; i Math.powsize; i
int idx randIntsize;
int idx randIntsize;
while idx idx
idx randIntsize;
idx randIntsize;
swapRowalphabets idx idx;
forint i ; i Math.powsize; i
int idx randIntsize;
int idx randIntsize;
while idx idx
idx randIntsize;
idx randIntsize;
swapColalphabets idx idx;
printPolyalphabets;
for int i ; i size; i
for int j ; j size; j
char P charsi;
for int j ; j size; j
char K charsj;
HashMap temp PCgetP;
temp.putK alphabets,ij;
PCgetP temp;
System.out.println;
public String encryptString plainText, String key
TODO: Implement me
return null;
public String decryptString cipherText, String key
TODO: Implement me
return null;
public static void mainString args
PolyAlphaCipher pac new PolyAlphaCipher;
List alphabets new ArrayList;
alphabets.addlowerAlpha;
alphabets.addupperAlpha;
alphabets.addwhitespace;
alphabetsaddsymbols;
alphabetsaddpunctuation;
alphabetsaddnumbers;
pac.generatePolyalphabets;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
