Updating tests
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: 04-15-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -15,16 +15,17 @@ import com.mattrixwv.NumberAlgorithms;
|
||||
|
||||
|
||||
public class Affine{
|
||||
protected static Logger logger = LoggerFactory.getLogger(Affine.class);
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Affine.class);
|
||||
//Fields
|
||||
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 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
|
||||
//Settings
|
||||
protected boolean preserveCapitals; //Persist capitals in the output string
|
||||
protected boolean preserveSymbols; //Persist symbols in the output string
|
||||
protected boolean preserveWhitespace; //Persist whitespace in the output string
|
||||
|
||||
|
||||
//Ensures key1 constraints
|
||||
protected void setKey1(int key1) throws InvalidKeywordException{
|
||||
@@ -225,19 +226,16 @@ public class Affine{
|
||||
return outputString;
|
||||
}
|
||||
|
||||
//Returns the cleaned inputString
|
||||
//Getters
|
||||
public String getInputString(){
|
||||
return inputString;
|
||||
}
|
||||
//Returns the outputString
|
||||
public String getOutputString(){
|
||||
return outputString;
|
||||
}
|
||||
//Returns the cleaned key1
|
||||
public int getKey1(){
|
||||
return key1;
|
||||
}
|
||||
//Returns the cleaned key2
|
||||
public int getKey2(){
|
||||
return key2;
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/Autokey.java
|
||||
//Mattrixwv
|
||||
// Created: 07-25-21
|
||||
//Modified: 04-15-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
public class Autokey extends Vigenere{
|
||||
protected static Logger logger = LoggerFactory.getLogger(Autokey.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(Autokey.class);
|
||||
|
||||
|
||||
//Special rules for setting the strings for encoding
|
||||
protected void encodeSet(String keyword, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
@@ -57,7 +58,7 @@ public class Autokey extends Vigenere{
|
||||
}
|
||||
//Decodes the inputString
|
||||
@Override
|
||||
protected String decode(){
|
||||
protected void decode(){
|
||||
logger.debug("Decoding");
|
||||
|
||||
//Decode what the key will allow, add that to the key and continue
|
||||
@@ -109,7 +110,6 @@ public class Autokey extends Vigenere{
|
||||
//Save and return the results
|
||||
outputString = fullOutput.toString();
|
||||
logger.debug("Saving output string '{}'", outputString);
|
||||
return outputString;
|
||||
}
|
||||
|
||||
|
||||
@@ -125,13 +125,15 @@ public class Autokey extends Vigenere{
|
||||
public String encode(String keyword, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
reset();
|
||||
encodeSet(keyword, inputString);
|
||||
return encode();
|
||||
encode();
|
||||
return outputString;
|
||||
}
|
||||
//Decodes inputString using the Autokey cipher
|
||||
@Override
|
||||
public String decode(String keyword, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
reset();
|
||||
decodeSet(keyword, inputString);
|
||||
return decode();
|
||||
decode();
|
||||
return outputString;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/Baconian.java
|
||||
//Mattrixwv
|
||||
// Created: 01-12-22
|
||||
//Modified: 04-15-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
|
||||
|
||||
public class Baconian{
|
||||
protected static Logger logger = LoggerFactory.getLogger(Baconian.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(Baconian.class);
|
||||
|
||||
//Conversions
|
||||
protected static final ArrayList<String> code = new ArrayList<>(Arrays.asList(
|
||||
@@ -25,8 +25,9 @@ public class Baconian{
|
||||
"abbaa", "abbab", "abbba", "abbbb", "baaaa", "baaab", "baaba", "baabb", "baabb", "babaa", "babab", "babba", "babbb" //N-Z
|
||||
));
|
||||
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
|
||||
protected String outputString; //The encoded/decoded string
|
||||
protected boolean preserveCapitals; //Persist capitals in the output string
|
||||
|
||||
|
||||
//Sets the input string
|
||||
protected void setInputStringEncode(String inputString) throws InvalidInputException{
|
||||
@@ -121,7 +122,7 @@ public class Baconian{
|
||||
logger.debug("Saving output string '{}'", outputString);
|
||||
}
|
||||
//Decodes the inputString and stores the result in outputString
|
||||
protected String decode(){
|
||||
protected void decode(){
|
||||
logger.debug("Decoding");
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
@@ -154,7 +155,6 @@ public class Baconian{
|
||||
//Save and return the output
|
||||
outputString = output.toString();
|
||||
logger.debug("Saving output string '{}'", outputString);
|
||||
return outputString;
|
||||
}
|
||||
|
||||
//Constructor
|
||||
@@ -166,14 +166,7 @@ public class Baconian{
|
||||
reset();
|
||||
this.preserveCapitals = preserveCapitals;
|
||||
}
|
||||
//Returns the outputString
|
||||
public String getOutputString(){
|
||||
return outputString;
|
||||
}
|
||||
//Returns the inputString
|
||||
public String getInputString(){
|
||||
return inputString;
|
||||
}
|
||||
|
||||
//Sets the inputString and encodes the message
|
||||
public String encode(String inputString) throws InvalidInputException{
|
||||
reset();
|
||||
@@ -185,9 +178,18 @@ public class Baconian{
|
||||
public String decode(String inputString) throws InvalidCharacterException, InvalidInputException{
|
||||
reset();
|
||||
setInputStringDecode(inputString);
|
||||
return decode();
|
||||
decode();
|
||||
return outputString;
|
||||
}
|
||||
//Makes sure all of the variables are empty
|
||||
|
||||
//Getters
|
||||
public String getInputString(){
|
||||
return inputString;
|
||||
}
|
||||
public String getOutputString(){
|
||||
return outputString;
|
||||
}
|
||||
//Makes sure all variables are empty
|
||||
public void reset(){
|
||||
logger.debug("Resetting fields");
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/BaseX.java
|
||||
//Mattrixwv
|
||||
// Created: 01-08-22
|
||||
//Modified: 04-16-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -16,12 +16,14 @@ import com.mattrixwv.cipherstream.exceptions.InvalidBaseException;
|
||||
|
||||
|
||||
public class BaseX{
|
||||
protected static Logger logger = LoggerFactory.getLogger(BaseX.class);
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(BaseX.class);
|
||||
//Fields
|
||||
protected String inputString; //The string that needs encoded/decoded
|
||||
protected String outputString; //The encoded/decoded string
|
||||
//Settings
|
||||
protected int base; //The base that the number will be encoded at
|
||||
|
||||
|
||||
//Sets the input string
|
||||
protected void setInputStringEncode(String inputString) throws InvalidInputException{
|
||||
if(inputString == null){
|
||||
@@ -80,7 +82,7 @@ public class BaseX{
|
||||
this.base = base;
|
||||
}
|
||||
//Encode inputString, store it in outputString, and return it
|
||||
protected String encode(){
|
||||
protected void encode(){
|
||||
logger.debug("Encoding");
|
||||
|
||||
//Encode every character in inputString
|
||||
@@ -99,12 +101,9 @@ public class BaseX{
|
||||
//Save the output
|
||||
outputString = output.toString().toUpperCase();
|
||||
logger.debug("Saving output string '{}'", outputString);
|
||||
|
||||
//Return the output
|
||||
return outputString;
|
||||
}
|
||||
//Decode inputString, store it in outputString, and return it
|
||||
protected String decode() throws InvalidCharacterException{
|
||||
protected void decode() throws InvalidCharacterException{
|
||||
logger.debug("Decoding");
|
||||
|
||||
//Decode every binary number in the string
|
||||
@@ -128,9 +127,6 @@ public class BaseX{
|
||||
//Save the output
|
||||
outputString = output.toString();
|
||||
logger.debug("Saving output string '{}'", outputString);
|
||||
|
||||
//Return the output
|
||||
return outputString;
|
||||
}
|
||||
|
||||
//Constructor
|
||||
@@ -142,43 +138,47 @@ public class BaseX{
|
||||
reset();
|
||||
setBase(base);
|
||||
}
|
||||
//Returns the inputString
|
||||
public String getInputString(){
|
||||
return inputString;
|
||||
}
|
||||
//Returns the outputString
|
||||
public String getOutputString(){
|
||||
return outputString;
|
||||
}
|
||||
//Returns the base
|
||||
public int getBase(){
|
||||
return base;
|
||||
}
|
||||
|
||||
//Sets the inputString and encodes the message
|
||||
public String encode(String inputString) throws InvalidInputException{
|
||||
reset();
|
||||
setInputStringEncode(inputString);
|
||||
return encode();
|
||||
encode();
|
||||
return outputString;
|
||||
}
|
||||
public String encode(int base, String inputString) throws InvalidBaseException, InvalidInputException{
|
||||
reset();
|
||||
setBase(base);
|
||||
setInputStringEncode(inputString);
|
||||
return encode();
|
||||
encode();
|
||||
return outputString;
|
||||
}
|
||||
//Sets the inputString and decodes the message
|
||||
public String decode(String inputString) throws InvalidCharacterException, InvalidInputException{
|
||||
reset();
|
||||
setInputStringDecode(inputString);
|
||||
return decode();
|
||||
decode();
|
||||
return outputString;
|
||||
}
|
||||
public String decode(int base, String inputString) throws InvalidBaseException, InvalidCharacterException, InvalidInputException{
|
||||
reset();
|
||||
setBase(base);
|
||||
setInputStringDecode(inputString);
|
||||
return decode();
|
||||
decode();
|
||||
return outputString;
|
||||
}
|
||||
//Makes sure all of the variables are empty
|
||||
|
||||
//Getters
|
||||
public String getInputString(){
|
||||
return inputString;
|
||||
}
|
||||
public String getOutputString(){
|
||||
return outputString;
|
||||
}
|
||||
public int getBase(){
|
||||
return base;
|
||||
}
|
||||
//Makes sure all variables are empty
|
||||
public void reset(){
|
||||
logger.debug("Resetting fields");
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/Beaufort.java
|
||||
//Mattrixwv
|
||||
// Created: 02-23-22
|
||||
//Modified: 04-16-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -13,20 +13,21 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
public class Beaufort{
|
||||
protected static Logger logger = LoggerFactory.getLogger(Beaufort.class);
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Beaufort.class);
|
||||
//Fields
|
||||
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
|
||||
//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
|
||||
//Internal ciphers
|
||||
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{
|
||||
//Make sure the input isn't null
|
||||
@@ -138,18 +139,7 @@ public class Beaufort{
|
||||
vigenere = new Vigenere(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
reset();
|
||||
}
|
||||
//Returns the current inputString
|
||||
public String getInputString(){
|
||||
return inputString;
|
||||
}
|
||||
//Returns the current outputString
|
||||
public String getOutputString(){
|
||||
return outputString;
|
||||
}
|
||||
//Returns the current keyword
|
||||
public String getKeyword(){
|
||||
return keyword;
|
||||
}
|
||||
|
||||
//Encodes inputString using keyword and returns the result
|
||||
public String encode(String keyword, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
//Set the parameters
|
||||
@@ -170,7 +160,18 @@ public class Beaufort{
|
||||
decode();
|
||||
return outputString;
|
||||
}
|
||||
//Makes sure all of the variables are empty
|
||||
|
||||
//Getters
|
||||
public String getInputString(){
|
||||
return inputString;
|
||||
}
|
||||
public String getOutputString(){
|
||||
return outputString;
|
||||
}
|
||||
public String getKeyword(){
|
||||
return keyword;
|
||||
}
|
||||
//Makes sure all variables are empty
|
||||
public void reset(){
|
||||
logger.debug("Resetting fields");
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/Caesar.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-25-21
|
||||
//Modified: 04-16-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -12,15 +12,16 @@ import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
|
||||
|
||||
public class Caesar{
|
||||
protected static Logger logger = LoggerFactory.getLogger(Caesar.class);
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Caesar.class);
|
||||
//Fields
|
||||
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
|
||||
//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
|
||||
|
||||
|
||||
//Sets shift and makes sure it is within the propper bounds
|
||||
protected void setShift(int shiftAmount){
|
||||
@@ -63,7 +64,7 @@ public class Caesar{
|
||||
}
|
||||
}
|
||||
//Encodes the inputString and stores the result in outputString
|
||||
protected String encode(){
|
||||
protected void encode(){
|
||||
logger.debug("Encoding");
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
@@ -109,10 +110,9 @@ public class Caesar{
|
||||
|
||||
outputString = output.toString();
|
||||
logger.debug("Saving encoded string '{}'", outputString);
|
||||
return outputString;
|
||||
}
|
||||
//Decodes the inputString and stores the result in outputString
|
||||
protected String decode(){
|
||||
protected void decode(){
|
||||
logger.debug("Decoding");
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
@@ -162,7 +162,6 @@ public class Caesar{
|
||||
|
||||
outputString = output.toString();
|
||||
logger.debug("Saving decoded string '{}'", outputString);
|
||||
return outputString;
|
||||
}
|
||||
|
||||
//Constructor
|
||||
@@ -184,29 +183,29 @@ public class Caesar{
|
||||
reset();
|
||||
setShift(shiftAmount);
|
||||
setInputString(inputString);
|
||||
return encode();
|
||||
encode();
|
||||
return outputString;
|
||||
}
|
||||
//Sets the shift and inputString and decodes the message
|
||||
public String decode(int shiftAmount, String inputString) throws InvalidInputException{
|
||||
reset();
|
||||
setShift(shiftAmount);
|
||||
setInputString(inputString);
|
||||
return decode();
|
||||
decode();
|
||||
return outputString;
|
||||
}
|
||||
|
||||
//Returns the inputString
|
||||
//Getters
|
||||
public String getInputString(){
|
||||
return inputString;
|
||||
}
|
||||
//Returns shift
|
||||
public int getShift(){
|
||||
return shift;
|
||||
}
|
||||
//Returns the outputString
|
||||
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");
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/OneTimePad.java
|
||||
//Mattrixwv
|
||||
// Created: 02-23-22
|
||||
//Modified: 07-09-22
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -13,10 +13,9 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
public class OneTimePad extends Vigenere{
|
||||
protected static Logger logger = LoggerFactory.getLogger(OneTimePad.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(OneTimePad.class);
|
||||
|
||||
//?Add some kind of entropy calculator?
|
||||
//?Add some kind of "book passage includer"?
|
||||
|
||||
|
||||
//Constructor
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/Porta.java
|
||||
//Mattrixwv
|
||||
// Created: 02-28-22
|
||||
//Modified: 04-17-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
public class Porta{
|
||||
protected static Logger logger = LoggerFactory.getLogger(Porta.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(Porta.class);
|
||||
|
||||
private static final String[] tableau = {
|
||||
"NOPQRSTUVWXYZABCDEFGHIJKLM", //A-B
|
||||
@@ -32,12 +32,14 @@ public class Porta{
|
||||
};
|
||||
|
||||
//Fields
|
||||
protected String inputString; //The string that needs encoded/decoded
|
||||
protected String inputString; //The string that needs encoded/decoded
|
||||
protected String outputString; //The encoded/decoded string
|
||||
protected String keyword; //The keyword used to encode the input 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
|
||||
|
||||
|
||||
//Ensure all keyword constraints are followed
|
||||
protected void setKeyword(String keyword) throws InvalidKeywordException{
|
||||
@@ -210,19 +212,17 @@ public class Porta{
|
||||
return outputString;
|
||||
}
|
||||
|
||||
//Returns the inputString
|
||||
//Getters
|
||||
public String getInputString(){
|
||||
return inputString;
|
||||
}
|
||||
//Returns the shift
|
||||
public String getOutputString(){
|
||||
return outputString;
|
||||
}
|
||||
//Returns the outputString
|
||||
public String getKeyword(){
|
||||
return keyword;
|
||||
}
|
||||
//Makes sure all of the fields are empty
|
||||
//Makes sure all fields are empty
|
||||
public void reset(){
|
||||
logger.debug("Resetting fields");
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/Substitution.java
|
||||
//Mattrixwv
|
||||
// Created: 02-22-22
|
||||
//Modified: 04-18-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -13,15 +13,16 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
public class Substitution{
|
||||
protected static Logger logger = LoggerFactory.getLogger(Substitution.class);
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Substitution.class);
|
||||
//Fields
|
||||
protected String inputString; //The string that needs encoded/decoded
|
||||
protected String outputString; //The encoded/decoded string
|
||||
protected String keyword; //The keyword used to encode/decode the input
|
||||
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
|
||||
//Getters
|
||||
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
|
||||
|
||||
|
||||
//Ensures key constraints are followed
|
||||
protected void setKeyword(String key) throws InvalidKeywordException{
|
||||
@@ -172,6 +173,7 @@ public class Substitution{
|
||||
logger.debug("Decoded message '{}'", outputString);
|
||||
}
|
||||
|
||||
//Constructors
|
||||
public Substitution(){
|
||||
preserveCapitals = false;
|
||||
preserveWhitespace = false;
|
||||
@@ -184,6 +186,23 @@ public class Substitution{
|
||||
this.preserveSymbols = preserveSymbols;
|
||||
reset();
|
||||
}
|
||||
|
||||
//Encodes inputString using the provided key
|
||||
public String encode(String key, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
setKeyword(key);
|
||||
setInputString(inputString);
|
||||
encode();
|
||||
return outputString;
|
||||
}
|
||||
//Decodes inputString using the provided key
|
||||
public String decode(String key, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
setKeyword(key);
|
||||
setInputString(inputString);
|
||||
decode();
|
||||
return outputString;
|
||||
}
|
||||
|
||||
//Getters
|
||||
public String getInputString(){
|
||||
return inputString;
|
||||
}
|
||||
@@ -193,18 +212,7 @@ public class Substitution{
|
||||
public String getKeyword(){
|
||||
return keyword;
|
||||
}
|
||||
public String encode(String key, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
setKeyword(key);
|
||||
setInputString(inputString);
|
||||
encode();
|
||||
return outputString;
|
||||
}
|
||||
public String decode(String key, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
setKeyword(key);
|
||||
setInputString(inputString);
|
||||
decode();
|
||||
return outputString;
|
||||
}
|
||||
//Makes sure all variables are empty
|
||||
public void reset(){
|
||||
logger.debug("Resetting fields");
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/Vigenere.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-25-21
|
||||
//Modified: 04-18-23
|
||||
//Modified: 05-04-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -16,16 +16,17 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
public class Vigenere{
|
||||
protected static Logger logger = LoggerFactory.getLogger(Vigenere.class);
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Vigenere.class);
|
||||
//Fields
|
||||
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 resposible for determining the offsets that you change each character by
|
||||
protected ArrayList<Integer> offset; //Holds the offsets coputed from each character in the keyword
|
||||
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
|
||||
|
||||
|
||||
//Uses keyword to calculate the offset for the Caesar cipher for each character
|
||||
protected void setOffset(){
|
||||
@@ -102,7 +103,7 @@ public class Vigenere{
|
||||
}
|
||||
}
|
||||
//Encodes inputString and stores the result in outputString
|
||||
protected String encode(){
|
||||
protected void encode(){
|
||||
logger.debug("Encoding");
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
@@ -145,10 +146,9 @@ public class Vigenere{
|
||||
//Save output
|
||||
outputString = output.toString();
|
||||
logger.debug("Encoded message '{}'", outputString);
|
||||
return outputString;
|
||||
}
|
||||
//Decodes inputString and stores the result in outputString
|
||||
protected String decode(){
|
||||
protected void decode(){
|
||||
logger.debug("Decoding");
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
@@ -191,7 +191,6 @@ public class Vigenere{
|
||||
//Save output
|
||||
outputString = output.toString();
|
||||
logger.debug("Decoded message '{}'", outputString);
|
||||
return outputString;
|
||||
}
|
||||
|
||||
|
||||
@@ -210,37 +209,39 @@ public class Vigenere{
|
||||
this.preserveWhitespace = preserveWhitespace;
|
||||
this.preserveSymbols = preserveSymbols;
|
||||
}
|
||||
//Returns the current inputString
|
||||
public String getInputString(){
|
||||
return inputString;
|
||||
}
|
||||
//Returns the current outputString
|
||||
public String getOutputString(){
|
||||
return outputString;
|
||||
}
|
||||
//Returns the current keyword
|
||||
public String getKeyword(){
|
||||
return keyword;
|
||||
}
|
||||
//Returns the current offsets (Used mostly in bug fixing)
|
||||
public List<Integer> getOffsets(){
|
||||
return offset;
|
||||
}
|
||||
|
||||
//Encodes input using key and returns the result
|
||||
public String encode(String keyword, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
reset();
|
||||
setKeyword(keyword);
|
||||
setInputString(inputString);
|
||||
return encode();
|
||||
encode();
|
||||
return outputString;
|
||||
}
|
||||
//Decodes input using key and returns the result
|
||||
public String decode(String keyword, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
reset();
|
||||
setKeyword(keyword);
|
||||
setInputString(inputString);
|
||||
return decode();
|
||||
decode();
|
||||
return outputString;
|
||||
}
|
||||
//Makes sure all of the variables are empty
|
||||
|
||||
//Getters
|
||||
public String getInputString(){
|
||||
return inputString;
|
||||
}
|
||||
public String getOutputString(){
|
||||
return outputString;
|
||||
}
|
||||
public String getKeyword(){
|
||||
return keyword;
|
||||
}
|
||||
public List<Integer> getOffsets(){
|
||||
return offset;
|
||||
}
|
||||
|
||||
//Makes sure all variables are empty
|
||||
public void reset(){
|
||||
logger.debug("Resetting fields");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user