diff --git a/pom.xml b/pom.xml
index bbd1b01..872ef9b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.mattrixwv
cipher-stream-java
- 1.1.0
+ 1.2.0
CipherStreamJava
http://www.mattrixwv.com
@@ -14,12 +14,13 @@
UTF-8
- 19
- 19
- 19
+ UTF-8
+ 20
+ 20
+ 20
- 19
+ 20
target/dependency-check-report.json
target/dependency-check-report.html
@@ -28,28 +29,47 @@
mattrixwv
myClasses
- 1.2.0
+ 1.3.0
com.mattrixwv
matrix
- 1.0.1
+ 1.1.0
org.slf4j
slf4j-api
- 2.0.6
+ 2.0.7
+
+
+
+ org.slf4j
+ slf4j-nop
+ 2.0.7
+ test
org.junit.jupiter
junit-jupiter-api
- 5.9.1
+ 5.9.2
test
+
+
+ org.mockito
+ mockito-core
+ 5.3.0
+
+
+
+ org.mockito
+ mockito-junit-jupiter
+ 5.3.0
+
@@ -58,7 +78,7 @@
org.apache.maven.plugins
maven-enforcer-plugin
- 3.1.0
+ 3.3.0
enforce-maven
@@ -83,46 +103,51 @@
maven-resources-plugin
- 3.2.0
+ 3.3.1
maven-compiler-plugin
- 3.10.1
+ 3.11.0
maven-surefire-plugin
- 3.0.0-M5
+ 3.0.0
maven-jar-plugin
- 3.2.2
+ 3.3.0
maven-install-plugin
- 3.0.0-M1
+ 3.1.1
maven-deploy-plugin
- 3.0.0-M1
+ 3.1.1
maven-site-plugin
- 3.12.0
+ 3.12.1
maven-project-info-reports-plugin
- 3.3.0
+ 3.4.2
org.codehaus.mojo
versions-maven-plugin
- 2.11.0
+ 2.15.0
file://${session.executionRootDirectory}/version-rules.xml
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+ 3.5.0
+
org.sonarsource.scanner.maven
@@ -132,7 +157,7 @@
org.jacoco
jacoco-maven-plugin
- 0.8.8
+ 0.8.9
jacoco-initialize
@@ -153,7 +178,7 @@
org.owasp
dependency-check-maven
- 7.1.1
+ 8.2.1
none
diff --git a/src/main/java/com/mattrixwv/cipherstream/combination/ADFGX.java b/src/main/java/com/mattrixwv/cipherstream/combination/ADFGX.java
index ab4f3ce..d1bd7f6 100644
--- a/src/main/java/com/mattrixwv/cipherstream/combination/ADFGX.java
+++ b/src/main/java/com/mattrixwv/cipherstream/combination/ADFGX.java
@@ -16,23 +16,23 @@ import com.mattrixwv.cipherstream.polysubstitution.PolybiusSquare;
public class ADFGX{
- private static final Logger logger = LoggerFactory.getLogger(ADFGX.class);
+ protected static Logger logger = LoggerFactory.getLogger(ADFGX.class);
//Internal fields
- 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
- 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 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
+ 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 PolybiusSquare polybiusSquare; //The first step in encoding
- private Columnar columnar; //The second step in encoding
+ protected PolybiusSquare polybiusSquare; //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");
}
@@ -41,7 +41,7 @@ public class ADFGX{
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");
}
@@ -50,7 +50,7 @@ public class ADFGX{
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");
}
@@ -80,7 +80,7 @@ public class ADFGX{
logger.debug("cleaned input string '{}'", inputString);
}
//Format the output string with capitals, symbols, and numbers that are in the input string
- private void formatOutputStringEncode(){
+ protected void formatOutputStringEncode(){
logger.debug("Formatting output string to match input string");
StringBuilder output = new StringBuilder();
@@ -109,7 +109,7 @@ public class ADFGX{
logger.debug("Saving output string '{}'", outputString);
outputString = output.toString();
}
- private void formatOutputStringDecode(){
+ protected void formatOutputStringDecode(){
logger.debug("Formatting output string to match input string");
StringBuilder output = new StringBuilder();
int outputLocation = 0;
@@ -139,7 +139,7 @@ public class ADFGX{
outputString = output.toString();
}
//Encodes the inputString and stores the result in outputString
- private void encode() throws InvalidCharacterException, InvalidInputException, InvalidKeywordException{
+ protected void encode() throws InvalidCharacterException, InvalidInputException, InvalidKeywordException{
//Encode the input with polybius
logger.debug("Encoding using Polybius Square");
String polybiusOutput = polybiusSquare.encode(squareKeyword, inputString);
@@ -158,7 +158,7 @@ public class ADFGX{
formatOutputStringEncode();
}
//Decodes the inputString and stores the result in outputString
- private void decode() throws InvalidKeywordException, InvalidCharacterException, InvalidInputException{
+ protected void decode() throws InvalidKeywordException, InvalidCharacterException, InvalidInputException{
//Decode the input with columnar
logger.debug("Decoding using columnar");
String columnarOutput = columnar.decode(keyword, inputString);
diff --git a/src/test/java/com/mattrixwv/cipherstream/combination/TestADFGX.java b/src/test/java/com/mattrixwv/cipherstream/combination/TestADFGX.java
index f309ef3..522f153 100644
--- a/src/test/java/com/mattrixwv/cipherstream/combination/TestADFGX.java
+++ b/src/test/java/com/mattrixwv/cipherstream/combination/TestADFGX.java
@@ -1,450 +1,199 @@
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamjava/combination/TestADFGX.java
//Mattrixwv
// Created: 01-25-22
-//Modified: 07-09-22
+//Modified: 04-14-23
package com.mattrixwv.cipherstream.combination;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.slf4j.Logger;
-import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
+@ExtendWith(MockitoExtension.class)
public class TestADFGX{
- @Test
- public void testEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
- ADFGX cipher = new ADFGX(true, true, true);
+ private ADFGX cipher;
+ private Logger logger;
- //Test lowercase encoding
- String inputString = "messagetoencode";
- String squareKeyword = "SquareKeyword";
- String keyword = "keyword";
- String correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
- String output = cipher.encode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
- //Test uppercase encoding
- inputString = "MESSAGETOENCODE";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
- output = cipher.encode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
- //Test whitespace encoding
- inputString = "message to encode";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "aagagadfagaxxd axdx adafafxddgdf";
- output = cipher.encode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
-
- //Test symbol encoding
- inputString = "message*to+encode-";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "aagagadfagaxxd*axdx+adafafxddgdf-";
- output = cipher.encode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
-
- //Test mixed case, whitespace, and symbol encoding
- inputString = "Message to^encode";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "AAgagadfagaxxd axdx^adafafxddgdf";
- output = cipher.encode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
- }
- @Test
- public void testNoCapitalEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
- ADFGX cipher = new ADFGX(false, true, true);
-
- //Test lowercase encoding
- String inputString = "messagetoencode";
- String squareKeyword = "SquareKeyword";
- String keyword = "keyword";
- String correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
- String output = cipher.encode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
- //Test uppercase encoding
- inputString = "MESSAGETOENCODE";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
- output = cipher.encode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
-
- //Test whitespace encoding
- inputString = "message to encode";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "AAGAGADFAGAXXD AXDX ADAFAFXDDGDF";
- output = cipher.encode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
-
- //Test symbol encoding
- inputString = "message*to+encode-";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "AAGAGADFAGAXXD*AXDX+ADAFAFXDDGDF-";
- output = cipher.encode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
-
- //Test mixed case, whitespace, and symbol encoding
- inputString = "Message to^encode";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "AAGAGADFAGAXXD AXDX^ADAFAFXDDGDF";
- output = cipher.encode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
- }
- @Test
- public void testNoWhitespaceEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
- ADFGX cipher = new ADFGX(true, false, true);
-
- //Test lowercase encoding
- String inputString = "messagetoencode";
- String squareKeyword = "SquareKeyword";
- String keyword = "keyword";
- String correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
- String output = cipher.encode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
- //Test uppercase encoding
- inputString = "MESSAGETOENCODE";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
- output = cipher.encode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
-
- //Test whitespace encoding
- inputString = "message to encode";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
- output = cipher.encode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
-
- //Test symbol encoding
- inputString = "message*to+encode-";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "aagagadfagaxxd*axdx+adafafxddgdf-";
- output = cipher.encode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
-
- //Test mixed case, whitespace, and symbol encoding
- inputString = "Message to^encode";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "AAgagadfagaxxdaxdx^adafafxddgdf";
- output = cipher.encode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
- }
- @Test
- public void testNoSymbolEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
- ADFGX cipher = new ADFGX(true, true, false);
-
- //Test lowercase encoding
- String inputString = "messagetoencode";
- String squareKeyword = "SquareKeyword";
- String keyword = "keyword";
- String correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
- String output = cipher.encode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
- //Test uppercase encoding
- inputString = "MESSAGETOENCODE";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
- output = cipher.encode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
-
- //Test whitespace encoding
- inputString = "message to encode";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "aagagadfagaxxd axdx adafafxddgdf";
- output = cipher.encode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
-
- //Test symbol encoding
- inputString = "message*to+encode-";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
- output = cipher.encode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
-
- //Test mixed case, whitespace, and symbol encoding
- inputString = "Message to^encode";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "AAgagadfagaxxd axdxadafafxddgdf";
- output = cipher.encode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
- }
- @Test
- public void testNoCapitalWhitespaceSymbolEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
- ADFGX cipher = new ADFGX(false, false, false);
-
- //Test lowercase encoding
- String inputString = "messagetoencode";
- String squareKeyword = "SquareKeyword";
- String keyword = "keyword";
- String correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
- String output = cipher.encode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
- //Test uppercase encoding
- inputString = "MESSAGETOENCODE";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
- output = cipher.encode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
-
- //Test whitespace encoding
- inputString = "message to encode";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
- output = cipher.encode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
-
- //Test symbol encoding
- inputString = "message*to+encode-";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
- output = cipher.encode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
-
- //Test mixed case, whitespace, and symbol encoding
- inputString = "Message to^encode";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
- output = cipher.encode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
+ @BeforeEach
+ public void setup(){
+ cipher = new ADFGX();
+ logger = mock(Logger.class);
+ ADFGX.logger = logger;
}
@Test
- public void testDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
- ADFGX cipher = new ADFGX(true, true, true);
+ public void testSetSquareKeyword(){
+ assertThrows(InvalidKeywordException.class, () -> {
+ cipher.setSquareKeyword(null);
+ });
+ assertEquals("", cipher.squareKeyword);
+ verify(logger, never()).debug(anyString(), anyString());
- //Test lowercase decoding
- String inputString = "aagagadfagaxxdaxdxadafafxddgdf";
- String squareKeyword = "SquareKeyword";
- String keyword = "keyword";
- String correctOutput = "messagetoencode";
- String output = cipher.decode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
- //Test uppercase decoding
- inputString = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "MESSAGETOENCODE";
- output = cipher.decode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
-
- //Test whitespace decoding
- inputString = "aagagadfagaxxd axdx adafafxddgdf";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "message to encode";
- output = cipher.decode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
-
- //Test symbol decoding
- inputString = "aagagadfagaxxd*axdx+adafafxddgdf-";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "message*to+encode-";
- output = cipher.decode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
-
- //Test mixed case, whitespace, and symbol decoding
- inputString = "AAgagadfagaxxd axdx^adafafxddgdf";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "Message to^encode";
- output = cipher.decode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
+ String squareKeyword = "squareKeyword";
+ cipher.setSquareKeyword(squareKeyword);
+ assertEquals(squareKeyword, cipher.squareKeyword);
+ verify(logger, times(1)).debug("squareKeyword = {}", squareKeyword);
}
+
@Test
- public void testNoCapitalDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
- ADFGX cipher = new ADFGX(false, true, true);
+ public void testSetKeyword(){
+ assertThrows(InvalidKeywordException.class, () -> {
+ cipher.setKeyword(null);
+ });
+ assertEquals("", cipher.keyword);
+ verify(logger, never()).debug(anyString(), anyString());
- //Test lowercase decoding
- String inputString = "aagagadfagaxxdaxdxadafafxddgdf";
- String squareKeyword = "SquareKeyword";
String keyword = "keyword";
- String correctOutput = "MESSAGETOENCODE";
- String output = cipher.decode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
- //Test uppercase decoding
- inputString = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "MESSAGETOENCODE";
- output = cipher.decode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
-
- //Test whitespace decoding
- inputString = "aagagadfagaxxd axdx adafafxddgdf";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "MESSAGE TO ENCODE";
- output = cipher.decode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
-
- //Test symbol decoding
- inputString = "aagagadfagaxxd*axdx+adafafxddgdf-";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "MESSAGE*TO+ENCODE-";
- output = cipher.decode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
-
- //Test mixed case, whitespace, and symbol decoding
- inputString = "AAgagadfagaxxd axdx^adafafxddgdf";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "MESSAGE TO^ENCODE";
- output = cipher.decode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
+ cipher.setKeyword(keyword);
+ assertEquals(keyword, cipher.keyword);
+ verify(logger, times(1)).debug("keyword = {}", keyword);
}
+
@Test
- public void testNoWhitespaceDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
- ADFGX cipher = new ADFGX(true, false, true);
+ public void testSetInputString(){
+ //Null input
+ assertThrows(InvalidInputException.class, () -> {
+ cipher.setInputString(null);
+ });
+ assertEquals("", cipher.inputString);
+ verify(logger, never()).debug(anyString(), anyString());
- //Test lowercase decoding
- String inputString = "aagagadfagaxxdaxdxadafafxddgdf";
- String squareKeyword = "SquareKeyword";
- String keyword = "keyword";
- String correctOutput = "messagetoencode";
- String output = cipher.decode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
- //Test uppercase decoding
- inputString = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "MESSAGETOENCODE";
- output = cipher.decode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
+ String originalInputString = "original input string '{}'";
+ String cleanedInputString = "cleaned input string '{}'";
- //Test whitespace decoding
- inputString = "aagagadfagaxxd axdx adafafxddgdf";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "messagetoencode";
- output = cipher.decode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
+ //Blank input
+ cipher.preserveCapitals = true;
+ cipher.preserveSymbols = true;
+ cipher.preserveWhitespace = true;
+ assertThrows(InvalidInputException.class, () -> {
+ cipher.setInputString("");
+ });
+ assertEquals("", cipher.inputString);
+ verify(logger, times(1)).debug(originalInputString, "");
- //Test symbol decoding
- inputString = "aagagadfagaxxd*axdx+adafafxddgdf-";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "message*to+encode-";
- output = cipher.decode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
+ //No options
+ String inputString = "input String*";
+ cipher.setInputString(inputString);
+ assertEquals(inputString, cipher.inputString);
+ verify(logger, times(1)).debug(originalInputString, inputString);
+ verify(logger, times(1)).debug(cleanedInputString, inputString);
- //Test mixed case, whitespace, and symbol decoding
- inputString = "AAgagadfagaxxd axdx^adafafxddgdf";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "Messageto^encode";
- output = cipher.decode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
+ //capitals
+ cipher.preserveCapitals = false;
+ cipher.preserveWhitespace = true;
+ cipher.preserveSymbols = true;
+ inputString = "input String*";
+ cipher.setInputString(inputString);
+ assertEquals(inputString.toUpperCase(), cipher.inputString);
+ verify(logger, times(2)).debug(originalInputString, inputString);
+ verify(logger, times(1)).debug("Removing capitals");
+ verify(logger, times(1)).debug(cleanedInputString, inputString.toUpperCase());
+
+ //whitespace
+ cipher.preserveCapitals = true;
+ cipher.preserveWhitespace = false;
+ cipher.preserveSymbols = true;
+ inputString = "input String*";
+ cipher.setInputString(inputString);
+ assertEquals(inputString.replaceAll("\\s", ""), cipher.inputString);
+ verify(logger, times(3)).debug(originalInputString, inputString);
+ verify(logger, times(1)).debug("Removing whitespace");
+ verify(logger, times(1)).debug(cleanedInputString, inputString.replaceAll("\\s", ""));
+
+ //symbols
+ cipher.preserveCapitals = true;
+ cipher.preserveWhitespace = true;
+ cipher.preserveSymbols = false;
+ inputString = "input String*";
+ cipher.setInputString(inputString);
+ assertEquals(inputString.replaceAll("[^a-zA-Z\\s]", ""), cipher.inputString);
+ verify(logger, times(4)).debug(originalInputString, inputString);
+ verify(logger, times(1)).debug("Removing symbols");
+ verify(logger, times(1)).debug(cleanedInputString, inputString.replaceAll("[^a-zA-Z\\s]", ""));
}
+
@Test
- public void testNoSymbolDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
- ADFGX cipher = new ADFGX(true, true, false);
-
- //Test lowercase decoding
- String inputString = "aagagadfagaxxdaxdxadafafxddgdf";
- String squareKeyword = "SquareKeyword";
- String keyword = "keyword";
- String correctOutput = "messagetoencode";
- String output = cipher.decode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
- //Test uppercase decoding
- inputString = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "MESSAGETOENCODE";
- output = cipher.decode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
-
- //Test whitespace decoding
- inputString = "aagagadfagaxxd axdx adafafxddgdf";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "message to encode";
- output = cipher.decode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
-
- //Test symbol decoding
- inputString = "aagagadfagaxxd*axdx+adafafxddgdf-";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "messagetoencode";
- output = cipher.decode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
-
- //Test mixed case, whitespace, and symbol decoding
- inputString = "AAgagadfagaxxd axdx^adafafxddgdf";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "Message toencode";
- output = cipher.decode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
+ public void testFormatOutputStringEncode(){
+ //TODO:
}
+
@Test
- public void testNoCapitalWhitespaceSymbolDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
- ADFGX cipher = new ADFGX(false, false, false);
+ public void formatOutputStringDecode(){
+ //TODO:
+ }
- //Test lowercase decoding
- String inputString = "aagagadfagaxxdaxdxadafafxddgdf";
- String squareKeyword = "SquareKeyword";
- String keyword = "keyword";
- String correctOutput = "MESSAGETOENCODE";
- String output = cipher.decode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
- //Test uppercase decoding
- inputString = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "MESSAGETOENCODE";
- output = cipher.decode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
+ @Test
+ public void testEncodePrivate(){
+ //TODO:
+ }
- //Test whitespace decoding
- inputString = "aagagadfagaxxd axdx adafafxddgdf";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "MESSAGETOENCODE";
- output = cipher.decode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
+ @Test
+ public void testDecodePrivate(){
+ //TODO:
+ }
- //Test symbol decoding
- inputString = "aagagadfagaxxd*axdx+adafafxddgdf-";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "MESSAGETOENCODE";
- output = cipher.decode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
+ @Test
+ public void testConstructors(){
+ //TODO:
+ }
- //Test mixed case, whitespace, and symbol decoding
- inputString = "AAgagadfagaxxd axdx^adafafxddgdf";
- squareKeyword = "SquareKeyword";
- keyword = "keyword";
- correctOutput = "MESSAGETOENCODE";
- output = cipher.decode(squareKeyword, keyword, inputString);
- assertEquals(correctOutput, output);
+ @Test
+ public void testGetters(){
+ //TODO:
+ }
+
+ @Test
+ public void testReset(){
+ //TODO:
+ }
+
+ @Test
+ public void testPracticalEncoding(){
+ //Test as original
+ cipher.preserveCapitals = true;
+ cipher.preserveWhitespace = true;
+ cipher.preserveSymbols = true;
+ String output = cipher.encode("SquareKeyword", "keyword", "Message to^encode");
+ assertEquals("AAgagadfagaxxd axdx^adafafxddgdf", output);
+
+ //Test fully cleaned
+ cipher.preserveCapitals = false;
+ cipher.preserveWhitespace = false;
+ cipher.preserveSymbols = false;
+ output = cipher.encode("SquareKeyword", "keyword", "Message to^encode");
+ assertEquals("AAGAGADFAGAXXDAXDXADAFAFXDDGDF", output);
+ }
+
+ @Test
+ public void testPracticalDecoding(){
+ //Test as original
+ cipher.preserveCapitals = true;
+ cipher.preserveWhitespace = true;
+ cipher.preserveSymbols = true;
+ String output = cipher.decode("SquareKeyword", "keyword", "AAgagadfagaxxd axdx^adafafxddgdf");
+ assertEquals("Message to^encode", output);
+
+ //Test fully cleaned
+ cipher.preserveCapitals = false;
+ cipher.preserveWhitespace = false;
+ cipher.preserveSymbols = false;
+ output = cipher.decode("SquareKeyword", "keyword", "AAgagadfagaxxd axdx^adafafxddgdf");
+ assertEquals("MESSAGETOENCODE", output);
}
}
diff --git a/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidBaseException.java b/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidBaseException.java
new file mode 100644
index 0000000..45f038a
--- /dev/null
+++ b/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidBaseException.java
@@ -0,0 +1,37 @@
+//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidBaseException.java
+//Mattrixwv
+// Created: 04-14-23
+//Modified: 04-14-23
+package com.mattrixwv.cipherstream.exceptions;
+
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import org.junit.jupiter.api.Test;
+
+
+public class TestInvalidBaseException{
+ private String message = "message";
+ private Throwable cause = new Exception();
+
+
+ @Test
+ public void testConstructors(){
+ InvalidBaseException exception = new InvalidBaseException();
+ assertNull(exception.getMessage());
+ assertNull(exception.getCause());
+
+ exception = new InvalidBaseException(message);
+ assertEquals(message, exception.getMessage());
+ assertNull(exception.getCause());
+
+ exception = new InvalidBaseException(cause);
+ assertEquals(cause.toString(), exception.getMessage());
+ assertEquals(cause, exception.getCause());
+
+ exception = new InvalidBaseException(message, cause);
+ assertEquals(message, exception.getMessage());
+ assertEquals(cause, exception.getCause());
+ }
+}
diff --git a/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidCharacterException.java b/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidCharacterException.java
new file mode 100644
index 0000000..cc82831
--- /dev/null
+++ b/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidCharacterException.java
@@ -0,0 +1,37 @@
+//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidcharacterException.java
+//Mattrixwv
+// Created: 04-14-23
+//Modified: 04-14-23
+package com.mattrixwv.cipherstream.exceptions;
+
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import org.junit.jupiter.api.Test;
+
+
+public class TestInvalidCharacterException{
+ private String message = "message";
+ private Throwable cause = new Exception();
+
+
+ @Test
+ public void testConstructors(){
+ InvalidCharacterException exception = new InvalidCharacterException();
+ assertNull(exception.getMessage());
+ assertNull(exception.getCause());
+
+ exception = new InvalidCharacterException(message);
+ assertEquals(message, exception.getMessage());
+ assertNull(exception.getCause());
+
+ exception = new InvalidCharacterException(cause);
+ assertEquals(cause.toString(), exception.getMessage());
+ assertEquals(cause, exception.getCause());
+
+ exception = new InvalidCharacterException(message, cause);
+ assertEquals(message, exception.getMessage());
+ assertEquals(cause, exception.getCause());
+ }
+}
diff --git a/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidInputException.java b/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidInputException.java
new file mode 100644
index 0000000..1aeefb0
--- /dev/null
+++ b/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidInputException.java
@@ -0,0 +1,37 @@
+//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/exception/TestInvalidInputException.java
+//Mattrixwv
+// Created: 04-14-23
+//Modified: 04-14-23
+package com.mattrixwv.cipherstream.exceptions;
+
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import org.junit.jupiter.api.Test;
+
+
+public class TestInvalidInputException{
+ private String message = "message";
+ private Throwable cause = new Exception();
+
+
+ @Test
+ public void testConstructors(){
+ InvalidInputException exception = new InvalidInputException();
+ assertNull(exception.getMessage());
+ assertNull(exception.getCause());
+
+ exception = new InvalidInputException(message);
+ assertEquals(message, exception.getMessage());
+ assertNull(exception.getCause());
+
+ exception = new InvalidInputException(cause);
+ assertEquals(cause.toString(), exception.getMessage());
+ assertEquals(cause, exception.getCause());
+
+ exception = new InvalidInputException(message, cause);
+ assertEquals(message, exception.getMessage());
+ assertEquals(cause, exception.getCause());
+ }
+}
diff --git a/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidKeyException.java b/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidKeyException.java
new file mode 100644
index 0000000..ef7e2b1
--- /dev/null
+++ b/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidKeyException.java
@@ -0,0 +1,37 @@
+//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidKeyException.java
+//Mattrixwv
+// Created: 04-14-23
+//Modified: 04-14-23
+package com.mattrixwv.cipherstream.exceptions;
+
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import org.junit.jupiter.api.Test;
+
+
+public class TestInvalidKeyException{
+ public String message = "message";
+ public Throwable cause = new Exception();
+
+
+ @Test
+ public void testConstructors(){
+ InvalidKeyException exception = new InvalidKeyException();
+ assertNull(exception.getMessage());
+ assertNull(exception.getCause());
+
+ exception = new InvalidKeyException(message);
+ assertEquals(message, exception.getMessage());
+ assertNull(exception.getCause());
+
+ exception = new InvalidKeyException(cause);
+ assertEquals(cause.toString(), exception.getMessage());
+ assertEquals(cause, exception.getCause());
+
+ exception = new InvalidKeyException(message, cause);
+ assertEquals(message, exception.getMessage());
+ assertEquals(cause, exception.getCause());
+ }
+}
diff --git a/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidKeywordException.java b/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidKeywordException.java
new file mode 100644
index 0000000..26222cf
--- /dev/null
+++ b/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidKeywordException.java
@@ -0,0 +1,37 @@
+//CipherStreamJava/src/test/java/com/mattrixwv/cipherstream/exceptions/TestInvalidKeywordException.java
+//Mattrixwv
+// Created: 04-14-23
+//Modified: 04-14-23
+package com.mattrixwv.cipherstream.exceptions;
+
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import org.junit.jupiter.api.Test;
+
+
+public class TestInvalidKeywordException{
+ private String message = "message";
+ private Throwable cause = new Exception();
+
+
+ @Test
+ public void testConstructor(){
+ InvalidKeywordException exception = new InvalidKeywordException();
+ assertNull(exception.getMessage());
+ assertNull(exception.getCause());
+
+ exception = new InvalidKeywordException(message);
+ assertEquals(message, exception.getMessage());
+ assertNull(exception.getCause());
+
+ exception = new InvalidKeywordException(cause);
+ assertEquals(cause.toString(), exception.getMessage());
+ assertEquals(cause, exception.getCause());
+
+ exception = new InvalidKeywordException(message, cause);
+ assertEquals(message, exception.getMessage());
+ assertEquals(cause, exception.getCause());
+ }
+}