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 Poly-alphabetic 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 90% 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 P2C and C2P (plain to cipher and cipher to plain)
private HashMap> P2C = new HashMap<>();
private HashMap> C2P = new HashMap<>();
public PolyAlphaCipher()
{
int size = poly.length;
for (int row =0; row < size; row++)
{
for (int col =0; col < size; col++)
System.out.print(poly[row][col]);
}
System.out.println();
}
System.out.println();
}
private void swapCol(char[][]alpha, int idx1, int idx2)
{
for (int i =0; i < alpha.length; i++)
{
char temp = alpha[i][idx1];
alpha[i][idx1]= alpha[idx2][i];
alpha[i][idx2]= temp;
}
}
private void swapRow(char[][]alpha, int idx1, int idx2)
{
char[] temp= alpha[idx1];
alpha[idx1]= alpha[idx2];
alpha[idx2]= temp;
}
public void generatePoly(Iterable alphas)
{
String alphabet = getAlphabet(alphas);
int size = alphabet.length();
char[] chars = alphabet.toCharArray();
for (int i = o i< size; i++)
{
P2C.put(chars[i, new HashMap<>]);
for (int j =0; j < size; j++)
{
P2C.get(chars[i]).put(chars[j],'a')
}
}
}
char[][] alphabets = new char[size][size];
for (int i =0; i < size; i++)
{
alphabets[i]= CaesarCipher.encrypt(alphabet, i, alphabet,false, false).toCharArray();
}
for (int i =0; i < Math.pow(size,2); i++)
{
int idx1= randInt(size);
int idx2= randInt(size);
while (idx1== idx2)
{
idx1= randInt(size);
idx2= randInt(size);
}
swapRow(alphabets, idx1, idx2);
}
for(int i =0; i < Math.pow(size,2); i++)
{
int idx1= randInt(size);
int idx2= randInt(size);
while (idx1== idx2)
{
idx1= randInt(size);
idx2= randInt(size);
}
swapCol(alphabets, idx1, idx2);
}
printPoly(alphabets);
for (int i =0; i < size; i++)
{
for (int j =0; j < size; j++)
{
char P = chars[i];
for (int j =0; j < size; j++)
{
char K = chars[j];
HashMap temp = P2C.get(P);
temp.put(K, alphabets,[i][j]);
P2C.get(P, temp);
}
}
System.out.println();
}
public String encrypt(String plainText, String key)
{
// TODO: Implement me!
return null;
}
public String decrypt(String cipherText, String key)
{
// TODO: Implement me!
return null;
}
public static void main(String[] args)
{
PolyAlphaCipher pac = new PolyAlphaCipher();
List alphabets = new ArrayList<>();
alphabets.add(lowerAlpha);
alphabets.add(upperAlpha);
alphabets.add(whitespace);
//alphabets.add(symbols);
//alphabets.add(punctuation);
//alphabets.add(numbers);
pac.generatePoly(alphabets);
}
}

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 Programming Questions!