Updating tests

This commit is contained in:
2023-05-05 20:19:27 -04:00
parent b3ca4754ea
commit 9c41f10576
45 changed files with 2729 additions and 2239 deletions

View File

@@ -1,7 +1,7 @@
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/polySubstitution/Hill.java
//Mattrixwv
// Created: 01-31-22
//Modified: 04-27-23
//Modified: 05-04-23
package com.mattrixwv.cipherstream.polysubstitution;
@@ -19,17 +19,19 @@ import com.mattrixwv.matrix.exceptions.InvalidScalarException;
public class Hill{
protected static Logger logger = LoggerFactory.getLogger(Hill.class);
private static final Logger logger = LoggerFactory.getLogger(Hill.class);
//Fields
protected String inputString; //The message that needs to be encoded/decoded
protected String outputString; //The encoded/decoded message
protected char characterToAdd; //The keyword used to create the grid
protected ModMatrix key; //The matrix used perform the encoding/decoding
//Settings
protected boolean preserveCapitals; //Persist capitals in the output string
protected boolean preserveWhitespace; //Persist whitespace in the output string
protected boolean preserveSymbols; //Persist symbols in the output string
protected boolean preserveCapitals;
protected boolean preserveWhitespace;
protected boolean preserveSymbols;
protected String inputString;
protected String outputString;
protected char characterToAdd;
protected ModMatrix key;
//Validate and set the key
protected void setKey(ModMatrix key) throws InvalidKeyException{
logger.debug("Setting key");
@@ -55,9 +57,10 @@ public class Hill{
}
//Set the key
logger.debug("key = {}", key);
logger.debug("key\n{}", key);
this.key = new ModMatrix(key);
}
//Validate and set the input string
protected void setInputStringEncode(String inputString) throws InvalidInputException{
logger.debug("Setting input string for encoding");
@@ -142,6 +145,7 @@ public class Hill{
throw new InvalidInputException("Length of input string must be a multiple of the number of rows in the key");
}
}
//Get a perfectly clean copy of input string
protected String getCleanInputString(){
logger.debug("Cleaning inputString");
@@ -150,6 +154,7 @@ public class Hill{
return cleanInputString;
}
//Validate and set character to add
protected void setCharacterToAdd(char characterToAdd) throws InvalidCharacterException{
logger.debug("Setting character to add {}", characterToAdd);
@@ -168,6 +173,7 @@ public class Hill{
logger.debug("Cleaned character {}", characterToAdd);
this.characterToAdd = characterToAdd;
}
//Add capitalization, whitespace, and symbols to the output based on the input
protected String polishOutputString(){
logger.debug("Polishing output string");
@@ -197,6 +203,7 @@ public class Hill{
logger.debug("Polished string '{}'", cleanString);
return cleanString;
}
//Get vectors representing the input string
protected ArrayList<ModMatrix> getInputVectors(){
logger.debug("Generating input vectors");
@@ -230,6 +237,7 @@ public class Hill{
//Return the array of vectors
return vectors;
}
//Get the string represented by the vectors that were passed in
protected String getOutputFromVectors(ArrayList<ModMatrix> outputVectors){
logger.debug("Turning vectors into a string");
@@ -249,6 +257,7 @@ public class Hill{
logger.debug("Converted string '{}'", convertedString);
return convertedString;
}
//Encode inputString and store the value in outputString
protected void encode(){
logger.debug("Encoding");
@@ -272,6 +281,7 @@ public class Hill{
//Add the extra characters back to the output and remove the added characters
outputString = polishOutputString();
}
//Decode inputString and store the value in outputString
protected void decode(){
logger.debug("Decoding");
@@ -298,6 +308,7 @@ public class Hill{
outputString = polishOutputString();
}
//Constructors
public Hill() throws InvalidCharacterException{
preserveCapitals = false;
preserveWhitespace = false;
@@ -320,6 +331,7 @@ public class Hill{
reset();
}
//Encode inputString using the provided key
public String encode(int[][] key, String inputString) throws InvalidKeyException, InvalidInputException{
return encode(new ModMatrix(key, 26), inputString);
}
@@ -329,6 +341,7 @@ public class Hill{
encode();
return outputString;
}
//Decode inputString using the provided key
public String decode(int[][] key, String inputString) throws InvalidKeyException, InvalidInputException{
return decode(new ModMatrix(key, 26), inputString);
}
@@ -338,6 +351,8 @@ public class Hill{
decode();
return outputString;
}
//Makes sure all variables are empty
public void reset(){
logger.debug("Resetting fields");
@@ -345,6 +360,8 @@ public class Hill{
outputString = "";
key = new ModMatrix(26);
}
//Getters
public String getInputString(){
return inputString;
}