Added logging

This commit is contained in:
2022-07-09 16:55:32 -04:00
parent e9c8397b86
commit 2d7382ba8f
44 changed files with 2341 additions and 1265 deletions

View File

@@ -1,21 +1,28 @@
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/Beaufort.java
//Mattrixwv
// Created: 02-23-22
//Modified: 02-23-22
//Modified: 07-09-22
package com.mattrixwv.cipherstream.monosubstitution;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
public class Beaufort{
private static final 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
//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
@@ -27,18 +34,27 @@ public class Beaufort{
throw new InvalidInputException("Input cannot be null");
}
logger.debug("Original input string '{}'", inputString);
//Apply removal options
if(!preserveCapitals){
logger.debug("Removing case");
inputString = inputString.toUpperCase();
}
if(!preserveWhitespace){
logger.debug("Removing whitespace");
inputString = inputString.replaceAll("\\s", "");
}
if(!preserveSymbols){
logger.debug("Removing symbols");
inputString = inputString.replaceAll("[^a-zA-Z\\s]", "");
}
//Save the string
logger.debug("Cleaned input string '{}'", inputString);
this.inputString = inputString;
//Make sure the string isn't blank
@@ -53,11 +69,17 @@ public class Beaufort{
throw new InvalidKeywordException("Keyword cannot be null");
}
logger.debug("Original keyword '{}'", keyword);
//Convert all letters to uppercase
logger.debug("Removing case");
keyword = keyword.toUpperCase();
//Remove all characters except capital letters
logger.debug("Removing all non-letters");
keyword = keyword.replaceAll("[^A-Z]", "");
//Save the string
logger.debug("Cleaned keyword '{}'", keyword);
this.keyword = keyword;
//If after all the elimination of unusable characters the keyword is empty throw an exception
@@ -67,19 +89,27 @@ public class Beaufort{
}
//Encodes the inputString and stores the result in outputString
public void encode() throws InvalidKeywordException, InvalidInputException{
logger.debug("Encoding");
//Reverse the string
logger.debug("Encoding with Atbash");
String atbashString = atbash.encode(inputString);
//Shift the reversal by 1
//?Not quite sure why this is needed. Need to look into this cipher a bit more closely
logger.debug("Shifting all letters by 1");
String caesarString = caesar.encode(1, atbashString);
//Shift each letter according to the key
logger.debug("Encoding with Vigenere");
String vigenereString = vigenere.encode(keyword, caesarString);
//Save the output
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();
}
@@ -138,6 +168,8 @@ public class Beaufort{
}
//Makes sure all of the variables are empty
public void reset(){
logger.debug("Resetting fields");
inputString = "";
outputString = "";
keyword = "";