Update test coverage

This commit is contained in:
2023-04-14 19:01:58 -04:00
parent bd086a2ab3
commit 575ff04ecd
8 changed files with 405 additions and 446 deletions

67
pom.xml
View File

@@ -6,7 +6,7 @@
<groupId>com.mattrixwv</groupId> <groupId>com.mattrixwv</groupId>
<artifactId>cipher-stream-java</artifactId> <artifactId>cipher-stream-java</artifactId>
<version>1.1.0</version> <version>1.2.0</version>
<name>CipherStreamJava</name> <name>CipherStreamJava</name>
<url>http://www.mattrixwv.com</url> <url>http://www.mattrixwv.com</url>
@@ -14,12 +14,13 @@
<properties> <properties>
<!--Compile--> <!--Compile-->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>19</maven.compiler.source> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.target>19</maven.compiler.target> <maven.compiler.source>20</maven.compiler.source>
<java.version>19</java.version> <maven.compiler.target>20</maven.compiler.target>
<java.version>20</java.version>
<!--Sonarqube--> <!--Sonarqube-->
<sonar.java.source>19</sonar.java.source> <sonar.java.source>20</sonar.java.source>
<sonar.dependencyCheck.jsonReportPath>target/dependency-check-report.json</sonar.dependencyCheck.jsonReportPath> <sonar.dependencyCheck.jsonReportPath>target/dependency-check-report.json</sonar.dependencyCheck.jsonReportPath>
<sonar.dependencyCheck.htmlReportPath>target/dependency-check-report.html</sonar.dependencyCheck.htmlReportPath> <sonar.dependencyCheck.htmlReportPath>target/dependency-check-report.html</sonar.dependencyCheck.htmlReportPath>
</properties> </properties>
@@ -28,28 +29,47 @@
<dependency> <dependency>
<groupId>mattrixwv</groupId> <groupId>mattrixwv</groupId>
<artifactId>myClasses</artifactId> <artifactId>myClasses</artifactId>
<version>1.2.0</version> <version>1.3.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.mattrixwv</groupId> <groupId>com.mattrixwv</groupId>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<version>1.0.1</version> <version>1.1.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
<version>2.0.6</version> <version>2.0.7</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>2.0.7</version>
<scope>test</scope>
</dependency> </dependency>
<!--Test--> <!--Test-->
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId> <artifactId>junit-jupiter-api</artifactId>
<version>5.9.1</version> <version>5.9.2</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.3.0</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>5.3.0</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
@@ -58,7 +78,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId> <artifactId>maven-enforcer-plugin</artifactId>
<version>3.1.0</version> <version>3.3.0</version>
<executions> <executions>
<execution> <execution>
<id>enforce-maven</id> <id>enforce-maven</id>
@@ -83,46 +103,51 @@
<!--Default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging--> <!--Default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging-->
<plugin> <plugin>
<artifactId>maven-resources-plugin</artifactId> <artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version> <version>3.3.1</version>
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version> <version>3.11.0</version>
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version> <version>3.0.0</version>
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version> <version>3.3.0</version>
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-install-plugin</artifactId> <artifactId>maven-install-plugin</artifactId>
<version>3.0.0-M1</version> <version>3.1.1</version>
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-deploy-plugin</artifactId> <artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M1</version> <version>3.1.1</version>
</plugin> </plugin>
<!--Site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle--> <!--Site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle-->
<plugin> <plugin>
<artifactId>maven-site-plugin</artifactId> <artifactId>maven-site-plugin</artifactId>
<version>3.12.0</version> <version>3.12.1</version>
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-project-info-reports-plugin</artifactId> <artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.3.0</version> <version>3.4.2</version>
</plugin> </plugin>
<!--Versions--> <!--Versions-->
<plugin> <plugin>
<groupId>org.codehaus.mojo</groupId> <groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId> <artifactId>versions-maven-plugin</artifactId>
<version>2.11.0</version> <version>2.15.0</version>
<configuration> <configuration>
<rulesUri>file://${session.executionRootDirectory}/version-rules.xml</rulesUri> <rulesUri>file://${session.executionRootDirectory}/version-rules.xml</rulesUri>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.5.0</version>
</plugin>
<!--Sonarqube--> <!--Sonarqube-->
<plugin> <plugin>
<groupId>org.sonarsource.scanner.maven</groupId> <groupId>org.sonarsource.scanner.maven</groupId>
@@ -132,7 +157,7 @@
<plugin> <plugin>
<groupId>org.jacoco</groupId> <groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId> <artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.8</version> <version>0.8.9</version>
<executions> <executions>
<execution> <execution>
<id>jacoco-initialize</id> <id>jacoco-initialize</id>
@@ -153,7 +178,7 @@
<plugin> <plugin>
<groupId>org.owasp</groupId> <groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId> <artifactId>dependency-check-maven</artifactId>
<version>7.1.1</version> <version>8.2.1</version>
<executions> <executions>
<execution> <execution>
<phase>none</phase> <phase>none</phase>

