Playfair started
This commit is contained in:
156
src/main/java/mattrixwv/CipherStreamJava/Playfair.java
Normal file
156
src/main/java/mattrixwv/CipherStreamJava/Playfair.java
Normal file
@@ -0,0 +1,156 @@
|
||||
//CipherStreamJava/src/main/java/mattrixwv/CipherStreamJava/Playfair.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-30-21
|
||||
//Modified: 07-30-21
|
||||
//This is the declaration of the Playfair class
|
||||
package mattrixwv.CipherStreamJava;
|
||||
|
||||
|
||||
public class Playfair{
|
||||
//Classes to help with error handling
|
||||
private class LetterNotFound{
|
||||
private char letter;
|
||||
public LetterNotFound(char letter){
|
||||
this.letter = letter;
|
||||
}
|
||||
public char getLetter(){
|
||||
return letter;
|
||||
}
|
||||
}
|
||||
public class InvalidGrid{
|
||||
private String type;
|
||||
private int size;
|
||||
public InvalidGrid(String type, int size){
|
||||
this.type = type;
|
||||
this.size = size;
|
||||
}
|
||||
public String getType(){
|
||||
return type;
|
||||
}
|
||||
public int getSize(){
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
//Variables
|
||||
private char replaced; //The letter that will need to be replaced in the grid and any input string or keyword
|
||||
private char replacer; //The letter that replaced replaced in the input string or keyword
|
||||
private char doubled; //The letter that will be placed between double letters in the input string if necessary or to make the string length even
|
||||
private String inputString; //The message that needs to be encoded/decoded
|
||||
private String outputString; //The encoded/decoded message
|
||||
private String keyword; //The keyword used to create the grid
|
||||
private char[][] grid; //The grid used to encoded/decode the message
|
||||
//Create the grid from the keyword
|
||||
private void createGrid(){
|
||||
int row = 0;
|
||||
int column = 0;
|
||||
boolean found = false;
|
||||
|
||||
//Add any new letters from the keyword to the grid
|
||||
//If you reach row 5 then the entire grid has been filled
|
||||
char current = '\0';
|
||||
for(int cnt = 0;(cnt < keyword.length()) && (row < 5);++cnt){
|
||||
current = keyword.charAt(cnt);
|
||||
//If the current letter needs to be replaced, do so
|
||||
if(current == replaced){
|
||||
current = replacer;
|
||||
}
|
||||
|
||||
//Search the grid for the current letter
|
||||
found = checkGrid(current);
|
||||
|
||||
//If the letter is not in the grid add it
|
||||
if(!found){
|
||||
grid[row][column] = keyword.charAt(cnt);
|
||||
++column;
|
||||
//If the column number is too high reset it and advance the row
|
||||
if(column >= 5){
|
||||
column = 0;
|
||||
++row;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//Returns true if the letter is found in the grid
|
||||
private boolean checkGrid(char letter){
|
||||
//TODO:
|
||||
return true;
|
||||
}
|
||||
//Searches the grid for letter and sets row & col to its location in grid
|
||||
//TODO: This needs to be reworked
|
||||
private void searchGrid(char letter, int row, int col){
|
||||
//TODO:
|
||||
}
|
||||
//Strips invalid characters from the string that needs encoded/decoded
|
||||
private void setInputString(String input){
|
||||
//TODO:
|
||||
}
|
||||
//Strips invalid character from the keyword and creates the grid
|
||||
private void setKeyword(String key){
|
||||
//TODO:
|
||||
}
|
||||
//Encoded inputString using the Playfair cipher and stores the result in outputString
|
||||
private String encode(){
|
||||
//TODO:
|
||||
return null;
|
||||
}
|
||||
//Decodes inputString using the Playfair cipher and stores the result in outputString
|
||||
private String decode(){
|
||||
//TODO:
|
||||
return null;
|
||||
}
|
||||
|
||||
public Playfair(){
|
||||
reset();
|
||||
replaced = 'J';
|
||||
replacer = 'I';
|
||||
doubled = 'X';
|
||||
}
|
||||
//Sets the keyword and inputString and encodes the message
|
||||
public String encode(String keyword, String input){
|
||||
//TODO:
|
||||
return null;
|
||||
}
|
||||
//Sets the keyword and inputString and decodes the message
|
||||
public String decode(String keyword, String input){
|
||||
//TODO:
|
||||
return null;
|
||||
}
|
||||
|
||||
//Makes sure all variables are empty
|
||||
public void reset(){
|
||||
//TODO:
|
||||
}
|
||||
//Gets
|
||||
public char getReplaced(){
|
||||
return replaced;
|
||||
}
|
||||
public void setReplaced(char replaced){
|
||||
//TODO:
|
||||
}
|
||||
public char getReplacer(){
|
||||
return replacer;
|
||||
}
|
||||
public void setReplacer(char replacer){
|
||||
//TODO:
|
||||
}
|
||||
public char getDoubled(){
|
||||
return doubled;
|
||||
}
|
||||
public void setDoubled(char doubled){
|
||||
//TODO:
|
||||
}
|
||||
public String getKeyword(){
|
||||
return keyword;
|
||||
}
|
||||
public String getInputString(){
|
||||
return inputString;
|
||||
}
|
||||
public String getOutputString(){
|
||||
return outputString;
|
||||
}
|
||||
public String getGrid(){
|
||||
//TODO:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user