Updated test coverage
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user