View File

@@ -16,23 +16,23 @@ import com.mattrixwv.cipherstream.polysubstitution.PolybiusSquare;
public class ADFGX{ public class ADFGX{
private static final Logger logger = LoggerFactory.getLogger(ADFGX.class); protected static Logger logger = LoggerFactory.getLogger(ADFGX.class);
//Internal fields //Internal fields
private String inputString; //The string that needs encoded/decoded protected String inputString; //The string that needs encoded/decoded
private String outputString; //The string that is output after encoding/decoding protected String outputString; //The string that is output after encoding/decoding
private String squareKeyword; //The keyword used in the Polybius Square protected String squareKeyword; //The keyword used in the Polybius Square
private String keyword; //The keyword used in the Columnar cipher protected String keyword; //The keyword used in the Columnar cipher
private boolean preserveCapitals; //Whether to respect capitals in the output string protected boolean preserveCapitals; //Whether to respect capitals in the output string
private boolean preserveWhitespace; //Whether to respect whitespace in the output string protected boolean preserveWhitespace; //Whether to respect whitespace in the output string
private boolean preserveSymbols; //Whether to respect symbols in the output string protected boolean preserveSymbols; //Whether to respect symbols in the output string
//Internal ciphers //Internal ciphers
private PolybiusSquare polybiusSquare; //The first step in encoding protected PolybiusSquare polybiusSquare; //The first step in encoding
private Columnar columnar; //The second step in encoding protected Columnar columnar; //The second step in encoding
//Ensures Polybius keyword constraints //Ensures Polybius keyword constraints
private void setSquareKeyword(String squareKeyword) throws InvalidKeywordException{ protected void setSquareKeyword(String squareKeyword) throws InvalidKeywordException{
if(squareKeyword == null){ if(squareKeyword == null){
throw new InvalidKeywordException("Square keyword cannot be null"); throw new InvalidKeywordException("Square keyword cannot be null");
} }
@@ -41,7 +41,7 @@ public class ADFGX{
this.squareKeyword = squareKeyword; this.squareKeyword = squareKeyword;
} }
//Ensures Columnar keyword constraints //Ensures Columnar keyword constraints
private void setKeyword(String keyword) throws InvalidKeywordException{ protected void setKeyword(String keyword) throws InvalidKeywordException{
if(keyword == null){ if(keyword == null){
throw new InvalidKeywordException("Keyword cannot be null"); throw new InvalidKeywordException("Keyword cannot be null");
} }
@@ -50,7 +50,7 @@ public class ADFGX{
this.keyword = keyword; this.keyword = keyword;
} }
//Ensures inputString constraints //Ensures inputString constraints
private void setInputString(String inputString) throws InvalidInputException{ protected void setInputString(String inputString) throws InvalidInputException{
if(inputString == null){ if(inputString == null){
throw new InvalidInputException("Input cannot be null"); throw new InvalidInputException("Input cannot be null");
} }
@@ -80,7 +80,7 @@ public class ADFGX{
logger.debug("cleaned input string '{}'", inputString); logger.debug("cleaned input string '{}'", inputString);
} }
//Format the output string with capitals, symbols, and numbers that are in the input string //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"); logger.debug("Formatting output string to match input string");
StringBuilder output = new StringBuilder(); StringBuilder output = new StringBuilder();
@@ -109,7 +109,7 @@ public class ADFGX{
logger.debug("Saving output string '{}'", outputString); logger.debug("Saving output string '{}'", outputString);
outputString = output.toString(); outputString = output.toString();
} }
private void formatOutputStringDecode(){ protected void formatOutputStringDecode(){
logger.debug("Formatting output string to match input string"); logger.debug("Formatting output string to match input string");
StringBuilder output = new StringBuilder(); StringBuilder output = new StringBuilder();
int outputLocation = 0; int outputLocation = 0;
@@ -139,7 +139,7 @@ public class ADFGX{
outputString = output.toString(); outputString = output.toString();
} }
//Encodes the inputString and stores the result in outputString //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 //Encode the input with polybius
logger.debug("Encoding using Polybius Square"); logger.debug("Encoding using Polybius Square");
String polybiusOutput = polybiusSquare.encode(squareKeyword, inputString); String polybiusOutput = polybiusSquare.encode(squareKeyword, inputString);
@@ -158,7 +158,7 @@ public class ADFGX{
formatOutputStringEncode(); formatOutputStringEncode();
} }
//Decodes the inputString and stores the result in outputString //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 //Decode the input with columnar
logger.debug("Decoding using columnar"); logger.debug("Decoding using columnar");
String columnarOutput = columnar.decode(keyword, inputString); String columnarOutput = columnar.decode(keyword, inputString);

View File

@@ -1,450 +1,199 @@
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamjava/combination/TestADFGX.java //CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamjava/combination/TestADFGX.java
//Mattrixwv //Mattrixwv
// Created: 01-25-22 // Created: 01-25-22
//Modified: 07-09-22 //Modified: 04-14-23
package com.mattrixwv.cipherstream.combination; package com.mattrixwv.cipherstream.combination;
import static org.junit.jupiter.api.Assertions.assertEquals; 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.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.InvalidInputException;
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException; import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
@ExtendWith(MockitoExtension.class)
public class TestADFGX{ public class TestADFGX{
@Test private ADFGX cipher;
public void testEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{ private Logger logger;
ADFGX cipher = new ADFGX(true, 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 @BeforeEach
inputString = "message to encode"; public void setup(){
squareKeyword = "SquareKeyword"; cipher = new ADFGX();
keyword = "keyword"; logger = mock(Logger.class);
correctOutput = "aagagadfagaxxd axdx adafafxddgdf"; ADFGX.logger = logger;
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);
} }
@Test @Test
public void testDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{ public void testSetSquareKeyword(){
ADFGX cipher = new ADFGX(true, true, true); assertThrows(InvalidKeywordException.class, () -> {
cipher.setSquareKeyword(null);
});
assertEquals("", cipher.squareKeyword);
verify(logger, never()).debug(anyString(), anyString());
//Test lowercase decoding String squareKeyword = "squareKeyword";
String inputString = "aagagadfagaxxdaxdxadafafxddgdf"; cipher.setSquareKeyword(squareKeyword);
String squareKeyword = "SquareKeyword"; assertEquals(squareKeyword, cipher.squareKeyword);
String keyword = "keyword"; verify(logger, times(1)).debug("squareKeyword = {}", squareKeyword);
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);
} }
@Test @Test
public void testNoCapitalDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{ public void testSetKeyword(){
ADFGX cipher = new ADFGX(false, true, true); 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 keyword = "keyword";
String correctOutput = "MESSAGETOENCODE"; cipher.setKeyword(keyword);
String output = cipher.decode(squareKeyword, keyword, inputString); assertEquals(keyword, cipher.keyword);
assertEquals(correctOutput, output); verify(logger, times(1)).debug("keyword = {}", keyword);
//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);
} }
@Test @Test
public void testNoWhitespaceDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{ public void testSetInputString(){
ADFGX cipher = new ADFGX(true, false, true); //Null input
assertThrows(InvalidInputException.class, () -> {
cipher.setInputString(null);
});
assertEquals("", cipher.inputString);
verify(logger, never()).debug(anyString(), anyString());
//Test lowercase decoding String originalInputString = "original input string '{}'";
String inputString = "aagagadfagaxxdaxdxadafafxddgdf"; String cleanedInputString = "cleaned input string '{}'";
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 //Blank input
inputString = "aagagadfagaxxd axdx adafafxddgdf"; cipher.preserveCapitals = true;
squareKeyword = "SquareKeyword"; cipher.preserveSymbols = true;
keyword = "keyword"; cipher.preserveWhitespace = true;
correctOutput = "messagetoencode"; assertThrows(InvalidInputException.class, () -> {
output = cipher.decode(squareKeyword, keyword, inputString); cipher.setInputString("");
assertEquals(correctOutput, output); });
assertEquals("", cipher.inputString);
verify(logger, times(1)).debug(originalInputString, "");
//Test symbol decoding //No options
inputString = "aagagadfagaxxd*axdx+adafafxddgdf-"; String inputString = "input String*";
squareKeyword = "SquareKeyword"; cipher.setInputString(inputString);
keyword = "keyword"; assertEquals(inputString, cipher.inputString);
correctOutput = "message*to+encode-"; verify(logger, times(1)).debug(originalInputString, inputString);
output = cipher.decode(squareKeyword, keyword, inputString); verify(logger, times(1)).debug(cleanedInputString, inputString);
assertEquals(correctOutput, output);
//Test mixed case, whitespace, and symbol decoding //capitals
inputString = "AAgagadfagaxxd axdx^adafafxddgdf"; cipher.preserveCapitals = false;
squareKeyword = "SquareKeyword"; cipher.preserveWhitespace = true;
keyword = "keyword"; cipher.preserveSymbols = true;
correctOutput = "Messageto^encode"; inputString = "input String*";
output = cipher.decode(squareKeyword, keyword, inputString); cipher.setInputString(inputString);
assertEquals(correctOutput, output); 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 @Test
public void testNoSymbolDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{ public void testFormatOutputStringEncode(){
ADFGX cipher = new ADFGX(true, true, false); //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 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);
} }
@Test @Test
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{ public void formatOutputStringDecode(){
ADFGX cipher = new ADFGX(false, false, false); //TODO:
}
//Test lowercase decoding @Test
String inputString = "aagagadfagaxxdaxdxadafafxddgdf"; public void testEncodePrivate(){
String squareKeyword = "SquareKeyword"; //TODO:
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 @Test
inputString = "aagagadfagaxxd axdx adafafxddgdf"; public void testDecodePrivate(){
squareKeyword = "SquareKeyword"; //TODO:
keyword = "keyword"; }
correctOutput = "MESSAGETOENCODE";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test symbol decoding @Test
inputString = "aagagadfagaxxd*axdx+adafafxddgdf-"; public void testConstructors(){
squareKeyword = "SquareKeyword"; //TODO:
keyword = "keyword"; }
correctOutput = "MESSAGETOENCODE";
output = cipher.decode(squareKeyword, keyword, inputString);
assertEquals(correctOutput, output);
//Test mixed case, whitespace, and symbol decoding @Test
inputString = "AAgagadfagaxxd axdx^adafafxddgdf"; public void testGetters(){
squareKeyword = "SquareKeyword"; //TODO:
keyword = "keyword"; }
correctOutput = "MESSAGETOENCODE";
output = cipher.decode(squareKeyword, keyword, inputString); @Test
assertEquals(correctOutput, output); 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);
} }
} }

View File

@@ -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());
}
}

View File

@@ -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());
}
}

View File

@@ -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());
}
}

View File

@@ -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());
}
}

View File

@@ -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());
}
}