Updating tests
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/Atbash.java
|
||||
//Mattrixwv
|
||||
// Created: 07-25-21
|
||||
//Modified: 04-15-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -12,17 +12,18 @@ import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
|
||||
|
||||
public class Atbash{
|
||||
protected static Logger logger = LoggerFactory.getLogger(Atbash.class);
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Atbash.class);
|
||||
//Fields
|
||||
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
|
||||
//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
|
||||
|
||||
|
||||
//Encodes inputString and stores in outputString
|
||||
protected String encode(){
|
||||
protected void encode(){
|
||||
logger.debug("Encoding");
|
||||
StringBuilder output = new StringBuilder();
|
||||
//Step through every element in the inputString and shift it the correct amount
|
||||
@@ -34,22 +35,27 @@ public class Atbash{
|
||||
//Use either uppercase or lowercase for the base
|
||||
//(letterbase + 25 - (currentChar - letterBase))
|
||||
if(Character.isUpperCase(currentChar)){
|
||||
logger.debug("Encoding uppercase");
|
||||
|
||||
output.append((char)(155 - currentChar));
|
||||
}
|
||||
else{
|
||||
logger.debug("Encoding lowercase");
|
||||
|
||||
output.append((char)(219 - currentChar));
|
||||
}
|
||||
}
|
||||
//Keep any punctuatio/whitespace the way it is
|
||||
else{
|
||||
logger.debug("Appending symbol");
|
||||
|
||||
output.append(currentChar);
|
||||
}
|
||||
}
|
||||
|
||||
//Return the output
|
||||
logger.debug("Saving output string '{}'", output);
|
||||
outputString = output.toString();
|
||||
return outputString;
|
||||
logger.debug("Saving output string '{}'", outputString);
|
||||
}
|
||||
//Removes all invalid characters and sets inputString
|
||||
protected void setInputString(String inputString) throws InvalidInputException{
|
||||
@@ -108,22 +114,22 @@ public class Atbash{
|
||||
//Make sure everything is empty before you begin
|
||||
reset();
|
||||
setInputString(inputString);
|
||||
return encode();
|
||||
encode();
|
||||
return outputString;
|
||||
}
|
||||
//Decodes inputString and returns the result
|
||||
public String decode(String inputString) throws InvalidInputException{
|
||||
return encode(inputString);
|
||||
}
|
||||
|
||||
//Returns the cleaned input string
|
||||
//Getters
|
||||
public String getInputString(){
|
||||
return inputString;
|
||||
}
|
||||
//Returns the output string
|
||||
public String getOutputString(){
|
||||
return outputString;
|
||||
}
|
||||
//Makes sure all of the variables are empty
|
||||
//Makes sure all variables are empty
|
||||
public void reset(){
|
||||
logger.debug("Resetting fields");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user