Updated test coverage

This commit is contained in:
2023-04-17 01:17:59 -04:00
parent 575ff04ecd
commit 494293c311
22 changed files with 2479 additions and 2970 deletions

View File

@@ -1,7 +1,7 @@
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/combination/ADFGVX.java
//Mattrixwv
// Created: 01-26-22
//Modified: 07-09-22
//Modified: 04-14-23
package com.mattrixwv.cipherstream.combination;
@@ -18,11 +18,11 @@ import com.mattrixwv.cipherstream.polysubstitution.PolybiusSquare;
public class ADFGVX{
private static final Logger logger = LoggerFactory.getLogger(ADFGVX.class);
protected static Logger logger = LoggerFactory.getLogger(ADFGVX.class);
//Internal classes
private class LargePolybiusSquare extends PolybiusSquare{
private static final Logger logger = LoggerFactory.getLogger(LargePolybiusSquare.class);
protected class LargePolybiusSquare extends PolybiusSquare{
protected static final Logger logger = LoggerFactory.getLogger(LargePolybiusSquare.class);
@Override
protected void createGrid(){
@@ -183,38 +183,38 @@ public class ADFGVX{
}
}
//Fields
private boolean preserveCapitals; //Whether to respect capitals in the output string
private boolean preserveWhitespace; //Whether to respect whitespace in the output string
private boolean preserveSymbols; //Whether to respect symbols in the output string
private String inputString; //The string that needs encoded/decoded
private String outputString; //The string that is output after encoding/decoding
private String squareKeyword; //The keyword used in the Polybius Square
private String keyword; //The Keyword used in the Columnar cipher
protected boolean preserveCapitals; //Whether to respect capitals in the output string
protected boolean preserveWhitespace; //Whether to respect whitespace in the output string
protected boolean preserveSymbols; //Whether to respect symbols in the output string
protected String inputString; //The string that needs encoded/decoded
protected String outputString; //The string that is output after encoding/decoding
protected String squareKeyword; //The keyword used in the Polybius Square
protected String keyword; //The Keyword used in the Columnar cipher
//Internal ciphers
private LargePolybiusSquare largePolybiusSquare; //The first step in encoding
private Columnar columnar; //The second step in encoding
protected LargePolybiusSquare largePolybiusSquare; //The first step in encoding
protected Columnar columnar; //The second step in encoding
//Ensures Polybius keyword constraints
private void setSquareKeyword(String squareKeyword) throws InvalidKeywordException{
protected void setSquareKeyword(String squareKeyword) throws InvalidKeywordException{
if(squareKeyword == null){
throw new InvalidKeywordException("Square Keyword cannot be null");
}
logger.debug("Square Keyword '{}'", squareKeyword);
logger.debug("squareKeyword = {}", squareKeyword);
this.squareKeyword = squareKeyword;
}
//Ensures Columnar keyword constraints
private void setKeyword(String keyword) throws InvalidKeywordException{
protected void setKeyword(String keyword) throws InvalidKeywordException{
if(keyword == null){
throw new InvalidKeywordException("Keyword cannot be null");
}
logger.debug("Keyword '{}'", keyword);
logger.debug("keyword = {}", keyword);
this.keyword = keyword;
}
//Ensures inputString constraints
private void setInputString(String inputString) throws InvalidInputException{
protected void setInputString(String inputString) throws InvalidInputException{
if(inputString == null){
throw new InvalidInputException("Input cannot be null");
}
@@ -246,31 +246,37 @@ public class ADFGVX{
}
}
//Format the output string with capitals, symbols, and numbers that are in the input string
private void formatOutputStringEncode(){
logger.debug("Formatting output string");
protected void formatOutputStringEncode(){
logger.debug("Formatting output string to match input string");
StringBuilder output = new StringBuilder();
int outputLocation = 0;
for(char ch : inputString.toCharArray()){
logger.debug("Input string {}", ch);
logger.debug("Input character {}", ch);
if(Character.isUpperCase(ch)){
logger.debug("Converting output to uppercase");
output.append(Character.toUpperCase(outputString.charAt(outputLocation++)));
output.append(Character.toUpperCase(outputString.charAt(outputLocation++)));
}
else if(Character.isLowerCase(ch)){
logger.debug("Converting output to lowercase");
output.append(Character.toLowerCase(outputString.charAt(outputLocation++)));
output.append(Character.toLowerCase(outputString.charAt(outputLocation++)));
}
else{
logger.debug("Appending symbol to output");
output.append(ch);
}
}
logger.debug("Saving output string '{}'", output);
outputString = output.toString();
logger.debug("Saving output string '{}'", outputString);
}
private void formatOutputStringDecode(){
logger.debug("Formatting output string");
protected void formatOutputStringDecode(){
logger.debug("Formatting output string to match input string");
StringBuilder output = new StringBuilder();
int outputLocation = 0;
@@ -278,23 +284,29 @@ public class ADFGVX{
char ch = inputString.charAt(inputLocation);
logger.debug("Input character {}", ch);
if(Character.isUpperCase(ch)){
logger.debug("Converting output to uppercase");
output.append(Character.toUpperCase(outputString.charAt(outputLocation++)));
++inputLocation;
}
else if(Character.isLowerCase(ch)){
logger.debug("Converting output to lowercase");
output.append(Character.toLowerCase(outputString.charAt(outputLocation++)));
++inputLocation;
}
else{
logger.debug("Appending symbol to output");
output.append(ch);
}
}
logger.debug("Saving output string '{}'", output);
outputString = output.toString();
logger.debug("Saving output string '{}'", outputString);
}
//Encodes the inputString and stores the result in outputString
private String encode() throws InvalidCharacterException, InvalidInputException, InvalidKeywordException{
protected String encode() throws InvalidCharacterException, InvalidInputException, InvalidKeywordException{
//Encode the input with polybius
logger.debug("Encoding using Polybius Square");
String polybiusOutput = largePolybiusSquare.encode(squareKeyword, inputString);
@@ -303,7 +315,7 @@ public class ADFGVX{
polybiusOutput = polybiusOutput.replace("1", "A").replace("2", "D").replace("3", "F").replace("4", "G").replace("5", "V").replace("6", "X");
//Encode polybius's output with columnar
logger.debug("Encoding with columnar");
logger.debug("Encoding using columnar");
String columnarOutput = columnar.encode(keyword, polybiusOutput);
outputString = columnarOutput;
@@ -313,16 +325,16 @@ public class ADFGVX{
return outputString;
}
//Decodes the inputString and stores the result in outputString
private String decode() throws InvalidKeywordException, InvalidCharacterException, InvalidInputException{
protected String decode() throws InvalidKeywordException, InvalidCharacterException, InvalidInputException{
//Decode the input with columnar
logger.debug("Decoding columnar");
logger.debug("Decoding using columnar");
String columnarOutput = columnar.decode(keyword, inputString);
//Change the symbols to the correct ones for polybius
logger.debug("Replacing characters with coordinates");
logger.debug("Replacing letters with coordinates");
columnarOutput = columnarOutput.replace("A", "1").replace("D", "2").replace("F", "3").replace("G", "4").replace("V", "5").replace("X", "6");
//Decode with polybius
logger.debug("Decoding Polybius Square");
logger.debug("Decoding using Polybius Square");
String polybiusOutput = largePolybiusSquare.decode(squareKeyword, columnarOutput);
outputString = polybiusOutput;
@@ -380,7 +392,7 @@ public class ADFGVX{
}
//Makes sure all of the variables are empty
public void reset() throws InvalidCharacterException{
logger.debug("Reseting fields");
logger.debug("Resetting fields");
largePolybiusSquare = new LargePolybiusSquare(false, false);
columnar = new Columnar(false, false, false, true, 'B');

View File

@@ -1,7 +1,7 @@
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/combination/ADFGX.java
//Mattrixwv
// Created: 01-25-22
//Modified: 07-09-22
//Modified: 04-14-23
package com.mattrixwv.cipherstream.combination;
@@ -55,7 +55,7 @@ public class ADFGX{
throw new InvalidInputException("Input cannot be null");
}
logger.debug("original input string '{}'", inputString);
logger.debug("Original input string '{}'", inputString);
if(!preserveCapitals){
logger.debug("Removing capitals");
@@ -77,7 +77,7 @@ public class ADFGX{
if(this.inputString.isBlank()){
throw new InvalidInputException("Input cannot be blank");
}
logger.debug("cleaned input string '{}'", inputString);
logger.debug("Cleaned input string '{}'", inputString);
}
//Format the output string with capitals, symbols, and numbers that are in the input string
protected void formatOutputStringEncode(){
@@ -106,8 +106,8 @@ public class ADFGX{
}
}
logger.debug("Saving output string '{}'", outputString);
outputString = output.toString();
logger.debug("Saving output string '{}'", outputString);
}
protected void formatOutputStringDecode(){
logger.debug("Formatting output string to match input string");
@@ -135,8 +135,8 @@ public class ADFGX{
}
}
logger.debug("Saving output string '{}'", output);
outputString = output.toString();
logger.debug("Saving output string '{}'", outputString);
}
//Encodes the inputString and stores the result in outputString
protected void encode() throws InvalidCharacterException, InvalidInputException, InvalidKeywordException{

View File

@@ -1,7 +1,7 @@
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/polySubstitution/Affine.java
//Mattrixwv
// Created: 01-26-22
//Modified: 07-09-22
//Modified: 04-15-23
package com.mattrixwv.cipherstream.monosubstitution;
@@ -15,24 +15,26 @@ import com.mattrixwv.NumberAlgorithms;
public class Affine{
private static final Logger logger = LoggerFactory.getLogger(Affine.class);
protected static Logger logger = LoggerFactory.getLogger(Affine.class);
//Fields
private boolean preserveCapitals; //Whether to respect capitals in the output string
private boolean preserveSymbols; //Whether to respect symbols in the output string
private boolean preserveWhitespace; //Whether to respect whitespace in the output string
private String inputString; //The string that needs encoded/decoded
private String outputString; //The string that is output after encoding/decoding
private int key1; //The multiplicative key. Key1 must be relatively prime to 26
private int key2; //The additive key
protected boolean preserveCapitals; //Whether to respect capitals in the output string
protected boolean preserveSymbols; //Whether to respect symbols in the output string
protected boolean preserveWhitespace; //Whether to respect whitespace in the output string
protected String inputString; //The string that needs encoded/decoded
protected String outputString; //The string that is output after encoding/decoding
protected int key1; //The multiplicative key. Key1 must be relatively prime to 26
protected int key2; //The additive key
//Ensures key1 constraints
private void setKey1(int key1) throws InvalidKeywordException{
protected void setKey1(int key1) throws InvalidKeywordException{
logger.debug("Setting key1 {}", key1);
//Mod 26 to ensure no overflow
key1 %= 26;
//If the key is negative change it to possitive
if(key1 < 0){
key1 %= 26;
key1 += 26;
}
@@ -47,12 +49,14 @@ public class Affine{
logger.debug("Cleaned key1 {}", key1);
}
//Ensures key2 constraints
private void setKey2(int key2){
protected void setKey2(int key2){
logger.debug("Setting key2 {}", key2);
//Mod 26 to ensure no overflow
key2 %= 26;
//If the key is negative change it to possitive
if(key2 < 0){
key2 %= 26;
key2 += 26;
}
@@ -62,7 +66,7 @@ public class Affine{
logger.debug("Cleaned key2 {}", key2);
}
//Ensures inputString constraints
private void setInputString(String inputString) throws InvalidInputException{
protected void setInputString(String inputString) throws InvalidInputException{
if(inputString == null){
throw new InvalidInputException("Input must not be null");
}
@@ -94,7 +98,7 @@ public class Affine{
}
}
//Encodes the inputString and stores the result in outputString
private String encode(){
protected void encode(){
logger.debug("Encoding");
//Step through every character in the input and encode it if needed
@@ -108,7 +112,7 @@ public class Affine{
//Encode the number
letter = ((key1 * letter) + key2) % 26;
//Change the new number back to a character and append it to the output
char newChar = (char)(letter + 65);
char newChar = (char)(letter + 'A');
output.append(newChar);
logger.debug("Encoded char {}", newChar);
@@ -119,7 +123,7 @@ public class Affine{
//Encode the number
letter = ((key1 * letter) + key2) % 26;
//Change the new number back to a character and append it to the output
char newChar = (char)(letter + 97);
char newChar = (char)(letter + 'a');
output.append(newChar);
logger.debug("Encoded char {}", newChar);
@@ -131,12 +135,11 @@ public class Affine{
}
//Save and return the output
logger.debug("Saving output string '{}'", output);
outputString = output.toString();
return outputString;
logger.debug("Saving output string '{}'", outputString);
}
//Decodes the inputString and stores the result in outputString
private String decode(){
protected void decode(){
logger.debug("Decoding");
//Find the multiplicative inverse of key1
@@ -186,9 +189,8 @@ public class Affine{
}
//Save and return the output
logger.debug("Saving output string '{}'", output);
outputString = output.toString();
return outputString;
logger.debug("Saving output string '{}'", outputString);
}
@@ -211,14 +213,16 @@ public class Affine{
setKey1(key1);
setKey2(key2);
setInputString(inputString);
return encode();
encode();
return outputString;
}
//Decodes inputString using key1 and key2 and returns the result
public String decode(int key1, int key2, String inputString) throws InvalidKeywordException, InvalidInputException{
setKey1(key1);
setKey2(key2);
setInputString(inputString);
return decode();
decode();
return outputString;
}
//Returns the cleaned inputString

View File

@@ -1,7 +1,7 @@
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/Atbash.java
//Mattrixwv
// Created: 07-25-21
//Modified: 07-09-22
//Modified: 04-15-23
package com.mattrixwv.cipherstream.monosubstitution;
@@ -12,17 +12,17 @@ import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
public class Atbash{
private static final Logger logger = LoggerFactory.getLogger(Atbash.class);
protected static Logger logger = LoggerFactory.getLogger(Atbash.class);
private String inputString; //Holds the string that needs encoded or decoded
private String outputString; //The encoded/decoded string
private boolean preserveCapitals; //Whether to respect capitals in the output string
private boolean preserveWhitespace; //Whether to respect whitespace in the output string
private boolean preserveSymbols; //Whether to respect symbols in the output string
protected String inputString; //Holds the string that needs encoded or decoded
protected String outputString; //The encoded/decoded string
protected boolean preserveCapitals; //Whether to respect capitals in the output string
protected boolean preserveWhitespace; //Whether to respect whitespace in the output string
protected boolean preserveSymbols; //Whether to respect symbols in the output string
//Encodes inputString and stores in outputString
private String encode(){
protected String encode(){
logger.debug("Encoding");
StringBuilder output = new StringBuilder();
//Step through every element in the inputString and shift it the correct amount
@@ -52,9 +52,9 @@ public class Atbash{
return outputString;
}
//Removes all invalid characters and sets inputString
private void setInputString(String inputString) throws InvalidInputException{
protected void setInputString(String inputString) throws InvalidInputException{
if(inputString == null){
throw new NullPointerException("Input cannot be null");
throw new InvalidInputException("Input cannot be null");
}
logger.debug("Original input string '{}'", inputString);

View File

@@ -1,7 +1,7 @@
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/Autokey.java
//Mattrixwv
// Created: 07-25-21
//Modified: 07-09-22
//Modified: 04-15-23
package com.mattrixwv.cipherstream.monosubstitution;
@@ -13,10 +13,10 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
public class Autokey extends Vigenere{
private static final Logger logger = LoggerFactory.getLogger(Autokey.class);
protected static Logger logger = LoggerFactory.getLogger(Autokey.class);
//Special rules for setting the strings for encoding
private void encodeSet(String keyword, String inputString) throws InvalidKeywordException, InvalidInputException{
protected void encodeSet(String keyword, String inputString) throws InvalidKeywordException, InvalidInputException{
logger.debug("Setting fields for encoding");
//Set the input
@@ -44,7 +44,7 @@ public class Autokey extends Vigenere{
setOffset();
}
//Setting the strings for decoding
private void decodeSet(String keyword, String inputString) throws InvalidKeywordException, InvalidInputException{
protected void decodeSet(String keyword, String inputString) throws InvalidKeywordException, InvalidInputException{
logger.debug("Setting fields for decoding");
//Remove all unneccessary elements from the key
@@ -88,11 +88,6 @@ public class Autokey extends Vigenere{
letter += 26;
}
else if(letter > 'Z'){
logger.debug("Wrapping around to A");
letter -= 26;
}
}
else if(Character.isLowerCase(letter)){
logger.debug("Appending lowercase");
@@ -103,11 +98,6 @@ public class Autokey extends Vigenere{
letter += 26;
}
else if(letter > 'z'){
logger.debug("Wrapping around to a");
letter -= 26;
}
}
logger.debug("Decoded letter {}", letter);
@@ -117,8 +107,8 @@ public class Autokey extends Vigenere{
fullOutput.append(currentOutput);
//Save and return the results
logger.debug("Saving output string '{}'", fullOutput);
outputString = fullOutput.toString();
logger.debug("Saving output string '{}'", outputString);
return outputString;
}

View File

@@ -1,7 +1,7 @@
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/Baconian.java
//Mattrixwv
// Created: 01-12-22
//Modified: 07-09-22
//Modified: 04-15-23
package com.mattrixwv.cipherstream.monosubstitution;
@@ -17,21 +17,21 @@ import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
public class Baconian{
private static final Logger logger = LoggerFactory.getLogger(Baconian.class);
protected static Logger logger = LoggerFactory.getLogger(Baconian.class);
//Conversions
private static final ArrayList<String> code = new ArrayList<>(Arrays.asList(
protected static final ArrayList<String> code = new ArrayList<>(Arrays.asList(
"aaaaa", "aaaab", "aaaba", "aaabb", "aabaa", "aabab", "aabba","aabbb", "abaaa", "abaaa", "abaab", "ababa", "ababb", //A-M
"abbaa", "abbab", "abbba", "abbbb", "baaaa", "baaab", "baaba", "baabb", "baabb", "babaa", "babab", "babba", "babbb" //N-Z
));
private String inputString; //The string that needs encoded/decoded
private String outputString; //The encoded/decoded string
private boolean preserveCapitals; //Whether to respect capitals in the output string
protected String inputString; //The string that needs encoded/decoded
protected String outputString; //The encoded/decoded string
protected boolean preserveCapitals; //Whether to respect capitals in the output string
//Sets the input string
private void setInputStringEncode(String inputString) throws InvalidInputException{
protected void setInputStringEncode(String inputString) throws InvalidInputException{
if(inputString == null){
throw new NullPointerException("Input cannot be null");
throw new InvalidInputException("Input cannot be null");
}
logger.debug("Setting input string for encoding '{}'", inputString);
@@ -52,9 +52,12 @@ public class Baconian{
throw new InvalidInputException("Input must contain at least 1 letter");
}
}
private void setInputStringDecode(String inputString) throws InvalidCharacterException, InvalidInputException{
protected void setInputStringDecode(String inputString) throws InvalidCharacterException, InvalidInputException{
if(inputString == null){
throw new NullPointerException("Input cannot be null");
throw new InvalidInputException("Input cannot be null");
}
else if(inputString.isBlank()){
throw new InvalidInputException("Input cannot be empty");
}
logger.debug("Setting input string for decoding '{}'", inputString);
@@ -86,13 +89,9 @@ public class Baconian{
this.inputString = inputString;
logger.debug("Cleaned input string '{}'", inputString);
if(this.inputString.isBlank()){
throw new InvalidInputException("Input cannot be empty");
}
}
//Encodes the inputString and stores the result in outputString
private String encode(){
protected void encode(){
logger.debug("Encoding");
StringJoiner output = new StringJoiner(" ");
//Go through every character in the inputString and encode it
@@ -113,17 +112,16 @@ public class Baconian{
}
//Add the encoded character to the output
logger.debug("Output 'letter' {}", binary);
logger.debug("Output letter {}", binary);
output.add(binary);
}
//Save and return the output
logger.debug("Saving output string '{}'", output);
outputString = output.toString();
return outputString;
logger.debug("Saving output string '{}'", outputString);
}
//Decodes the inputString and stores the result in outputString
private String decode(){
protected String decode(){
logger.debug("Decoding");
StringBuilder output = new StringBuilder();
@@ -154,8 +152,8 @@ public class Baconian{
}
//Save and return the output
logger.debug("Saving output string '{}'", output);
outputString = output.toString();
logger.debug("Saving output string '{}'", outputString);
return outputString;
}
@@ -180,7 +178,8 @@ public class Baconian{
public String encode(String inputString) throws InvalidInputException{
reset();
setInputStringEncode(inputString);
return encode();
encode();
return outputString;
}
//Sets the inputString and decodes the message
public String decode(String inputString) throws InvalidCharacterException, InvalidInputException{

View File

@@ -1,7 +1,7 @@
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/BaseX.java
//Mattrixwv
// Created: 01-08-22
//Modified: 07-09-22
//Modified: 04-16-23
package com.mattrixwv.cipherstream.monosubstitution;
@@ -16,16 +16,16 @@ import com.mattrixwv.cipherstream.exceptions.InvalidBaseException;
public class BaseX{
private static final Logger logger = LoggerFactory.getLogger(BaseX.class);
protected static Logger logger = LoggerFactory.getLogger(BaseX.class);
private String inputString; //The string that needs encoded/decoded
private String outputString; //The encoded/decoded string
private int base; //The base that the number will be encoded at
protected String inputString; //The string that needs encoded/decoded
protected String outputString; //The encoded/decoded string
protected int base; //The base that the number will be encoded at
//Sets the input string
private void setInputStringEncode(String inputString) throws InvalidInputException{
protected void setInputStringEncode(String inputString) throws InvalidInputException{
if(inputString == null){
throw new NullPointerException("Input cannot be null");
throw new InvalidInputException("Input cannot be null");
}
logger.debug("Setting input string for encoding '{}'", inputString);
@@ -36,9 +36,9 @@ public class BaseX{
throw new InvalidInputException("Input must contain at least 1 letter");
}
}
private void setInputStringDecode(String inputString) throws InvalidCharacterException, InvalidInputException{
protected void setInputStringDecode(String inputString) throws InvalidCharacterException, InvalidInputException{
if(inputString == null){
throw new NullPointerException("Input cannot be null");
throw new InvalidInputException("Input cannot be null");
}
logger.debug("Setting input string for decoding '{}'", inputString);
@@ -67,9 +67,12 @@ public class BaseX{
}
}
//Sets the numeric base
private void setBase(int base) throws InvalidBaseException{
if(base <= 0){
throw new InvalidBaseException("Base cannot be a negative number");
protected void setBase(int base) throws InvalidBaseException{
if(base < Character.MIN_RADIX){
throw new InvalidBaseException("Base cannot be less than " + Character.MIN_RADIX);
}
else if(base > Character.MAX_RADIX){
throw new InvalidBaseException("Base cannot be larger than " + Character.MAX_RADIX);
}
logger.debug("Setting base {}", base);
@@ -77,7 +80,7 @@ public class BaseX{
this.base = base;
}
//Encode inputString, store it in outputString, and return it
private String encode(){
protected String encode(){
logger.debug("Encoding");
//Encode every character in inputString
@@ -101,7 +104,7 @@ public class BaseX{
return outputString;
}
//Decode inputString, store it in outputString, and return it
private String decode() throws InvalidCharacterException{
protected String decode() throws InvalidCharacterException{
logger.debug("Decoding");
//Decode every binary number in the string
@@ -114,8 +117,8 @@ public class BaseX{
logger.debug("Decoded number {}", num);
//Make sure it is in a valid range
if((num < 0) && (num > 255)){
throw new InvalidCharacterException("The base" + base + " string '" + baseXString + "' is not a valid character");
if((num < 0) || (num > 255)){
throw new InvalidCharacterException("The base" + base + " string '" + baseXString + "' is not a valid ASCII character");
}
//Convert the int to a char and save it
@@ -123,8 +126,8 @@ public class BaseX{
}
//Save the output
logger.debug("Saving output string '{}'", output);
outputString = output.toString();
logger.debug("Saving output string '{}'", outputString);
//Return the output
return outputString;

View File

@@ -1,7 +1,7 @@
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/Beaufort.java
//Mattrixwv
// Created: 02-23-22
//Modified: 07-09-22
//Modified: 04-16-23
package com.mattrixwv.cipherstream.monosubstitution;
@@ -13,19 +13,19 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
public class Beaufort{
private static final Logger logger = LoggerFactory.getLogger(Beaufort.class);
protected static Logger logger = LoggerFactory.getLogger(Beaufort.class);
//Fields
private String inputString; //This is the string that needs encoded/decoded
private String outputString; //This is the string that is output after encoding/decoding
private String keyword; //This is the keyword that is responsible for determining the offsets that you change each character by
private boolean preserveCapitals; //Whether to respect capitals in the output string
private boolean preserveWhitespace; //Whether to respect whitespace in the output string
private boolean preserveSymbols; //Whether to respect symbols in the output string
protected String inputString; //This is the string that needs encoded/decoded
protected String outputString; //This is the string that is output after encoding/decoding
protected String keyword; //This is the keyword that is responsible for determining the offsets that you change each character by
protected boolean preserveCapitals; //Whether to respect capitals in the output string
protected boolean preserveWhitespace; //Whether to respect whitespace in the output string
protected boolean preserveSymbols; //Whether to respect symbols in the output string
//Internal ciphers
private Atbash atbash; //The first step in encoding/decoding the cipher
private Caesar caesar; //The second step in encoding/decoding the cipher
private Vigenere vigenere; //The third step in encoding/decoding the cipher
protected Atbash atbash; //The first step in encoding/decoding the cipher
protected Caesar caesar; //The second step in encoding/decoding the cipher
protected Vigenere vigenere; //The third step in encoding/decoding the cipher
//Ensures inputString constraints
public void setInputString(String inputString) throws InvalidInputException{
@@ -88,9 +88,20 @@ public class Beaufort{
}
}
//Encodes the inputString and stores the result in outputString
public void encode() throws InvalidKeywordException, InvalidInputException{
protected void encode() throws InvalidKeywordException, InvalidInputException{
logger.debug("Encoding");
code();
}
//Decodes the inputString and stores the result in outputString
protected void decode() throws InvalidKeywordException, InvalidInputException{
logger.debug("Decoding");
//Decoding is just encoding again
code();
}
//Codes input and saves to output
protected void code(){
//Reverse the string
logger.debug("Encoding with Atbash");
String atbashString = atbash.encode(inputString);
@@ -106,13 +117,6 @@ public class Beaufort{
logger.debug("Saving output string '{}'", vigenereString);
this.outputString = vigenereString;
}
//Decodes the inputString and stores the result in outputString
public void decode() throws InvalidKeywordException, InvalidInputException{
logger.debug("Decoding");
//Decoding is just encoding again
encode();
}
//Constructor

View File

@@ -1,7 +1,7 @@
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/Caesar.java
//Matthew Ellison
// Created: 07-25-21
//Modified: 07-09-22
//Modified: 04-16-23
package com.mattrixwv.cipherstream.monosubstitution;
@@ -12,18 +12,18 @@ import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
public class Caesar{
private static final Logger logger = LoggerFactory.getLogger(Caesar.class);
protected static Logger logger = LoggerFactory.getLogger(Caesar.class);
//Fields
private String inputString; //The string that needs encoded/decoded
private String outputString; //The encoded/decoded string
private int shift; //The amount that you need to shift each letter
private boolean preserveCapitals; //Whether to respect capitals in the output string
private boolean preserveWhitespace; //Whether to respect whitespace in the output string
private boolean preserveSymbols; //Whether to respect symbols in the output string
protected String inputString; //The string that needs encoded/decoded
protected String outputString; //The encoded/decoded string
protected int shift; //The amount that you need to shift each letter
protected boolean preserveCapitals; //Whether to respect capitals in the output string
protected boolean preserveWhitespace; //Whether to respect whitespace in the output string
protected boolean preserveSymbols; //Whether to respect symbols in the output string
//Sets shift and makes sure it is within the propper bounds
private void setShift(int shiftAmount){
protected void setShift(int shiftAmount){
logger.debug("Setting shift {}", shiftAmount);
//If you shift more than 26 you will just be wrapping back around again
@@ -32,9 +32,9 @@ public class Caesar{
logger.debug("Cleaned shift {}", shift);
}
//Sets the input string
private void setInputString(String inputString) throws InvalidInputException{
protected void setInputString(String inputString) throws InvalidInputException{
if(inputString == null){
throw new NullPointerException("Input cannot be null");
throw new InvalidInputException("Input cannot be null");
}
logger.debug("Original input string '{}'", inputString);
@@ -63,7 +63,7 @@ public class Caesar{
}
}
//Encodes the inputString and stores the result in outputString
private String encode(){
protected String encode(){
logger.debug("Encoding");
StringBuilder output = new StringBuilder();
@@ -107,12 +107,12 @@ public class Caesar{
output.append(currentChar);
}
logger.debug("Saving encoded string '{}'", output);
outputString = output.toString();
logger.debug("Saving encoded string '{}'", outputString);
return outputString;
}
//Decodes the inputString and stores the result in outputString
private String decode(){
protected String decode(){
logger.debug("Decoding");
StringBuilder output = new StringBuilder();
@@ -156,11 +156,12 @@ public class Caesar{
}
//If it is whitespace, number, or punctuation just let it pass through
//Add it to the output string
logger.debug("Decoded character {}", currentChar);
output.append(currentChar);
}
logger.debug("Saving decoded string '{}'", output);
outputString = output.toString();
logger.debug("Saving decoded string '{}'", outputString);
return outputString;
}

View File

@@ -16,7 +16,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
public class Vigenere{
private static final Logger logger = LoggerFactory.getLogger(Vigenere.class);
protected static Logger logger = LoggerFactory.getLogger(Vigenere.class);
//Fields
protected String inputString; //This is the string that needs encoded/decoded

View File

@@ -15,7 +15,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
public class PolybiusSquare{
private static final Logger logger = LoggerFactory.getLogger(PolybiusSquare.class);
protected static final Logger logger = LoggerFactory.getLogger(PolybiusSquare.class);
//A class representing the location of a character in the grid
protected class CharLocation{