Added logging
This commit is contained in:
40
pom.xml
40
pom.xml
@@ -22,19 +22,26 @@
|
||||
<dependency>
|
||||
<groupId>mattrixwv</groupId>
|
||||
<artifactId>myClasses</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mattrixwv</groupId>
|
||||
<artifactId>matrix</artifactId>
|
||||
<version>1.0</version>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.2</version>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.36</version>
|
||||
</dependency>
|
||||
|
||||
<!--Test-->
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.8.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
@@ -45,7 +52,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>3.0.0-M3</version>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>enforce-maven</id>
|
||||
@@ -55,7 +62,7 @@
|
||||
<configuration>
|
||||
<rules>
|
||||
<requireMavenVersion>
|
||||
<version>3.6.3</version>
|
||||
<version>3.8.6</version>
|
||||
</requireMavenVersion>
|
||||
</rules>
|
||||
</configuration>
|
||||
@@ -65,7 +72,7 @@
|
||||
<!--Clean lifecycle, see https://maven.apache.org/ref/current/maven-core-lifecycles.html#clean_Lifecycle-->
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.2.0</version>
|
||||
</plugin>
|
||||
<!--Default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging-->
|
||||
<plugin>
|
||||
@@ -74,7 +81,7 @@
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<version>3.10.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
@@ -82,7 +89,7 @@
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<version>3.2.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
@@ -95,11 +102,20 @@
|
||||
<!--Site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle-->
|
||||
<plugin>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>3.9.1</version>
|
||||
<version>3.12.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<version>3.3.0</version>
|
||||
</plugin>
|
||||
<!--Versions-->
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>versions-maven-plugin</artifactId>
|
||||
<version>2.11.0</version>
|
||||
<configuration>
|
||||
<rulesUri>file://${session.executionRootDirectory}/version-rules.xml</rulesUri>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!--Sonar-->
|
||||
<plugin>
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/combination/ADFGVX.java
|
||||
//Mattrixwv
|
||||
// Created: 01-26-22
|
||||
//Modified: 07-03-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.combination;
|
||||
|
||||
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
@@ -15,9 +18,16 @@ import com.mattrixwv.cipherstream.polysubstitution.PolybiusSquare;
|
||||
|
||||
|
||||
public class ADFGVX{
|
||||
private static final Logger logger = LoggerFactory.getLogger(ADFGVX.class);
|
||||
|
||||
//Internal classes
|
||||
private class LargePolybiusSquare extends PolybiusSquare{
|
||||
private static final Logger logger = LoggerFactory.getLogger(LargePolybiusSquare.class);
|
||||
|
||||
@Override
|
||||
protected void createGrid(){
|
||||
logger.debug("Creating grid");
|
||||
|
||||
for(int row = 0;row < 6;++row){
|
||||
for(int col = 0;col < 6;++col){
|
||||
char letter = keyword.charAt((6 * row) + col);
|
||||
@@ -31,16 +41,22 @@ public class ADFGVX{
|
||||
throw new NullPointerException("Input cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Original input string '{}'", inputString);
|
||||
|
||||
//Change to upper case
|
||||
inputString = inputString.toUpperCase();
|
||||
|
||||
//Remove any whitespace if selected
|
||||
if(!preserveWhitespace){
|
||||
logger.debug("Removing whitespace");
|
||||
|
||||
inputString = inputString.replaceAll("\\s", "");
|
||||
}
|
||||
|
||||
//Remove any symbols if selected
|
||||
if(!preserveSymbols){
|
||||
logger.debug("Removing symbols");
|
||||
|
||||
inputString = inputString.replaceAll("[^a-zA-Z0-9\\s]", "");
|
||||
}
|
||||
|
||||
@@ -56,14 +72,21 @@ public class ADFGVX{
|
||||
//Save the string
|
||||
this.inputString = inputString;
|
||||
|
||||
logger.debug("Cleaned input string '{}'", inputString);
|
||||
|
||||
if(this.inputString.isBlank() || getPreparedInputStringEncoding().isBlank()){
|
||||
throw new InvalidInputException("Input must contain at least 1 letter");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected String getPreparedInputStringEncoding(){
|
||||
logger.debug("Preparing input string for encoding");
|
||||
|
||||
String cleanString = inputString.toUpperCase();
|
||||
cleanString = cleanString.replaceAll("[^A-Z0-9]", "");
|
||||
|
||||
logger.debug("Cleaned input string '{}'", cleanString);
|
||||
|
||||
return cleanString;
|
||||
}
|
||||
@Override
|
||||
@@ -71,6 +94,9 @@ public class ADFGVX{
|
||||
if(keyword == null){
|
||||
throw new NullPointerException("Keyword cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Original keyword '{}'", keyword);
|
||||
|
||||
//Change everything to uppercase
|
||||
keyword = keyword.toUpperCase();
|
||||
|
||||
@@ -85,45 +111,67 @@ public class ADFGVX{
|
||||
keyword.chars().distinct().forEach(c -> uniqueKey.append((char)c));
|
||||
this.keyword = uniqueKey.toString();
|
||||
|
||||
logger.debug("Cleaned keyword '{}'", keyword);
|
||||
|
||||
//Create the grid from the sanitized keyword
|
||||
createGrid();
|
||||
}
|
||||
@Override
|
||||
protected void addCharactersToCleanStringEncode(String cleanString){
|
||||
logger.debug("Formatting output string");
|
||||
|
||||
int outputCnt = 0;
|
||||
StringBuilder fullOutput = new StringBuilder();
|
||||
for(int inputCnt = 0;inputCnt < inputString.length();++inputCnt){
|
||||
logger.debug("Current character {}", inputString.charAt(inputCnt));
|
||||
|
||||
//Add both numbers of any letters to the output
|
||||
if(Character.isAlphabetic(inputString.charAt(inputCnt)) || Character.isDigit(inputString.charAt(inputCnt))){
|
||||
logger.debug("Appending character");
|
||||
|
||||
fullOutput.append(cleanString.charAt(outputCnt++));
|
||||
fullOutput.append(cleanString.charAt(outputCnt++));
|
||||
}
|
||||
//Add any other characters that appear to the output
|
||||
else{
|
||||
logger.debug("Appending symbol");
|
||||
|
||||
fullOutput.append(inputString.charAt(inputCnt));
|
||||
}
|
||||
}
|
||||
|
||||
outputString = fullOutput.toString();
|
||||
}
|
||||
@Override
|
||||
protected void addCharactersToCleanStringDecode(String cleanString){
|
||||
logger.debug("Formatting output string");
|
||||
|
||||
int outputCnt = 0;
|
||||
StringBuilder fullOutput = new StringBuilder();
|
||||
for(int inputCnt = 0;inputCnt < inputString.length();++inputCnt){
|
||||
logger.debug("Current character {}", inputString.charAt(inputCnt));
|
||||
|
||||
//Add the letter to the output and skip the second number
|
||||
if(Character.isDigit(inputString.charAt(inputCnt)) || Character.isAlphabetic(inputString.charAt(inputCnt))){
|
||||
logger.debug("Appending character");
|
||||
|
||||
fullOutput.append(cleanString.charAt(outputCnt++));
|
||||
++inputCnt;
|
||||
}
|
||||
//Add any other characters that appear to the output
|
||||
else{
|
||||
logger.debug("Appending symbol");
|
||||
|
||||
fullOutput.append(inputString.charAt(inputCnt));
|
||||
}
|
||||
}
|
||||
|
||||
outputString = fullOutput.toString();
|
||||
}
|
||||
@Override
|
||||
public void reset(){
|
||||
logger.debug("reseting");
|
||||
|
||||
grid = new char[6][6];
|
||||
inputString = "";
|
||||
outputString = "";
|
||||
@@ -134,55 +182,77 @@ public class ADFGVX{
|
||||
super(preserveWhitespace, preserveSymbols);
|
||||
}
|
||||
}
|
||||
private boolean preserveCapitals;
|
||||
private boolean preserveWhitespace;
|
||||
private boolean preserveSymbols;
|
||||
private String inputString;
|
||||
private String outputString;
|
||||
private String squareKeyword;
|
||||
private String keyword;
|
||||
private LargePolybiusSquare largePolybiusSquare;
|
||||
private Columnar columnar;
|
||||
//Fields
|
||||
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
|
||||
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
|
||||
//Internal ciphers
|
||||
private LargePolybiusSquare largePolybiusSquare; //The first step in encoding
|
||||
private Columnar columnar; //The second step in encoding
|
||||
|
||||
|
||||
//Ensures Polybius keyword constraints
|
||||
private void setSquareKeyword(String squareKeyword) throws InvalidKeywordException{
|
||||
if(squareKeyword == null){
|
||||
throw new InvalidKeywordException("Square Keyword cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Square Keyword '{}'", squareKeyword);
|
||||
this.squareKeyword = squareKeyword;
|
||||
}
|
||||
//Ensures Columnar keyword constraints
|
||||
private void setKeyword(String keyword) throws InvalidKeywordException{
|
||||
if(keyword == null){
|
||||
throw new InvalidKeywordException("Keyword cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Keyword '{}'", keyword);
|
||||
this.keyword = keyword;
|
||||
}
|
||||
//Ensures inputString constraints
|
||||
private void setInputString(String inputString) throws InvalidInputException{
|
||||
if(inputString == null){
|
||||
throw new InvalidInputException("Input cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Original input string '{}'", inputString);
|
||||
|
||||
if(!preserveCapitals){
|
||||
logger.debug("Removing capitals");
|
||||
|
||||
inputString = inputString.toUpperCase();
|
||||
}
|
||||
if(!preserveWhitespace){
|
||||
logger.debug("Removing whitespace");
|
||||
|
||||
inputString = inputString.replaceAll("\\s", "");
|
||||
}
|
||||
if(!preserveSymbols){
|
||||
logger.debug("Removing symbols");
|
||||
|
||||
inputString = inputString.replaceAll("[^a-zA-Z\\s]", "");
|
||||
}
|
||||
|
||||
this.inputString = inputString;
|
||||
|
||||
logger.debug("Cleaned input string '{}'", inputString);
|
||||
|
||||
if(this.inputString.isBlank()){
|
||||
throw new InvalidInputException("Input cannot be blank");
|
||||
}
|
||||
}
|
||||
//Format the output string with capitals, symbols, and numbers that are in the input string
|
||||
private void formatOutputStringEncode(){
|
||||
logger.debug("Formatting output string");
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
int outputLocation = 0;
|
||||
for(char ch : inputString.toCharArray()){
|
||||
logger.debug("Input string {}", ch);
|
||||
if(Character.isUpperCase(ch)){
|
||||
output.append(Character.toUpperCase(outputString.charAt(outputLocation++)));
|
||||
output.append(Character.toUpperCase(outputString.charAt(outputLocation++)));
|
||||
@@ -196,13 +266,17 @@ public class ADFGVX{
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Saving output string '{}'", output);
|
||||
outputString = output.toString();
|
||||
}
|
||||
private void formatOutputStringDecode(){
|
||||
logger.debug("Formatting output string");
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
int outputLocation = 0;
|
||||
for(int inputLocation = 0;inputLocation < inputString.length();++inputLocation){
|
||||
char ch = inputString.charAt(inputLocation);
|
||||
logger.debug("Input character {}", ch);
|
||||
if(Character.isUpperCase(ch)){
|
||||
output.append(Character.toUpperCase(outputString.charAt(outputLocation++)));
|
||||
++inputLocation;
|
||||
@@ -215,15 +289,21 @@ public class ADFGVX{
|
||||
output.append(ch);
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Saving output string '{}'", output);
|
||||
outputString = output.toString();
|
||||
}
|
||||
//Encodes the inputString and stores the result in outputString
|
||||
private String encode() throws InvalidCharacterException, InvalidInputException, InvalidKeywordException{
|
||||
//Encode the input with polybius
|
||||
logger.debug("Encoding using Polybius Square");
|
||||
String polybiusOutput = largePolybiusSquare.encode(squareKeyword, inputString);
|
||||
//Change polybius to use the correct symbols
|
||||
logger.debug("Replacing coordinates with letters");
|
||||
polybiusOutput = polybiusOutput.replace("1", "A").replace("2", "D").replace("3", "F").replace("4", "G").replace("5", "V").replace("6", "X");
|
||||
|
||||
//Encode polybius's output with columnar
|
||||
logger.debug("Encoding with columnar");
|
||||
String columnarOutput = columnar.encode(keyword, polybiusOutput);
|
||||
outputString = columnarOutput;
|
||||
|
||||
@@ -232,13 +312,17 @@ public class ADFGVX{
|
||||
|
||||
return outputString;
|
||||
}
|
||||
//Decodes the inputString and stores the result in outputString
|
||||
private String decode() throws InvalidKeywordException, InvalidCharacterException, InvalidInputException{
|
||||
//Decode the input with columnar
|
||||
logger.debug("Decoding columnar");
|
||||
String columnarOutput = columnar.decode(keyword, inputString);
|
||||
|
||||
//Change the symbols to the correct ones for polybius
|
||||
logger.debug("Replacing characters with coordinates");
|
||||
columnarOutput = columnarOutput.replace("A", "1").replace("D", "2").replace("F", "3").replace("G", "4").replace("V", "5").replace("X", "6");
|
||||
//Decode with polybius
|
||||
logger.debug("Decoding Polybius Square");
|
||||
String polybiusOutput = largePolybiusSquare.decode(squareKeyword, columnarOutput);
|
||||
outputString = polybiusOutput;
|
||||
|
||||
@@ -248,6 +332,8 @@ public class ADFGVX{
|
||||
return outputString;
|
||||
}
|
||||
|
||||
|
||||
//Constructor
|
||||
public ADFGVX() throws InvalidCharacterException{
|
||||
preserveCapitals = false;
|
||||
preserveWhitespace = false;
|
||||
@@ -261,31 +347,41 @@ public class ADFGVX{
|
||||
reset();
|
||||
}
|
||||
|
||||
//Encodes inputString using keyword and returns the result
|
||||
public String encode(String squareKeyword, String keyword, String inputString) throws InvalidKeywordException, InvalidInputException, InvalidCharacterException{
|
||||
setSquareKeyword(squareKeyword);
|
||||
setKeyword(keyword);
|
||||
setInputString(inputString);
|
||||
return encode();
|
||||
}
|
||||
//Decodes inputString using keyword and returns the result
|
||||
public String decode(String squareKeyword, String keyword, String inputString) throws InvalidKeywordException, InvalidInputException, InvalidCharacterException{
|
||||
setSquareKeyword(squareKeyword);
|
||||
setKeyword(keyword);
|
||||
setInputString(inputString);
|
||||
return decode();
|
||||
}
|
||||
|
||||
//Returns the cleaned inputString
|
||||
public String getInputString(){
|
||||
return inputString;
|
||||
}
|
||||
//Returns the outputString
|
||||
public String getOutputString(){
|
||||
return outputString;
|
||||
}
|
||||
//Returns the cleaned Polybius Square keyword
|
||||
public String getSquareKeyword(){
|
||||
return squareKeyword;
|
||||
}
|
||||
//Returns the cleaned Columnar keyword
|
||||
public String getKeyword(){
|
||||
return keyword;
|
||||
}
|
||||
//Makes sure all of the variables are empty
|
||||
public void reset() throws InvalidCharacterException{
|
||||
logger.debug("Reseting fields");
|
||||
|
||||
largePolybiusSquare = new LargePolybiusSquare(false, false);
|
||||
columnar = new Columnar(false, false, false, true, 'B');
|
||||
inputString = "";
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/combination/ADFGX.java
|
||||
//Mattrixwv
|
||||
// Created: 01-25-22
|
||||
//Modified: 07-03-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.combination;
|
||||
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
@@ -13,22 +16,28 @@ import com.mattrixwv.cipherstream.polysubstitution.PolybiusSquare;
|
||||
|
||||
|
||||
public class ADFGX{
|
||||
private String inputString; //This is the string that needs encoded/decoded
|
||||
private String outputString; //This is the string that is output after encoding/decoding
|
||||
private String squareKeyword; //The keyword used to create the Polybius Square
|
||||
private String keyword; //The keyword used to create the Columnar cipher
|
||||
private static final 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
|
||||
//Internal ciphers
|
||||
private PolybiusSquare polybiusSquare; //The first step in encoding
|
||||
private Columnar columnar; //The second step in encoding
|
||||
|
||||
|
||||
//Ensures Polybius keyword constraints
|
||||
private void setSquareKeyword(String squareKeyword) throws InvalidKeywordException{
|
||||
if(squareKeyword == null){
|
||||
throw new InvalidKeywordException("Square Keyword cannot be null");
|
||||
throw new InvalidKeywordException("Square keyword cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("squareKeyword = {}", squareKeyword);
|
||||
this.squareKeyword = squareKeyword;
|
||||
}
|
||||
//Ensures Columnar keyword constraints
|
||||
@@ -37,6 +46,7 @@ public class ADFGX{
|
||||
throw new InvalidKeywordException("Keyword cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("keyword = {}", keyword);
|
||||
this.keyword = keyword;
|
||||
}
|
||||
//Ensures inputString constraints
|
||||
@@ -45,13 +55,20 @@ public class ADFGX{
|
||||
throw new InvalidInputException("Input cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("original input string '{}'", inputString);
|
||||
if(!preserveCapitals){
|
||||
logger.debug("Removing capitals");
|
||||
|
||||
inputString = inputString.toUpperCase();
|
||||
}
|
||||
if(!preserveWhitespace){
|
||||
logger.debug("Removing whitespace");
|
||||
|
||||
inputString = inputString.replaceAll("\\s", "");
|
||||
}
|
||||
if(!preserveSymbols){
|
||||
logger.debug("Removing symbols");
|
||||
|
||||
inputString = inputString.replaceAll("[^a-zA-Z\\s]", "");
|
||||
}
|
||||
|
||||
@@ -60,55 +77,79 @@ public class ADFGX{
|
||||
if(this.inputString.isBlank()){
|
||||
throw new InvalidInputException("Input cannot be blank");
|
||||
}
|
||||
logger.debug("cleaned input string '{}'", inputString);
|
||||
}
|
||||
//Format the output string with capitals, symbols, and numbers that are in the input string
|
||||
private void formatOutputStringEncode(){
|
||||
logger.debug("Formatting output string to match input string");
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
int outputLocation = 0;
|
||||
for(char ch : inputString.toCharArray()){
|
||||
logger.debug("Input character {}", ch);
|
||||
if(Character.isUpperCase(ch)){
|
||||
logger.debug("Converting output to uppercase");
|
||||
|
||||
output.append(Character.toUpperCase(outputString.charAt(outputLocation++)));
|
||||
output.append(Character.toUpperCase(outputString.charAt(outputLocation++)));
|
||||
}
|
||||
else if(Character.isLowerCase(ch)){
|
||||
logger.debug("Converting output to lowercase");
|
||||
|
||||
output.append(Character.toLowerCase(outputString.charAt(outputLocation++)));
|
||||
output.append(Character.toLowerCase(outputString.charAt(outputLocation++)));
|
||||
}
|
||||
else{
|
||||
logger.debug("Appending symbol to output");
|
||||
|
||||
output.append(ch);
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Saving output string '{}'", outputString);
|
||||
outputString = output.toString();
|
||||
}
|
||||
private void formatOutputStringDecode(){
|
||||
logger.debug("Formatting output string to match input string");
|
||||
StringBuilder output = new StringBuilder();
|
||||
int outputLocation = 0;
|
||||
for(int inputLocation = 0;inputLocation < inputString.length();++inputLocation){
|
||||
char ch = inputString.charAt(inputLocation);
|
||||
logger.debug("Input character {}", ch);
|
||||
if(Character.isUpperCase(ch)){
|
||||
logger.debug("Converting output to uppercase");
|
||||
|
||||
output.append(Character.toUpperCase(outputString.charAt(outputLocation++)));
|
||||
++inputLocation;
|
||||
}
|
||||
else if(Character.isLowerCase(ch)){
|
||||
logger.debug("Converting output to lowercase");
|
||||
|
||||
output.append(Character.toLowerCase(outputString.charAt(outputLocation++)));
|
||||
++inputLocation;
|
||||
}
|
||||
else{
|
||||
logger.debug("Appending symbol to output");
|
||||
|
||||
output.append(ch);
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Saving output string '{}'", output);
|
||||
outputString = output.toString();
|
||||
}
|
||||
//Encodes the inputString and stores the result in outputString
|
||||
private void encode() throws InvalidCharacterException, InvalidInputException, InvalidKeywordException{
|
||||
//Encode the input with polybius
|
||||
logger.debug("Encoding using Polybius Square");
|
||||
String polybiusOutput = polybiusSquare.encode(squareKeyword, inputString);
|
||||
squareKeyword = polybiusSquare.getKeyword();
|
||||
//Change polybius to use the correct symbols
|
||||
logger.debug("Replacing coordinates with letters");
|
||||
polybiusOutput = polybiusOutput.replace("1", "A").replace("2", "D").replace("3", "F").replace("4", "G").replace("5", "X");
|
||||
|
||||
//Encode polybius's output with columnar
|
||||
logger.debug("Encoding using columnar");
|
||||
String columnarOutput = columnar.encode(keyword, polybiusOutput);
|
||||
keyword = columnar.getKeyword();
|
||||
outputString = columnarOutput;
|
||||
@@ -119,12 +160,15 @@ public class ADFGX{
|
||||
//Decodes the inputString and stores the result in outputString
|
||||
private void decode() throws InvalidKeywordException, InvalidCharacterException, InvalidInputException{
|
||||
//Decode the input with columnar
|
||||
logger.debug("Decoding using columnar");
|
||||
String columnarOutput = columnar.decode(keyword, inputString);
|
||||
keyword = columnar.getKeyword();
|
||||
|
||||
//Change the symbols to the correct ones for polybius
|
||||
logger.debug("Replacing letters with coordinates");
|
||||
columnarOutput = columnarOutput.replace("A", "1").replace("D", "2").replace("F", "3").replace("G", "4").replace("X", "5");
|
||||
//Decode with polybius
|
||||
logger.debug("Decoding using Polybius Square");
|
||||
String polybiusOutput = polybiusSquare.decode(squareKeyword, columnarOutput);
|
||||
squareKeyword = polybiusSquare.getKeyword();
|
||||
outputString = polybiusOutput;
|
||||
@@ -183,6 +227,8 @@ public class ADFGX{
|
||||
}
|
||||
//Makes sure all of the variables are empty
|
||||
public void reset() throws InvalidCharacterException{
|
||||
logger.debug("Resetting fields");
|
||||
|
||||
polybiusSquare = new PolybiusSquare(false, false);
|
||||
columnar = new Columnar(false, false, false, true, 'B');
|
||||
inputString = "";
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/cipherstream/exceptions/InvalidKeyException.java
|
||||
//Matrixwv
|
||||
// Created: 07-09-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.exceptions;
|
||||
|
||||
|
||||
public class InvalidKeyException extends RuntimeException{
|
||||
public InvalidKeyException(){
|
||||
super();
|
||||
}
|
||||
public InvalidKeyException(String message){
|
||||
super(message);
|
||||
}
|
||||
public InvalidKeyException(Throwable error){
|
||||
super(error);
|
||||
}
|
||||
public InvalidKeyException(String message, Throwable error){
|
||||
super(message, error);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/polySubstitution/Affine.java
|
||||
//Mattrixwv
|
||||
// Created: 01-26-22
|
||||
//Modified: 02-17-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
@@ -12,15 +15,21 @@ import mattrixwv.NumberAlgorithms;
|
||||
|
||||
|
||||
public class Affine{
|
||||
private boolean preserveCapitals;
|
||||
private boolean preserveSymbols;
|
||||
private boolean preserveWhitespace;
|
||||
private String inputString;
|
||||
private String outputString;
|
||||
private int key1; //Key1 must be relatively prime to 26
|
||||
private int key2;
|
||||
private static final Logger logger = LoggerFactory.getLogger(Affine.class);
|
||||
|
||||
//Fields
|
||||
private boolean preserveCapitals; //Whether to respect capitals in the output string
|
||||
private boolean preserveSymbols; //Whether to respect symbols in the output string
|
||||
private boolean preserveWhitespace; //Whether to respect whitespace in the output string
|
||||
private String inputString; //The string that needs encoded/decoded
|
||||
private String outputString; //The string that is output after encoding/decoding
|
||||
private int key1; //The multiplicative key. Key1 must be relatively prime to 26
|
||||
private int key2; //The additive key
|
||||
|
||||
//Ensures key1 constraints
|
||||
private void setKey1(int key1) throws InvalidKeywordException{
|
||||
logger.debug("Setting key1 {}", key1);
|
||||
|
||||
//If the key is negative change it to possitive
|
||||
if(key1 < 0){
|
||||
key1 %= 26;
|
||||
@@ -34,8 +43,13 @@ public class Affine{
|
||||
|
||||
//Save the key
|
||||
this.key1 = key1;
|
||||
|
||||
logger.debug("Cleaned key1 {}", key1);
|
||||
}
|
||||
//Ensures key2 constraints
|
||||
private void setKey2(int key2){
|
||||
logger.debug("Setting key2 {}", key2);
|
||||
|
||||
//If the key is negative change it to possitive
|
||||
if(key2 < 0){
|
||||
key2 %= 26;
|
||||
@@ -44,32 +58,49 @@ public class Affine{
|
||||
|
||||
//Save the key
|
||||
this.key2 = key2;
|
||||
|
||||
logger.debug("Cleaned key2 {}", key2);
|
||||
}
|
||||
//Ensures inputString constraints
|
||||
private void setInputString(String inputString) throws InvalidInputException{
|
||||
if(inputString == null){
|
||||
throw new InvalidInputException("Input must not be null");
|
||||
}
|
||||
|
||||
logger.debug("Original input string '{}'", inputString);
|
||||
|
||||
if(!preserveCapitals){
|
||||
logger.debug("Removing case");
|
||||
|
||||
inputString = inputString.toLowerCase();
|
||||
}
|
||||
if(!preserveWhitespace){
|
||||
logger.debug("Removing whitespace");
|
||||
|
||||
inputString = inputString.replaceAll("\\s", "");
|
||||
}
|
||||
if(!preserveSymbols){
|
||||
logger.debug("Removing symbols");
|
||||
|
||||
inputString = inputString.replaceAll("[^a-zA-Z\\s]", "");
|
||||
}
|
||||
|
||||
this.inputString = inputString;
|
||||
|
||||
logger.debug("Cleaned input string '{}'", inputString);
|
||||
|
||||
if(this.inputString.isBlank()){
|
||||
throw new InvalidInputException("Input cannot be blank");
|
||||
}
|
||||
}
|
||||
//Encodes the inputString and stores the result in outputString
|
||||
private String encode(){
|
||||
logger.debug("Encoding");
|
||||
|
||||
//Step through every character in the input and encode it if needed
|
||||
StringBuilder output = new StringBuilder();
|
||||
for(char ch : inputString.toCharArray()){
|
||||
logger.debug("Current char {}", ch);
|
||||
//Encode all letters
|
||||
if(Character.isUpperCase(ch)){
|
||||
//Change the character to a number
|
||||
@@ -79,6 +110,8 @@ public class Affine{
|
||||
//Change the new number back to a character and append it to the output
|
||||
char newChar = (char)(letter + 65);
|
||||
output.append(newChar);
|
||||
|
||||
logger.debug("Encoded char {}", newChar);
|
||||
}
|
||||
else if(Character.isLowerCase(ch)){
|
||||
//Change the character to a number
|
||||
@@ -88,6 +121,8 @@ public class Affine{
|
||||
//Change the new number back to a character and append it to the output
|
||||
char newChar = (char)(letter + 97);
|
||||
output.append(newChar);
|
||||
|
||||
logger.debug("Encoded char {}", newChar);
|
||||
}
|
||||
//Pass all other characters through
|
||||
else{
|
||||
@@ -96,19 +131,25 @@ public class Affine{
|
||||
}
|
||||
|
||||
//Save and return the output
|
||||
logger.debug("Saving output string '{}'", output);
|
||||
outputString = output.toString();
|
||||
return outputString;
|
||||
}
|
||||
//Decodes the inputString and stores the result in outputString
|
||||
private String decode(){
|
||||
logger.debug("Decoding");
|
||||
|
||||
//Find the multiplicative inverse of key1
|
||||
int key1I = 1;
|
||||
while(((key1 * key1I) % 26) != 1){
|
||||
++key1I;
|
||||
}
|
||||
logger.debug("Key1 inverse {}", key1I);
|
||||
|
||||
//Step through every character in the input and decode it if needed
|
||||
StringBuilder output = new StringBuilder();
|
||||
for(char ch : inputString.toCharArray()){
|
||||
logger.debug("Current char {}", ch);
|
||||
//Encode all letters
|
||||
if(Character.isUpperCase(ch)){
|
||||
//Change the letter to a number
|
||||
@@ -121,6 +162,8 @@ public class Affine{
|
||||
//Change the new number back to a character and append it to the output
|
||||
char newChar = (char)(letter + 65);
|
||||
output.append(newChar);
|
||||
|
||||
logger.debug("Decoded char {}", newChar);
|
||||
}
|
||||
else if(Character.isLowerCase(ch)){
|
||||
//Change the letter to a number
|
||||
@@ -133,6 +176,8 @@ public class Affine{
|
||||
//Change the new number back to a character and append it to the output
|
||||
char newChar = (char)(letter + 97);
|
||||
output.append(newChar);
|
||||
|
||||
logger.debug("Decoded char {}", newChar);
|
||||
}
|
||||
//Pass all other characters through
|
||||
else{
|
||||
@@ -141,10 +186,13 @@ public class Affine{
|
||||
}
|
||||
|
||||
//Save and return the output
|
||||
logger.debug("Saving output string '{}'", output);
|
||||
outputString = output.toString();
|
||||
return outputString;
|
||||
}
|
||||
|
||||
|
||||
//Constructor
|
||||
public Affine(){
|
||||
preserveCapitals = false;
|
||||
preserveSymbols = false;
|
||||
@@ -157,12 +205,15 @@ public class Affine{
|
||||
this.preserveWhitespace = preserveWhitespace;
|
||||
reset();
|
||||
}
|
||||
|
||||
//Encodes inputString using key1 and key2 and returns the result
|
||||
public String encode(int key1, int key2, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
setKey1(key1);
|
||||
setKey2(key2);
|
||||
setInputString(inputString);
|
||||
return encode();
|
||||
}
|
||||
//Decodes inputString using key1 and key2 and returns the result
|
||||
public String decode(int key1, int key2, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
setKey1(key1);
|
||||
setKey2(key2);
|
||||
@@ -170,22 +221,29 @@ public class Affine{
|
||||
return decode();
|
||||
}
|
||||
|
||||
//Returns the cleaned inputString
|
||||
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;
|
||||
}
|
||||
//Makes sure all of the variables are empty
|
||||
public void reset(){
|
||||
logger.debug("Resetting fields");
|
||||
|
||||
inputString = "";
|
||||
outputString = "";
|
||||
key1 = 0;
|
||||
key2 = 0;
|
||||
}
|
||||
public String getInputString(){
|
||||
return inputString;
|
||||
}
|
||||
public String getOutputString(){
|
||||
return outputString;
|
||||
}
|
||||
public int getKey1(){
|
||||
return key1;
|
||||
}
|
||||
public int getKey2(){
|
||||
return key2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,34 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/Atbash.java
|
||||
//Mattrixwv
|
||||
// Created: 07-25-21
|
||||
//Modified: 02-22-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
|
||||
|
||||
public class Atbash{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Atbash.class);
|
||||
|
||||
private String inputString; //Holds the string that needs encoded or decoded
|
||||
private String outputString; //The encoded/decoded string
|
||||
private boolean preserveCapitals; //Whether to respect capitals in the output string
|
||||
private boolean preserveWhitespace; //Whether to respect whitespace in the output string
|
||||
private boolean preserveSymbols; //Whether to respect symbols in the output string
|
||||
|
||||
|
||||
//Encodes inputString and stores in outputString
|
||||
private String encode(){
|
||||
logger.debug("Encoding");
|
||||
StringBuilder output = new StringBuilder();
|
||||
//Step through every element in the inputString and shift it the correct amount
|
||||
for(int cnt = 0;cnt < inputString.length();++cnt){
|
||||
char currentChar = inputString.charAt(cnt);
|
||||
logger.debug("Encoding char {}", currentChar);
|
||||
//Decode if the letter is alphabetic
|
||||
if(Character.isAlphabetic(currentChar)){
|
||||
//Use either uppercase or lowercase for the base
|
||||
@@ -37,6 +46,8 @@ public class Atbash{
|
||||
}
|
||||
}
|
||||
|
||||
//Return the output
|
||||
logger.debug("Saving output string '{}'", output);
|
||||
outputString = output.toString();
|
||||
return outputString;
|
||||
}
|
||||
@@ -46,15 +57,23 @@ public class Atbash{
|
||||
throw new NullPointerException("Input cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Original input string '{}'", inputString);
|
||||
|
||||
if(!preserveCapitals){
|
||||
logger.debug("Removing case");
|
||||
|
||||
//Convert all letters to lowercase
|
||||
inputString = inputString.toUpperCase();
|
||||
}
|
||||
if(!preserveWhitespace){
|
||||
logger.debug("Removing whitespace");
|
||||
|
||||
//Remove all characters except capital letters
|
||||
inputString = inputString.replaceAll("\\s", "");
|
||||
}
|
||||
if(!preserveSymbols){
|
||||
logger.debug("Removing symbols");
|
||||
|
||||
//Remove all non-alpha numeric and whitespace symbols
|
||||
inputString = inputString.replaceAll("[^a-zA-Z\\s]", "");
|
||||
}
|
||||
@@ -62,12 +81,15 @@ public class Atbash{
|
||||
//Save the string
|
||||
this.inputString = inputString;
|
||||
|
||||
logger.debug("Cleaned input string '{}'", inputString);
|
||||
|
||||
if(this.inputString.isBlank()){
|
||||
throw new InvalidInputException("Input must contain at least 1 character");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Constructor
|
||||
public Atbash(){
|
||||
reset();
|
||||
preserveCapitals = false;
|
||||
@@ -80,22 +102,32 @@ public class Atbash{
|
||||
this.preserveWhitespace = preserveWhitespace;
|
||||
this.preserveSymbols = preserveSymbols;
|
||||
}
|
||||
public String getInputString(){
|
||||
return inputString;
|
||||
}
|
||||
public String getOutputString(){
|
||||
return outputString;
|
||||
}
|
||||
|
||||
//Encodes inputString and returns the result
|
||||
public String encode(String inputString) throws InvalidInputException{
|
||||
//Make sure everything is empty before you begin
|
||||
reset();
|
||||
setInputString(inputString);
|
||||
return encode();
|
||||
}
|
||||
//Decodes inputString and returns the result
|
||||
public String decode(String inputString) throws InvalidInputException{
|
||||
return encode(inputString);
|
||||
}
|
||||
|
||||
//Returns the cleaned input string
|
||||
public String getInputString(){
|
||||
return inputString;
|
||||
}
|
||||
//Returns the output string
|
||||
public String getOutputString(){
|
||||
return outputString;
|
||||
}
|
||||
//Makes sure all of the variables are empty
|
||||
public void reset(){
|
||||
inputString = outputString = "";
|
||||
logger.debug("Resetting fields");
|
||||
|
||||
inputString = "";
|
||||
outputString = "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,47 +1,65 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/Autokey.java
|
||||
//Mattrixwv
|
||||
// Created: 07-25-21
|
||||
//Modified: 07-03-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
public class Autokey extends Vigenere{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Autokey.class);
|
||||
|
||||
//Special rules for setting the strings for encoding
|
||||
private void encodeSet(String keyword, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
logger.debug("Setting fields for encoding");
|
||||
|
||||
//Set the input
|
||||
setInputString(inputString);
|
||||
|
||||
StringBuilder newKey = new StringBuilder();
|
||||
//Remove all unneccessary elements from the key
|
||||
logger.debug("Setting keyword");
|
||||
setKeyword(keyword);
|
||||
newKey.append(keyword);
|
||||
//Remove all unneccessary elements from the input
|
||||
logger.debug("Adding input to keyword");
|
||||
setKeyword(inputString);
|
||||
newKey.append(getKeyword());
|
||||
|
||||
//Make sure the key is not any longer than the input
|
||||
logger.debug("Removing last letters in the keyword");
|
||||
keyword = newKey.substring(0, getKeyword().length());
|
||||
|
||||
//Set the new keyword
|
||||
setKeyword(keyword);
|
||||
|
||||
//Make sure to update the offset
|
||||
offset.clear();
|
||||
setOffset();
|
||||
}
|
||||
//Setting the strings for decoding
|
||||
private void decodeSet(String keyword, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
logger.debug("Setting fields for decoding");
|
||||
|
||||
//Remove all unneccessary elements from the key
|
||||
logger.debug("Setting keyword");
|
||||
setKeyword(keyword);
|
||||
|
||||
//Remove all unneccessary elements from the input
|
||||
logger.debug("Setting input string");
|
||||
setInputString(inputString);
|
||||
}
|
||||
//Decodes the inputString
|
||||
@Override
|
||||
protected String decode(){
|
||||
logger.debug("Decoding");
|
||||
|
||||
//Decode what the key will allow, add that to the key and continue
|
||||
StringBuilder currentOutput = new StringBuilder();
|
||||
StringBuilder fullOutput = new StringBuilder();
|
||||
@@ -51,36 +69,55 @@ public class Autokey extends Vigenere{
|
||||
for(int letterCnt = 0;letterCnt < inputString.length();++letterCnt){
|
||||
//If we have reached the end of the keyword add what we have to it and continue
|
||||
if(offsetCnt == keyword.length()){
|
||||
logger.debug("Appending partial output to keyword");
|
||||
|
||||
setKeyword(keyword + currentOutput.toString());
|
||||
fullOutput.append(currentOutput);
|
||||
currentOutput = new StringBuilder();
|
||||
}
|
||||
|
||||
char letter = inputString.charAt(letterCnt);
|
||||
logger.debug("Working character {}", letter);
|
||||
|
||||
if(Character.isUpperCase(letter)){
|
||||
logger.debug("Appending uppercase");
|
||||
|
||||
letter -= offset.get((offsetCnt++) % offset.size());
|
||||
if(letter < 'A'){
|
||||
logger.debug("Wrapping around to Z");
|
||||
|
||||
letter += 26;
|
||||
}
|
||||
else if(letter > 'Z'){
|
||||
logger.debug("Wrapping around to A");
|
||||
|
||||
letter -= 26;
|
||||
}
|
||||
}
|
||||
else if(Character.isLowerCase(letter)){
|
||||
logger.debug("Appending lowercase");
|
||||
|
||||
letter -= offset.get((offsetCnt++) % offset.size());
|
||||
if(letter < 'a'){
|
||||
logger.debug("Wrapping around to z");
|
||||
|
||||
letter += 26;
|
||||
}
|
||||
else if(letter > 'z'){
|
||||
logger.debug("Wrapping around to a");
|
||||
|
||||
letter -= 26;
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Decoded letter {}", letter);
|
||||
currentOutput.append(letter);
|
||||
}
|
||||
//Empty the last character that were decoded
|
||||
fullOutput.append(currentOutput);
|
||||
|
||||
//Save and return the results
|
||||
logger.debug("Saving output string '{}'", fullOutput);
|
||||
outputString = fullOutput.toString();
|
||||
return outputString;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,25 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/Baconian.java
|
||||
//Mattrixwv
|
||||
// Created: 01-12-22
|
||||
//Modified: 01-16-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
|
||||
|
||||
public class Baconian{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Baconian.class);
|
||||
|
||||
//Conversions
|
||||
private static final ArrayList<String> code = new ArrayList<>(Arrays.asList(
|
||||
"aaaaa", "aaaab", "aaaba", "aaabb", "aabaa", "aabab", "aabba","aabbb", "abaaa", "abaaa", "abaab", "ababa", "ababb", //A-M
|
||||
"abbaa", "abbab", "abbba", "abbbb", "baaaa", "baaab", "baaba", "baabb", "baabb", "babaa", "babab", "babba", "babbb" //N-Z
|
||||
@@ -26,14 +34,20 @@ public class Baconian{
|
||||
throw new NullPointerException("Input cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Setting input string for encoding '{}'", inputString);
|
||||
|
||||
//Remove all whitespace and symbols
|
||||
inputString = inputString.replaceAll("[^A-Za-z]", "");
|
||||
if(!preserveCapitals){
|
||||
logger.debug("Removing case");
|
||||
|
||||
inputString = inputString.toLowerCase();
|
||||
}
|
||||
|
||||
this.inputString = inputString;
|
||||
|
||||
logger.debug("Cleaned input string '{}'", inputString);
|
||||
|
||||
if(this.inputString.isBlank()){
|
||||
throw new InvalidInputException("Input must contain at least 1 letter");
|
||||
}
|
||||
@@ -43,17 +57,26 @@ public class Baconian{
|
||||
throw new NullPointerException("Input cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Setting input string for decoding '{}'", inputString);
|
||||
|
||||
if(!preserveCapitals){
|
||||
logger.debug("Removing case");
|
||||
|
||||
inputString = inputString.toLowerCase();
|
||||
}
|
||||
|
||||
//Check each Baconian Cipher letter for validity
|
||||
logger.debug("Ensuring all 'letters' contain 5 characters");
|
||||
for(String str : inputString.split(" ")){
|
||||
logger.debug("Current 'letter' {}", str);
|
||||
|
||||
//Make sure each letter contains 5 characters
|
||||
if(str.length() != 5){
|
||||
throw new InvalidCharacterException("All Baconian letters contain exactly 5 characters: " + str);
|
||||
}
|
||||
|
||||
//Make sure the letter contains only a's and b's
|
||||
logger.debug("Replacing all non-abAB characters");
|
||||
String temp = str.replaceAll("[^abAB]", "");
|
||||
if(!temp.equals(str)){
|
||||
throw new InvalidCharacterException("Baconian letters contain only a's and b's: " + str);
|
||||
@@ -62,54 +85,76 @@ public class Baconian{
|
||||
|
||||
this.inputString = inputString;
|
||||
|
||||
logger.debug("Cleaned input string '{}'", inputString);
|
||||
|
||||
if(this.inputString.isBlank()){
|
||||
throw new InvalidInputException("Input cannot be empty");
|
||||
}
|
||||
}
|
||||
//Encodes the inputString and stores the result in outputString
|
||||
private String encode(){
|
||||
logger.debug("Encoding");
|
||||
StringJoiner output = new StringJoiner(" ");
|
||||
//Go through every character in the inputString and encode it
|
||||
for(char ch : inputString.toCharArray()){
|
||||
logger.debug("Working character {}", ch);
|
||||
|
||||
//Convert the character to a binary string with A = 0
|
||||
String binary = null;
|
||||
if(Character.isUpperCase(ch)){
|
||||
logger.debug("Encoding uppercase");
|
||||
|
||||
binary = code.get(ch - 'A').toUpperCase();
|
||||
}
|
||||
else{
|
||||
logger.debug("Encoding lowercase");
|
||||
|
||||
binary = code.get(ch - 'a').toLowerCase();
|
||||
}
|
||||
|
||||
//Add the encoded character to the output
|
||||
logger.debug("Output 'letter' {}", binary);
|
||||
output.add(binary);
|
||||
}
|
||||
|
||||
//Save and return the output
|
||||
logger.debug("Saving output string '{}'", output);
|
||||
outputString = output.toString();
|
||||
return outputString;
|
||||
}
|
||||
//Decodes the inputString and stores the result in outputString
|
||||
private String decode(){
|
||||
logger.debug("Decoding");
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
//Go through every Baconian Cipher character in the inputString and decode it
|
||||
for(String baconianCharacter : inputString.split(" ")){
|
||||
logger.debug("Working letter {}", baconianCharacter);
|
||||
|
||||
//Get the location of the Baconian character in the array
|
||||
int location = code.indexOf(baconianCharacter.toLowerCase());
|
||||
logger.debug("Location of letter {}", location);
|
||||
|
||||
//Convert the Baconian character to an ASCII character
|
||||
char ch;
|
||||
if(Character.isUpperCase(baconianCharacter.charAt(0))){
|
||||
logger.debug("Decoding uppercase");
|
||||
|
||||
ch = (char)(location + 'A');
|
||||
}
|
||||
else{
|
||||
logger.debug("Decoding lowercase");
|
||||
|
||||
ch = (char)(location + 'a');
|
||||
}
|
||||
|
||||
//Add the decoded character to the output
|
||||
logger.debug("Decoded character {}", ch);
|
||||
output.append(ch);
|
||||
}
|
||||
|
||||
//Save and return the output
|
||||
logger.debug("Saving output string '{}'", output);
|
||||
outputString = output.toString();
|
||||
return outputString;
|
||||
}
|
||||
@@ -145,6 +190,8 @@ public class Baconian{
|
||||
}
|
||||
//Makes sure all of the variables are empty
|
||||
public void reset(){
|
||||
logger.debug("Resetting fields");
|
||||
|
||||
inputString = "";
|
||||
outputString = "";
|
||||
}
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/BaseX.java
|
||||
//Mattrixwv
|
||||
// Created: 01-08-22
|
||||
//Modified: 01-09-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidBaseException;
|
||||
|
||||
|
||||
public class BaseX{
|
||||
private static final Logger logger = LoggerFactory.getLogger(BaseX.class);
|
||||
|
||||
private String inputString; //The string that needs encoded/decoded
|
||||
private String outputString; //The encoded/decoded string
|
||||
private int base; //The base that the number will be encoded at
|
||||
@@ -23,6 +28,8 @@ public class BaseX{
|
||||
throw new NullPointerException("Input cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Setting input string for encoding '{}'", inputString);
|
||||
|
||||
this.inputString = inputString;
|
||||
|
||||
if(this.inputString.isBlank()){
|
||||
@@ -34,15 +41,27 @@ public class BaseX{
|
||||
throw new NullPointerException("Input cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Setting input string for decoding '{}'", inputString);
|
||||
|
||||
//Create a string of valid 'numbers'
|
||||
logger.debug("Creating string of valid 'numbers'");
|
||||
StringBuilder validNumbers = new StringBuilder();
|
||||
for(int cnt = 0;cnt < base;++cnt){
|
||||
validNumbers.append(Integer.toString(cnt, base).toUpperCase());
|
||||
String number = Integer.toString(cnt, base).toUpperCase();
|
||||
logger.debug("Current number {}, converted {}", cnt, number);
|
||||
validNumbers.append(number);
|
||||
}
|
||||
|
||||
//Remove all invalid characters
|
||||
logger.debug("Checking for invalid characters");
|
||||
this.inputString = inputString.replaceAll("[^" + validNumbers.toString() + "\\s]", "");
|
||||
//Throw an exception if there were any invalid characters
|
||||
if(!this.inputString.equals(inputString)){
|
||||
throw new InvalidCharacterException("inputString cannot contain anything except numbers 0-" + Integer.toString(base - 1, base) + ", and whitespace");
|
||||
}
|
||||
|
||||
logger.debug("Cleaned input string '{}'", inputString);
|
||||
|
||||
if(this.inputString.isBlank()){
|
||||
throw new InvalidInputException("Input must contain at least 1 letter");
|
||||
}
|
||||
@@ -53,32 +72,47 @@ public class BaseX{
|
||||
throw new InvalidBaseException("Base cannot be a negative number");
|
||||
}
|
||||
|
||||
logger.debug("Setting base {}", base);
|
||||
|
||||
this.base = base;
|
||||
}
|
||||
//Encode inputString, store it in outputString, and return it
|
||||
private String encode(){
|
||||
logger.debug("Encoding");
|
||||
|
||||
//Encode every character in inputString
|
||||
StringJoiner output = new StringJoiner(" ");
|
||||
for(int cnt = 0;cnt < inputString.length();++cnt){
|
||||
//Get the next character
|
||||
char ch = inputString.charAt(cnt);
|
||||
logger.debug("Working number {}", ch);
|
||||
|
||||
//Encode the character to binary and add it to the output
|
||||
output.add(Integer.toString(ch, base));
|
||||
String convertedNum = Integer.toString(ch, base);
|
||||
output.add(convertedNum);
|
||||
logger.debug("Converted number {}", convertedNum);
|
||||
}
|
||||
|
||||
//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
|
||||
private String decode() throws InvalidCharacterException{
|
||||
logger.debug("Decoding");
|
||||
|
||||
//Decode every binary number in the string
|
||||
StringBuilder output = new StringBuilder();
|
||||
for(String baseXString : inputString.split(" ")){
|
||||
logger.debug("Current number {}", baseXString);
|
||||
|
||||
//Decode the current binary number
|
||||
int num = Integer.valueOf(baseXString, base);
|
||||
logger.debug("Decoded number {}", num);
|
||||
|
||||
//Make sure it is in a valid range
|
||||
if((num < 0) && (num > 255)){
|
||||
throw new InvalidCharacterException("The base" + base + " string '" + baseXString + "' is not a valid character");
|
||||
@@ -89,6 +123,7 @@ public class BaseX{
|
||||
}
|
||||
|
||||
//Save the output
|
||||
logger.debug("Saving output string '{}'", output);
|
||||
outputString = output.toString();
|
||||
|
||||
//Return the output
|
||||
@@ -142,6 +177,8 @@ public class BaseX{
|
||||
}
|
||||
//Makes sure all of the variables are empty
|
||||
public void reset(){
|
||||
logger.debug("Resetting fields");
|
||||
|
||||
inputString = "";
|
||||
outputString = "";
|
||||
}
|
||||
|
||||
@@ -1,21 +1,28 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/Beaufort.java
|
||||
//Mattrixwv
|
||||
// Created: 02-23-22
|
||||
//Modified: 02-23-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
public class Beaufort{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Beaufort.class);
|
||||
|
||||
//Fields
|
||||
private String inputString; //This is the string that needs encoded/decoded
|
||||
private String outputString; //This is the string that is output after encoding/decoding
|
||||
private String keyword; //This is the keyword that is responsible for determining the offsets that you change each character by
|
||||
private boolean preserveCapitals; //Whether to respect capitals in the output string
|
||||
private boolean preserveWhitespace; //Whether to respect whitespace in the output string
|
||||
private boolean preserveSymbols; //Whether to respect symbols in the output string
|
||||
//Internal ciphers
|
||||
private Atbash atbash; //The first step in encoding/decoding the cipher
|
||||
private Caesar caesar; //The second step in encoding/decoding the cipher
|
||||
private Vigenere vigenere; //The third step in encoding/decoding the cipher
|
||||
@@ -27,18 +34,27 @@ public class Beaufort{
|
||||
throw new InvalidInputException("Input cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Original input string '{}'", inputString);
|
||||
|
||||
//Apply removal options
|
||||
if(!preserveCapitals){
|
||||
logger.debug("Removing case");
|
||||
|
||||
inputString = inputString.toUpperCase();
|
||||
}
|
||||
if(!preserveWhitespace){
|
||||
logger.debug("Removing whitespace");
|
||||
|
||||
inputString = inputString.replaceAll("\\s", "");
|
||||
}
|
||||
if(!preserveSymbols){
|
||||
logger.debug("Removing symbols");
|
||||
|
||||
inputString = inputString.replaceAll("[^a-zA-Z\\s]", "");
|
||||
}
|
||||
|
||||
//Save the string
|
||||
logger.debug("Cleaned input string '{}'", inputString);
|
||||
this.inputString = inputString;
|
||||
|
||||
//Make sure the string isn't blank
|
||||
@@ -53,11 +69,17 @@ public class Beaufort{
|
||||
throw new InvalidKeywordException("Keyword cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Original keyword '{}'", keyword);
|
||||
|
||||
//Convert all letters to uppercase
|
||||
logger.debug("Removing case");
|
||||
keyword = keyword.toUpperCase();
|
||||
//Remove all characters except capital letters
|
||||
logger.debug("Removing all non-letters");
|
||||
keyword = keyword.replaceAll("[^A-Z]", "");
|
||||
|
||||
//Save the string
|
||||
logger.debug("Cleaned keyword '{}'", keyword);
|
||||
this.keyword = keyword;
|
||||
|
||||
//If after all the elimination of unusable characters the keyword is empty throw an exception
|
||||
@@ -67,19 +89,27 @@ public class Beaufort{
|
||||
}
|
||||
//Encodes the inputString and stores the result in outputString
|
||||
public void encode() throws InvalidKeywordException, InvalidInputException{
|
||||
logger.debug("Encoding");
|
||||
|
||||
//Reverse the string
|
||||
logger.debug("Encoding with Atbash");
|
||||
String atbashString = atbash.encode(inputString);
|
||||
//Shift the reversal by 1
|
||||
//?Not quite sure why this is needed. Need to look into this cipher a bit more closely
|
||||
logger.debug("Shifting all letters by 1");
|
||||
String caesarString = caesar.encode(1, atbashString);
|
||||
//Shift each letter according to the key
|
||||
logger.debug("Encoding with Vigenere");
|
||||
String vigenereString = vigenere.encode(keyword, caesarString);
|
||||
|
||||
//Save the output
|
||||
logger.debug("Saving output string '{}'", vigenereString);
|
||||
this.outputString = vigenereString;
|
||||
}
|
||||
//Decodes the inputString and stores the result in outputString
|
||||
public void decode() throws InvalidKeywordException, InvalidInputException{
|
||||
logger.debug("Decoding");
|
||||
|
||||
//Decoding is just encoding again
|
||||
encode();
|
||||
}
|
||||
@@ -138,6 +168,8 @@ public class Beaufort{
|
||||
}
|
||||
//Makes sure all of the variables are empty
|
||||
public void reset(){
|
||||
logger.debug("Resetting fields");
|
||||
|
||||
inputString = "";
|
||||
outputString = "";
|
||||
keyword = "";
|
||||
|
||||
@@ -1,24 +1,35 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/Caesar.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-25-21
|
||||
//Modified: 02-17-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
|
||||
|
||||
public class Caesar{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Caesar.class);
|
||||
|
||||
//Fields
|
||||
private String inputString; //The string that needs encoded/decoded
|
||||
private String outputString; //The encoded/decoded string
|
||||
private int shift; //The amount that you need to shift each letter
|
||||
private boolean preserveCapitals; //Whether to respect capitals in the output string
|
||||
private boolean preserveWhitespace; //Whether to respect whitespace in the output string
|
||||
private boolean preserveSymbols; //Whether to respect symbols in the output string
|
||||
|
||||
//Sets shift and makes sure it is within the propper bounds
|
||||
private void setShift(int shiftAmount){
|
||||
logger.debug("Setting shift {}", shiftAmount);
|
||||
|
||||
//If you shift more than 26 you will just be wrapping back around again
|
||||
shift = shiftAmount % 26;
|
||||
|
||||
logger.debug("Cleaned shift {}", shift);
|
||||
}
|
||||
//Sets the input string
|
||||
private void setInputString(String inputString) throws InvalidInputException{
|
||||
@@ -26,16 +37,25 @@ public class Caesar{
|
||||
throw new NullPointerException("Input cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Original input string '{}'", inputString);
|
||||
|
||||
if(!preserveCapitals){
|
||||
logger.debug("Removing case");
|
||||
|
||||
inputString = inputString.toLowerCase();
|
||||
}
|
||||
if(!preserveWhitespace){
|
||||
logger.debug("Removing whitespace");
|
||||
|
||||
inputString = inputString.replaceAll("\\s", "");
|
||||
}
|
||||
if(!preserveSymbols){
|
||||
logger.debug("Removing symbols");
|
||||
|
||||
inputString = inputString.replaceAll("[^a-zA-Z\\s]", "");
|
||||
}
|
||||
|
||||
logger.debug("Cleaned input string '{}'", inputString);
|
||||
this.inputString = inputString;
|
||||
|
||||
if(this.inputString.isBlank()){
|
||||
@@ -44,63 +64,93 @@ public class Caesar{
|
||||
}
|
||||
//Encodes the inputString and stores the result in outputString
|
||||
private String encode(){
|
||||
logger.debug("Encoding");
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
for(int cnt = 0;cnt < inputString.length();++cnt){
|
||||
char currentChar = inputString.charAt(cnt); //A temperary holder for the current working character
|
||||
logger.debug("Working character {}", currentChar);
|
||||
|
||||
//If it is an upper case letter shift it and wrap if necessary
|
||||
if(Character.isUpperCase(currentChar)){
|
||||
logger.debug("Encoding uppercase");
|
||||
|
||||
currentChar += shift;
|
||||
//Wrap around if the letter is now out of bounds
|
||||
if(currentChar < 'A'){
|
||||
logger.debug("Wrapping around to Z");
|
||||
currentChar += 26;
|
||||
}
|
||||
else if(currentChar > 'Z'){
|
||||
logger.debug("Wrapping around to A");
|
||||
currentChar -= 26;
|
||||
}
|
||||
}
|
||||
//If it is a lower case letter shift it and wrap if necessary
|
||||
else if(Character.isLowerCase(currentChar)){
|
||||
logger.debug("Encoding lowercase");
|
||||
|
||||
currentChar += shift;
|
||||
//Wrap around if the letter is now out of bounds
|
||||
if(currentChar < 'a'){
|
||||
logger.debug("Wrapping around to z");
|
||||
currentChar += 26;
|
||||
}
|
||||
else if(currentChar > 'z'){
|
||||
logger.debug("Wrapping around to a");
|
||||
currentChar -= 26;
|
||||
}
|
||||
}
|
||||
//If it is whitespace, number, or punctuation just let it pass through
|
||||
//Add it to the output string
|
||||
logger.debug("Encoded character {}", currentChar);
|
||||
output.append(currentChar);
|
||||
}
|
||||
|
||||
logger.debug("Saving encoded string '{}'", output);
|
||||
outputString = output.toString();
|
||||
return outputString;
|
||||
}
|
||||
//Decodes the inputString and stores the result in outputString
|
||||
private String decode(){
|
||||
logger.debug("Decoding");
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
for(int cnt = 0;cnt < inputString.length();++cnt){
|
||||
char currentChar = inputString.charAt(cnt); //A temperary holder for the current working character
|
||||
logger.debug("Working character {}", currentChar);
|
||||
|
||||
//If it is an upper case letter shift it and wrap if necessary
|
||||
if(Character.isUpperCase(currentChar)){
|
||||
logger.debug("Decoding uppercase");
|
||||
|
||||
currentChar -= shift;
|
||||
//Wrap around if the letter is now out of bounds
|
||||
if(currentChar < 'A'){
|
||||
logger.debug("Wrapping around to Z");
|
||||
|
||||
currentChar += 26;
|
||||
}
|
||||
else if(currentChar > 'Z'){
|
||||
logger.debug("Wrapping around to A");
|
||||
|
||||
currentChar -= 26;
|
||||
}
|
||||
}
|
||||
//If it is a lower case letter shift it and wrap if necessary
|
||||
else if(Character.isLowerCase(currentChar)){
|
||||
logger.debug("Decoding lowercase");
|
||||
|
||||
currentChar -= shift;
|
||||
//Wrap around if the letter is now out of bounds
|
||||
if(currentChar < 'a'){
|
||||
logger.debug("Wrapping around to z");
|
||||
|
||||
currentChar += 26;
|
||||
}
|
||||
else if(currentChar > 'z'){
|
||||
logger.debug("Wrapping around to a");
|
||||
|
||||
currentChar -= 26;
|
||||
}
|
||||
}
|
||||
@@ -109,6 +159,7 @@ public class Caesar{
|
||||
output.append(currentChar);
|
||||
}
|
||||
|
||||
logger.debug("Saving decoded string '{}'", output);
|
||||
outputString = output.toString();
|
||||
return outputString;
|
||||
}
|
||||
@@ -126,18 +177,7 @@ public class Caesar{
|
||||
this.preserveWhitespace = preserveWhitespace;
|
||||
this.preserveSymbols = preserveSymbols;
|
||||
}
|
||||
//Returns the inputString
|
||||
public String getInputString(){
|
||||
return inputString;
|
||||
}
|
||||
//Returns shift
|
||||
public int getShift(){
|
||||
return shift;
|
||||
}
|
||||
//Returns the outputString
|
||||
public String getOutputString(){
|
||||
return outputString;
|
||||
}
|
||||
|
||||
//Sets the shift and inputString and encodes the message
|
||||
public String encode(int shiftAmount, String inputString) throws InvalidInputException{
|
||||
reset();
|
||||
@@ -152,9 +192,25 @@ public class Caesar{
|
||||
setInputString(inputString);
|
||||
return decode();
|
||||
}
|
||||
|
||||
//Returns the inputString
|
||||
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
|
||||
public void reset(){
|
||||
inputString = outputString = "";
|
||||
logger.debug("Resetting fields");
|
||||
|
||||
inputString = "";
|
||||
outputString = "";
|
||||
shift = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/OneTimePad.java
|
||||
//Mattrixwv
|
||||
// Created: 02-23-22
|
||||
//Modified: 02-23-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
public class OneTimePad extends Vigenere{
|
||||
private static final Logger logger = LoggerFactory.getLogger(OneTimePad.class);
|
||||
|
||||
//?Add some kind of entropy calculator?
|
||||
//?Add some kind of "book passage includer"?
|
||||
|
||||
@@ -28,6 +33,9 @@ public class OneTimePad extends Vigenere{
|
||||
if(keyword.length() < inputString.length()){
|
||||
throw new InvalidKeywordException("Key must be at least as long as the input");
|
||||
}
|
||||
|
||||
logger.debug("Encoding");
|
||||
|
||||
return super.encode(keyword, inputString);
|
||||
}
|
||||
//Decodes input using key and returns the result
|
||||
@@ -36,6 +44,9 @@ public class OneTimePad extends Vigenere{
|
||||
if(keyword.length() < inputString.length()){
|
||||
throw new InvalidKeywordException("Key must be at least as long as the input");
|
||||
}
|
||||
|
||||
logger.debug("Decoding");
|
||||
|
||||
return super.decode(keyword, inputString);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/Porta.java
|
||||
//Mattrixwv
|
||||
// Created: 02-28-22
|
||||
//Modified: 02-28-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
public class Porta{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Porta.class);
|
||||
|
||||
private static final String[] tableau = {
|
||||
"NOPQRSTUVWXYZABCDEFGHIJKLM", //A-B
|
||||
"OPQRSTUVWXYZNMABCDEFGHIJKL", //C-D
|
||||
@@ -26,48 +31,68 @@ public class Porta{
|
||||
"ZNOPQRSTUVWXYBCDEFGHIJKLMA" //Y-Z
|
||||
};
|
||||
|
||||
private String inputString;
|
||||
private String outputString;
|
||||
private String keyword;
|
||||
private boolean preserveCapitals;
|
||||
private boolean preserveWhitespace;
|
||||
private boolean preserveSymbols;
|
||||
//Fields
|
||||
private String inputString; //The string that needs encoded/decoded
|
||||
private String outputString; //The encoded/decoded string
|
||||
private String keyword; //The keyword used to encode the input string
|
||||
private boolean preserveCapitals; //Whether to respect capitals in the output string
|
||||
private boolean preserveWhitespace; //Whether to respect whitespace in the output string
|
||||
private boolean preserveSymbols; //Whether to respect symbols in the output string
|
||||
|
||||
//Ensure all keyword constraints are followed
|
||||
private void setKeyword(String keyword) throws InvalidKeywordException{
|
||||
//Make sure the keyword isn't null
|
||||
if(keyword == null){
|
||||
throw new InvalidKeywordException("Keyword cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Original keyword '{}'", keyword);
|
||||
|
||||
//Convert all letters to uppercase
|
||||
logger.debug("Removing case");
|
||||
keyword = keyword.toUpperCase();
|
||||
//Remove all characters except capital letters and save the string
|
||||
logger.debug("Removing all non-letters");
|
||||
keyword = keyword.replaceAll("[^A-Z]", "");
|
||||
|
||||
//Save the keyword
|
||||
this.keyword = keyword;
|
||||
|
||||
logger.debug("Cleaned keyword '{}'", keyword);
|
||||
|
||||
//If after eliminating all ususable characters the keyword is empty throw an exception
|
||||
if(this.keyword.isBlank() || (this.keyword.length() < 2)){
|
||||
throw new InvalidKeywordException("Keyword must contain at least 2 letters");
|
||||
}
|
||||
}
|
||||
//Ensure all input constraints are followed
|
||||
private void setInputString(String inputString) throws InvalidInputException{
|
||||
//Ensure the input isn't null
|
||||
if(inputString == null){
|
||||
throw new InvalidInputException("Input cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Original input string {}", inputString);
|
||||
|
||||
//Apply removal options
|
||||
if(!preserveCapitals){
|
||||
logger.debug("Removing case");
|
||||
|
||||
inputString = inputString.toUpperCase();
|
||||
}
|
||||
if(!preserveWhitespace){
|
||||
logger.debug("Removing whitespace");
|
||||
|
||||
inputString = inputString.replaceAll("\\s", "");
|
||||
}
|
||||
if(!preserveSymbols){
|
||||
logger.debug("Removig symbols");
|
||||
|
||||
inputString = inputString.replaceAll("[^a-zA-Z\\s]", "");
|
||||
}
|
||||
|
||||
//Save the string
|
||||
logger.debug("Cleaned input string '{}'", inputString);
|
||||
this.inputString = inputString;
|
||||
|
||||
//Ensure the string isn't blank
|
||||
@@ -75,11 +100,14 @@ public class Porta{
|
||||
throw new InvalidInputException("Input must contain at least 1 letter");
|
||||
}
|
||||
}
|
||||
//Returns the letter that replaces the passed in letter
|
||||
private char getReplacer(int keywordCnt, char letter){
|
||||
logger.debug("Getting letter that replaces {} at {}", letter, keywordCnt);
|
||||
|
||||
char keyLetter = keyword.charAt(keywordCnt % keyword.length());
|
||||
int tableauColumn = (Character.toUpperCase(letter) - 'A');
|
||||
char replacer;
|
||||
|
||||
char replacer;
|
||||
switch(keyLetter){
|
||||
case 'A', 'B' -> replacer = tableau[0].charAt(tableauColumn);
|
||||
case 'C', 'D' -> replacer = tableau[1].charAt(tableauColumn);
|
||||
@@ -97,32 +125,44 @@ public class Porta{
|
||||
default -> replacer = letter;
|
||||
}
|
||||
|
||||
logger.debug("Replacer {}", replacer);
|
||||
return replacer;
|
||||
}
|
||||
//Encodes the inputString and stores the result in outputString
|
||||
private void encode(){
|
||||
logger.debug("Encoding");
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
|
||||
//Step through every character in the inputString and advance it the correct amount according to the keyword and tableau
|
||||
int keywordCnt = 0;
|
||||
for(char letter : inputString.toCharArray()){
|
||||
logger.debug("Working character {}", letter);
|
||||
//If the character is a letter replace with the corresponding character from the tableau
|
||||
if(Character.isUpperCase(letter)){
|
||||
logger.debug("Encoding uppercase");
|
||||
letter = Character.toUpperCase(getReplacer(keywordCnt, letter));
|
||||
++keywordCnt;
|
||||
}
|
||||
else if(Character.isLowerCase(letter)){
|
||||
logger.debug("Encoding lowercase");
|
||||
letter = Character.toLowerCase(getReplacer(keywordCnt, letter));
|
||||
++keywordCnt;
|
||||
}
|
||||
|
||||
//Add the current character to the output
|
||||
logger.debug("Encoded letter {}", letter);
|
||||
output.append(letter);
|
||||
}
|
||||
|
||||
//Save the output
|
||||
logger.debug("Saving output string '{}'", output);
|
||||
outputString = output.toString();
|
||||
}
|
||||
//Decodes the inputString and stores the result in outputString
|
||||
private void decode(){
|
||||
logger.debug("Decoding");
|
||||
|
||||
//Decoding is the same as encoding
|
||||
encode();
|
||||
}
|
||||
@@ -142,6 +182,7 @@ public class Porta{
|
||||
reset();
|
||||
}
|
||||
|
||||
//Sets the keyword and inputString and encodes the message
|
||||
public String encode(String keyword, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
//Set the parameters
|
||||
reset();
|
||||
@@ -152,6 +193,7 @@ public class Porta{
|
||||
encode();
|
||||
return outputString;
|
||||
}
|
||||
//Sets the keyword and inputString and decodes the message
|
||||
public String decode(String keyword, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
//Set the parameters
|
||||
reset();
|
||||
@@ -163,16 +205,22 @@ public class Porta{
|
||||
return outputString;
|
||||
}
|
||||
|
||||
//Returns the inputString
|
||||
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
|
||||
public void reset(){
|
||||
logger.debug("Resetting fields");
|
||||
|
||||
inputString = "";
|
||||
outputString = "";
|
||||
keyword = "";
|
||||
|
||||
@@ -1,31 +1,42 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/Substitution.java
|
||||
//Mattrixwv
|
||||
// Created: 02-22-22
|
||||
//Modified: 02-22-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
public class Substitution{
|
||||
private String inputString;
|
||||
private String outputString;
|
||||
private String key;
|
||||
private boolean preserveCapitals;
|
||||
private boolean preserveWhitespace;
|
||||
private boolean preserveSymbols;
|
||||
private static final Logger logger = LoggerFactory.getLogger(Substitution.class);
|
||||
|
||||
//Fields
|
||||
private String inputString; //The string that needs encoded/decoded
|
||||
private String outputString; //The encoded/decoded string
|
||||
private String key; //The keyword used to encode/decode the input
|
||||
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
|
||||
|
||||
//Ensures key constraints are followed
|
||||
private void setKey(String key) throws InvalidKeywordException{
|
||||
if(key == null){
|
||||
throw new InvalidKeywordException("Key cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Original key '{}'", key);
|
||||
|
||||
//Transform all letters to uppercase
|
||||
logger.debug("Removing case");
|
||||
key = key.toUpperCase();
|
||||
|
||||
//Make sure the key contains no duplicate mappings
|
||||
logger.debug("Ensuring there are no duplicate mappings");
|
||||
String tempKey = key.replaceAll("(.)\\1{2}", "");
|
||||
if(!tempKey.equals(key)){
|
||||
throw new InvalidKeywordException("The key cannot contain duplicate mappings");
|
||||
@@ -33,6 +44,8 @@ public class Substitution{
|
||||
|
||||
//Make sure the key is a valid length
|
||||
if(key.length() == 26){
|
||||
logger.debug("Ensuring there are only letters in the key");
|
||||
|
||||
//Make sure the key contains all valid characters
|
||||
tempKey = key.replaceAll("[^A-Z]", "");
|
||||
if(!tempKey.equals(key)){
|
||||
@@ -40,6 +53,8 @@ public class Substitution{
|
||||
}
|
||||
}
|
||||
else if(key.length() == 36){
|
||||
logger.debug("Ensure there are only alpha-numeric characters in the key");
|
||||
|
||||
//Make sure the key contains all valid characters
|
||||
tempKey = key.replaceAll("[^A-Z0-9]", "");
|
||||
if(!tempKey.equals(key)){
|
||||
@@ -51,25 +66,36 @@ public class Substitution{
|
||||
}
|
||||
|
||||
//Save the key
|
||||
logger.debug("Cleaned key '{}'", key);
|
||||
this.key = key;
|
||||
}
|
||||
//Ensure intput constraints are followed
|
||||
private void setInputString(String inputString) throws InvalidInputException{
|
||||
if(inputString == null){
|
||||
throw new InvalidInputException("Input cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Original input string '{}'", inputString);
|
||||
|
||||
//Remove any data that should not be preserved
|
||||
if(!preserveCapitals){
|
||||
logger.debug("Removing case");
|
||||
|
||||
inputString = inputString.toUpperCase();
|
||||
}
|
||||
if(!preserveWhitespace){
|
||||
logger.debug("Removing whitespace");
|
||||
|
||||
inputString = inputString.replaceAll("\\s", "");
|
||||
}
|
||||
if(!preserveSymbols){
|
||||
logger.debug("Removing symbols");
|
||||
|
||||
inputString = inputString.replaceAll("[^a-zA-Z\\s]", "");
|
||||
}
|
||||
|
||||
//Save the inputString
|
||||
logger.debug("Cleaned input string '{}'", inputString);
|
||||
this.inputString = inputString;
|
||||
|
||||
//Make sure there is still input
|
||||
@@ -77,46 +103,71 @@ public class Substitution{
|
||||
throw new InvalidInputException("Input must contain at least 1 letter");
|
||||
}
|
||||
}
|
||||
//Encodes the inputString and stores the result in outputString
|
||||
private void encode(){
|
||||
logger.debug("Encoding");
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
|
||||
//Step through every character in the inputString and convert it
|
||||
for(char ch : inputString.toCharArray()){
|
||||
logger.debug("Working character {}", ch);
|
||||
|
||||
if(Character.isUpperCase(ch)){
|
||||
logger.debug("Encoding uppercase");
|
||||
output.append(Character.toUpperCase(key.charAt(ch - 'A')));
|
||||
}
|
||||
else if(Character.isLowerCase(ch)){
|
||||
logger.debug("Encoding lowercase");
|
||||
output.append(Character.toLowerCase(key.charAt(ch - 'a')));
|
||||
}
|
||||
else if(Character.isDigit(ch) && (key.length() == 36)){
|
||||
logger.debug("Encoding digit");
|
||||
output.append(key.charAt('Z' - 'A' + Integer.valueOf(Character.toString(ch)) + 1));
|
||||
}
|
||||
else{
|
||||
logger.debug("Passing symbol through");
|
||||
output.append(ch);
|
||||
}
|
||||
}
|
||||
|
||||
//Save the output
|
||||
logger.debug("Encoded message '{}'", output);
|
||||
this.outputString = output.toString();
|
||||
}
|
||||
//Decodes the inputString and stores the result in outputString
|
||||
private void decode(){
|
||||
logger.debug("Decoding");
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
|
||||
//Step through every character in the inputString and convert it
|
||||
for(char ch : inputString.toCharArray()){
|
||||
logger.debug("Working character {}", ch);
|
||||
|
||||
if(Character.isUpperCase(ch)){
|
||||
logger.debug("Encoding uppercase");
|
||||
|
||||
output.append((char)('A' + key.indexOf(Character.toUpperCase(ch))));
|
||||
}
|
||||
else if(Character.isLowerCase(ch)){
|
||||
logger.debug("Encoding lowercase");
|
||||
|
||||
output.append((char)('a' + key.indexOf(Character.toUpperCase(ch))));
|
||||
}
|
||||
else if(Character.isDigit(ch) && (key.length() == 36)){
|
||||
logger.debug("Encoding digit");
|
||||
|
||||
output.append((char)('0' + (key.indexOf(Character.toUpperCase(ch)) - 26)));
|
||||
}
|
||||
else{
|
||||
logger.debug("Passing through symbol");
|
||||
output.append(ch);
|
||||
}
|
||||
}
|
||||
|
||||
//Save the output
|
||||
logger.debug("Encoded message '{}'", output);
|
||||
this.outputString = output.toString();
|
||||
}
|
||||
|
||||
@@ -154,6 +205,8 @@ public class Substitution{
|
||||
return outputString;
|
||||
}
|
||||
public void reset(){
|
||||
logger.debug("Resetting fields");
|
||||
|
||||
inputString = "";
|
||||
outputString = "";
|
||||
key = "";
|
||||
|
||||
@@ -1,18 +1,24 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/Vigenere.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-25-21
|
||||
//Modified: 02-22-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
public class Vigenere{
|
||||
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
|
||||
@@ -23,6 +29,8 @@ public class Vigenere{
|
||||
|
||||
//Uses keyword to calculate the offset for the Caesar cipher for each character
|
||||
protected void setOffset(){
|
||||
logger.debug("Setting offset array from keyword");
|
||||
|
||||
//Reserve the correct size to increase speed later
|
||||
offset.ensureCapacity(keyword.length());
|
||||
|
||||
@@ -31,6 +39,8 @@ public class Vigenere{
|
||||
char letter = keyword.charAt(cnt);
|
||||
offset.add((letter - 'A') % 26);
|
||||
}
|
||||
|
||||
logger.debug("Offset {}", offset);
|
||||
}
|
||||
//Sets inputString
|
||||
protected void setInputString(String inputString) throws InvalidInputException{
|
||||
@@ -38,16 +48,25 @@ public class Vigenere{
|
||||
throw new NullPointerException("Input cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Original input string '{}'", inputString);
|
||||
|
||||
if(!preserveCapitals){
|
||||
logger.debug("Removing case");
|
||||
|
||||
inputString = inputString.toUpperCase();
|
||||
}
|
||||
if(!preserveWhitespace){
|
||||
logger.debug("Removing whitespace");
|
||||
|
||||
inputString = inputString.replaceAll("\\s", "");
|
||||
}
|
||||
if(!preserveSymbols){
|
||||
logger.debug("Removing symbols");
|
||||
|
||||
inputString = inputString.replaceAll("[^a-zA-Z\\s]", "");
|
||||
}
|
||||
|
||||
logger.debug("Cleaned input string '{}'", inputString);
|
||||
this.inputString = inputString;
|
||||
|
||||
if(this.inputString.isBlank()){
|
||||
@@ -60,11 +79,17 @@ public class Vigenere{
|
||||
throw new NullPointerException("Keyword cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Original keyword '{}'", keyword);
|
||||
|
||||
//Convert all letters to uppercase
|
||||
logger.debug("Removing case");
|
||||
keyword = keyword.toUpperCase();
|
||||
//Remove all characters except capital letters
|
||||
logger.debug("Removing all non-letter characters");
|
||||
keyword = keyword.replaceAll("[^A-Z]", "");
|
||||
|
||||
//Save the string
|
||||
logger.debug("Clean keyword '{}'", keyword);
|
||||
this.keyword = keyword;
|
||||
|
||||
//Make sure offset is empty before adding to it
|
||||
@@ -78,67 +103,113 @@ public class Vigenere{
|
||||
}
|
||||
//Encodes inputString and stores the result in outputString
|
||||
protected String encode(){
|
||||
logger.debug("Encoding");
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
|
||||
//Step through every character in the inputString and advance it the correct amount, according to offset
|
||||
int offsetCnt = 0;
|
||||
for(int inputCnt = 0;inputCnt < inputString.length();++inputCnt){
|
||||
char letter = inputString.charAt(inputCnt);
|
||||
logger.debug("Working character {}", letter);
|
||||
|
||||
if(Character.isUpperCase(letter)){
|
||||
logger.debug("Encoding uppercase");
|
||||
|
||||
letter += offset.get((offsetCnt++) % offset.size());
|
||||
|
||||
//Make sure the character is still a letter, if not, wrap around
|
||||
if(letter < 'A'){
|
||||
logger.debug("Wrapping around to Z");
|
||||
|
||||
letter += 26;
|
||||
}
|
||||
else if(letter > 'Z'){
|
||||
logger.debug("Wrapping around to A");
|
||||
|
||||
letter -= 26;
|
||||
}
|
||||
}
|
||||
else if(Character.isLowerCase(letter)){
|
||||
logger.debug("Encoding lowercase");
|
||||
|
||||
letter += offset.get((offsetCnt++) % offset.size());
|
||||
|
||||
//Make sure the character is still a letter, if not, wrap around
|
||||
if(letter < 'a'){
|
||||
logger.debug("Wrapping around to z");
|
||||
|
||||
letter += 26;
|
||||
}
|
||||
else if(letter > 'z'){
|
||||
logger.debug("Wrapping around to a");
|
||||
|
||||
letter -= 26;
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Encoded character {}", letter);
|
||||
output.append(letter);
|
||||
}
|
||||
|
||||
//Save output
|
||||
logger.debug("Encoded message '{}'", output);
|
||||
outputString = output.toString();
|
||||
return outputString;
|
||||
}
|
||||
//Decodes inputString and stores the result in outputString
|
||||
protected String decode(){
|
||||
logger.debug("Decoding");
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
|
||||
//Step through every character in the inputString and advance it the correct amount, according to offset
|
||||
int offsetCnt = 0;
|
||||
for(int letterCnt = 0;letterCnt < inputString.length();++letterCnt){
|
||||
char letter = inputString.charAt(letterCnt);
|
||||
|
||||
logger.debug("Working character {}", letter);
|
||||
|
||||
if(Character.isUpperCase(letter)){
|
||||
logger.debug("Decoding uppercase");
|
||||
|
||||
letter -= offset.get((offsetCnt++) % offset.size());
|
||||
|
||||
if(letter < 'A'){
|
||||
logger.debug("Wrapping around to Z");
|
||||
|
||||
letter += 26;
|
||||
}
|
||||
else if(letter > 'Z'){
|
||||
logger.debug("Wrapping around to A");
|
||||
|
||||
letter -= 26;
|
||||
}
|
||||
}
|
||||
else if(Character.isLowerCase(letter)){
|
||||
logger.debug("Decoding lowercase");
|
||||
|
||||
letter -= offset.get((offsetCnt++) % offset.size());
|
||||
|
||||
if(letter < 'a'){
|
||||
logger.debug("Wrapping around to z");
|
||||
|
||||
letter += 26;
|
||||
}
|
||||
else if(letter > 'z'){
|
||||
logger.debug("Wrapping around to a");
|
||||
|
||||
letter -= 26;
|
||||
}
|
||||
}
|
||||
|
||||
//Add letter to output
|
||||
logger.debug("Encoded letter {}", letter);
|
||||
output.append(letter);
|
||||
}
|
||||
|
||||
//Save output
|
||||
logger.debug("Encoded message '{}'", output);
|
||||
outputString = output.toString();
|
||||
return outputString;
|
||||
}
|
||||
@@ -191,6 +262,8 @@ public class Vigenere{
|
||||
}
|
||||
//Makes sure all of the variables are empty
|
||||
public void reset(){
|
||||
logger.debug("Resetting fields");
|
||||
|
||||
inputString = "";
|
||||
outputString = "";
|
||||
keyword = "";
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/polySubstitution/Bifid.java
|
||||
//Mattrixwv
|
||||
// Created: 03-03-22
|
||||
//Modified: 03-03-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
public class Bifid{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Bifid.class);
|
||||
|
||||
//Fields
|
||||
private String inputString; //The message that needs to be encoded/decoded
|
||||
private String outputString; //The encoded/decoded message
|
||||
private String keyword; //The keyword used to create the grid
|
||||
@@ -17,6 +25,7 @@ public class Bifid{
|
||||
private boolean preserveWhitespace; //Persist whitespace in the output string
|
||||
private boolean preserveSymbols; //Persist symbols in the output string
|
||||
|
||||
|
||||
//Strips invalid characters from the keyword and creates the grid
|
||||
private void setKeyword(String keyword) throws InvalidKeywordException{
|
||||
//Ensure the keyword isn't null
|
||||
@@ -24,6 +33,8 @@ public class Bifid{
|
||||
throw new InvalidKeywordException("Keyword cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Setting keyword '{}'", keyword);
|
||||
|
||||
//Save the key for polybius to deal with
|
||||
this.keyword = keyword;
|
||||
}
|
||||
@@ -34,18 +45,27 @@ public class Bifid{
|
||||
throw new InvalidInputException("Input cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Original input string '{}'", inputString);
|
||||
|
||||
//Apply removal options
|
||||
if(!preserveCapitals){
|
||||
logger.debug("Removing case");
|
||||
|
||||
inputString = inputString.toUpperCase();
|
||||
}
|
||||
if(!preserveWhitespace){
|
||||
logger.debug("Removing whitespace");
|
||||
|
||||
inputString = inputString.replaceAll("\\s", "");
|
||||
}
|
||||
if(!preserveSymbols){
|
||||
logger.debug("Removing symbols");
|
||||
|
||||
inputString = inputString.replaceAll("[^a-zA-Z\\s]", "");
|
||||
}
|
||||
|
||||
//Save the string
|
||||
logger.debug("Cleaned input string '{}'", inputString);
|
||||
this.inputString = inputString;
|
||||
|
||||
//Ensure the string isn't blank
|
||||
@@ -55,47 +75,65 @@ public class Bifid{
|
||||
}
|
||||
//Adds all non-letter characters back to the output string
|
||||
private void formatOutput(String outputString){
|
||||
logger.debug("Formatting output");
|
||||
//Keep track of where you are in the output
|
||||
int outputCnt = 0;
|
||||
StringBuilder output = new StringBuilder();
|
||||
//Check every character in the input and apply the correct rules to the output
|
||||
for(char ch : inputString.toCharArray()){
|
||||
logger.debug("Current character {}", ch);
|
||||
if(Character.isUpperCase(ch)){
|
||||
logger.debug("Altering uppercase");
|
||||
|
||||
output.append(Character.toUpperCase(outputString.charAt(outputCnt++)));
|
||||
}
|
||||
else if(Character.isLowerCase(ch)){
|
||||
logger.debug("Altering lowercase");
|
||||
|
||||
output.append(Character.toLowerCase(outputString.charAt(outputCnt++)));
|
||||
}
|
||||
else{
|
||||
logger.debug("Adding symbol");
|
||||
|
||||
output.append(ch);
|
||||
}
|
||||
}
|
||||
|
||||
//Save the output
|
||||
logger.debug("Formatted output string '{}'", output);
|
||||
this.outputString = output.toString();
|
||||
}
|
||||
//Encodes inputString using a polybius square and stores the result in outputString
|
||||
private void encode() throws InvalidCharacterException, InvalidInputException{
|
||||
logger.debug("Encoding");
|
||||
|
||||
//Get the encoded numbers from a polybius square
|
||||
String numberResult = polybiusSquare.encode(keyword, inputString).replaceAll("\\s", "");
|
||||
logger.debug("Encoding polybius");
|
||||
String polybiusMessage = polybiusSquare.encode(keyword, inputString).replaceAll("\\s", "");
|
||||
keyword = polybiusSquare.getKeyword(); //Save the cleaned keyword
|
||||
|
||||
//Split the numbers into 2 rows and rejoin the rows to create a new string
|
||||
StringBuilder row0 = new StringBuilder();
|
||||
StringBuilder row1 = new StringBuilder();
|
||||
boolean firstNum = true;
|
||||
for(char ch : numberResult.toCharArray()){
|
||||
logger.debug("Splitting Polybius Square message");
|
||||
for(char ch : polybiusMessage.toCharArray()){
|
||||
logger.debug("Current character {}", ch);
|
||||
|
||||
if(firstNum){
|
||||
row0.append(ch);
|
||||
}
|
||||
else{
|
||||
row1.append(ch);
|
||||
}
|
||||
|
||||
firstNum = !firstNum;
|
||||
}
|
||||
|
||||
String shuffledResult = row0.toString() + row1.toString();
|
||||
|
||||
//Take the new string and decode the numbers using polybius
|
||||
logger.debug("Decoding Polybius Square");
|
||||
String letterResult = polybiusSquare.decode(keyword, shuffledResult);
|
||||
|
||||
//Format the output
|
||||
@@ -103,7 +141,10 @@ public class Bifid{
|
||||
}
|
||||
//Decodes inputString using a polybius square and stores the result in outputString
|
||||
private void decode() throws InvalidCharacterException, InvalidInputException{
|
||||
logger.debug("Decoding");
|
||||
|
||||
//Get the decoded number from a polybius square
|
||||
logger.debug("Encoding Polybius Square");
|
||||
String numberResult = polybiusSquare.encode(keyword, inputString).replaceAll("\\s", "");
|
||||
keyword = polybiusSquare.getKeyword();
|
||||
|
||||
@@ -111,12 +152,16 @@ public class Bifid{
|
||||
String row0 = numberResult.substring(0, numberResult.length() / 2);
|
||||
String row1 = numberResult.substring(numberResult.length() / 2);
|
||||
StringBuilder unshuffledResult = new StringBuilder();
|
||||
logger.debug("Splitting Polybius Square message");
|
||||
for(int cnt = 0;cnt < row0.length();++cnt){
|
||||
logger.debug("Current characters {} {}", row0.charAt(cnt), row1.charAt(cnt));
|
||||
|
||||
unshuffledResult.append(row0.charAt(cnt));
|
||||
unshuffledResult.append(row1.charAt(cnt));
|
||||
}
|
||||
|
||||
//Take the new string and decode the numbers using polybius
|
||||
logger.debug("Decoding Polybius Square");
|
||||
String letterResult = polybiusSquare.decode(keyword, unshuffledResult.toString());
|
||||
|
||||
//Format the outputString
|
||||
@@ -162,12 +207,6 @@ public class Bifid{
|
||||
return outputString;
|
||||
}
|
||||
|
||||
//Makes sure all variables are empty
|
||||
public void reset(){
|
||||
inputString = "";
|
||||
outputString = "";
|
||||
keyword = "";
|
||||
}
|
||||
//Gets
|
||||
public String getInputString(){
|
||||
return inputString;
|
||||
@@ -178,4 +217,12 @@ public class Bifid{
|
||||
public String getKeyword(){
|
||||
return keyword;
|
||||
}
|
||||
//Makes sure all variables are empty
|
||||
public void reset(){
|
||||
logger.debug("Resetting fields");
|
||||
|
||||
inputString = "";
|
||||
outputString = "";
|
||||
keyword = "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//MattrixwvWebsite/src/main/java/com/mattrixwv/CipherStreamJava/polySubstitution/Columnar.java
|
||||
//Mattrixwv
|
||||
// Created: 01-16-22
|
||||
//Modified: 03-03-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
@@ -9,12 +9,18 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
public class Columnar{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Columnar.class);
|
||||
|
||||
//Fields
|
||||
private String inputString; //The message that needs to be encoded/decoded
|
||||
private String outputString; //The encoded/decoded message
|
||||
private String keyword; //The keyword used to create the grid
|
||||
@@ -28,10 +34,13 @@ public class Columnar{
|
||||
|
||||
//Strip the inputString of all non-letter characters and change them to capitals
|
||||
private String getCleanInputString(){
|
||||
logger.debug("Cleaning input string");
|
||||
return inputString.toUpperCase().replaceAll("[^A-Z]", "");
|
||||
}
|
||||
//Create the grid from the keyword
|
||||
private void createGridEncode(){
|
||||
logger.debug("Creating grid for encoding");
|
||||
|
||||
//Add the keyword to the first row in the array
|
||||
grid = new ArrayList<>();
|
||||
grid.add(new ArrayList<>(Arrays.asList(keyword.chars().mapToObj(c -> (char)c).toArray(Character[]::new))));
|
||||
@@ -49,6 +58,8 @@ public class Columnar{
|
||||
}
|
||||
}
|
||||
private void createGridDecode(){
|
||||
logger.debug("Creating grid for decoding");
|
||||
|
||||
//Add the keyword to the first row in the array
|
||||
grid = new ArrayList<>();
|
||||
StringBuilder orderedKeyword = new StringBuilder();
|
||||
@@ -76,19 +87,29 @@ public class Columnar{
|
||||
}
|
||||
//Strips invalid characters from the string that needs encoded/decoded
|
||||
private void setInputStringEncode(String inputString) throws InvalidInputException{
|
||||
logger.debug("Setting input string for encoding");
|
||||
|
||||
//Ensure the input isn't null
|
||||
if(inputString == null){
|
||||
throw new InvalidInputException("Input must not be null");
|
||||
}
|
||||
|
||||
logger.debug("Original input string '{}'", inputString);
|
||||
|
||||
//Apply removal options
|
||||
if(!preserveCapitals){
|
||||
logger.debug("Removing case");
|
||||
|
||||
inputString = inputString.toUpperCase();
|
||||
}
|
||||
if(!preserveWhitespace){
|
||||
logger.debug("Removing whitespace");
|
||||
|
||||
inputString = inputString.replaceAll("\\s", "");
|
||||
}
|
||||
if(!preserveSymbols){
|
||||
logger.debug("Remoing symbols");
|
||||
|
||||
inputString = inputString.replaceAll("[^a-zA-Z\\s]", "");
|
||||
}
|
||||
|
||||
@@ -100,6 +121,8 @@ public class Columnar{
|
||||
int charsToAdd = (cleanLength % keyword.length());
|
||||
if(charsToAdd != 0){
|
||||
charsToAdd = keyword.length() - charsToAdd;
|
||||
|
||||
logger.debug("Appending {} characters", charsToAdd);
|
||||
}
|
||||
for(int cnt = 0;cnt < charsToAdd;++cnt){
|
||||
inputStringBuilder.append(characterToAdd);
|
||||
@@ -108,6 +131,7 @@ public class Columnar{
|
||||
inputString = inputStringBuilder.toString();
|
||||
|
||||
//Save the string
|
||||
logger.debug("Cleaned input string '{}'", inputString);
|
||||
this.inputString = inputString;
|
||||
|
||||
//Ensure the string isn't blank
|
||||
@@ -116,19 +140,29 @@ public class Columnar{
|
||||
}
|
||||
}
|
||||
private void setInputStringDecode(String inputString) throws InvalidInputException{
|
||||
logger.debug("Setting input string for decoding");
|
||||
|
||||
//Ensure the input isn't null
|
||||
if(inputString == null){
|
||||
throw new InvalidInputException("Input must not be null");
|
||||
}
|
||||
|
||||
logger.debug("Original input string '{}'", inputString);
|
||||
|
||||
//Apply removal options
|
||||
if(!preserveCapitals){
|
||||
logger.debug("Removing case");
|
||||
|
||||
inputString = inputString.toUpperCase();
|
||||
}
|
||||
if(!preserveWhitespace){
|
||||
logger.debug("Removing whitespace");
|
||||
|
||||
inputString = inputString.replaceAll("[\\s]", "");
|
||||
}
|
||||
if(!preserveSymbols){
|
||||
logger.debug("Removing symbols");
|
||||
|
||||
inputString = inputString.replaceAll("[^a-zA-Z\\s]", "");
|
||||
}
|
||||
|
||||
@@ -182,6 +216,7 @@ public class Columnar{
|
||||
}
|
||||
|
||||
//Save the input
|
||||
logger.debug("Cleaned input string '{}'", inputString);
|
||||
this.inputString = inputString;
|
||||
|
||||
//Ensure the string isn't blank
|
||||
@@ -191,7 +226,10 @@ public class Columnar{
|
||||
}
|
||||
//Creates the output string from the grid
|
||||
private void createOutputStringFromColumns(){
|
||||
logger.debug("Creating output string for encoding");
|
||||
|
||||
//Get the current rows of any characters that you added
|
||||
logger.debug("Getting added characters");
|
||||
ArrayList<Integer> colsAddedTo = new ArrayList<>();
|
||||
if(removePadding){
|
||||
ArrayList<Integer> cols = getKeywordOriginalLocations();
|
||||
@@ -205,6 +243,7 @@ public class Columnar{
|
||||
}
|
||||
|
||||
//Turn the grid into a string
|
||||
logger.debug("Turning grid into string");
|
||||
StringBuilder gridOutput = new StringBuilder();
|
||||
for(int col = 0;col < grid.get(0).size();++col){
|
||||
for(int row = 1;row < grid.size();++row){
|
||||
@@ -216,6 +255,7 @@ public class Columnar{
|
||||
}
|
||||
|
||||
//Preserve any remaining symbols in the string
|
||||
logger.debug("Formatting output string");
|
||||
StringBuilder output = new StringBuilder();
|
||||
for(int outputLoc = 0, inputLoc = 0;inputLoc < (inputString.length() - charsAdded);){
|
||||
char inputChar = inputString.charAt(inputLoc++);
|
||||
@@ -231,10 +271,14 @@ public class Columnar{
|
||||
}
|
||||
|
||||
//Save and return the output
|
||||
logger.debug("Output string '{}'", output);
|
||||
outputString = output.toString();
|
||||
}
|
||||
private void createOutputStringFromRows(){
|
||||
logger.debug("Creating output string for decoding");
|
||||
|
||||
//Turn the grid into a string
|
||||
logger.debug("Transforming grid to a string");
|
||||
StringBuilder gridOutput = new StringBuilder();
|
||||
for(int row = 1;row < grid.size();++row){
|
||||
for(int col = 0;col < grid.get(row).size();++col){
|
||||
@@ -242,6 +286,7 @@ public class Columnar{
|
||||
}
|
||||
}
|
||||
//Remove any added characters
|
||||
logger.debug("Removing padding");
|
||||
if(removePadding){
|
||||
for(int cnt = 0;cnt < charsAdded;++cnt){
|
||||
gridOutput.deleteCharAt(gridOutput.length() - 1);
|
||||
@@ -260,6 +305,7 @@ public class Columnar{
|
||||
}
|
||||
}
|
||||
//Preserve any remaining symbols in the string
|
||||
logger.debug("Formatting output string");
|
||||
StringBuilder output = new StringBuilder();
|
||||
for(int outputLoc = 0, inputLoc = 0, row = 1, col = 0;inputLoc < inputString.length();){
|
||||
char inputChar = inputString.charAt(inputLoc++);
|
||||
@@ -288,6 +334,7 @@ public class Columnar{
|
||||
}
|
||||
|
||||
//Save and return the output
|
||||
logger.debug("Decoded output string '{}'", output);
|
||||
outputString = output.toString();
|
||||
}
|
||||
//Strips invalid characters from the keyword and creates the grid
|
||||
@@ -297,9 +344,13 @@ public class Columnar{
|
||||
throw new NullPointerException("Keyword cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Original keyword {}", keyword);
|
||||
|
||||
//Strip all non-letter characters and change them to uppercase
|
||||
this.keyword = keyword.toUpperCase().replaceAll("[^A-Z]", "");
|
||||
|
||||
logger.debug("Cleaned keyword {}", keyword);
|
||||
|
||||
//Make sure a valid keyword is present
|
||||
if(this.keyword.length() < 2){
|
||||
throw new InvalidKeywordException("The keyword must contain at least 2 letters");
|
||||
@@ -311,17 +362,23 @@ public class Columnar{
|
||||
throw new InvalidCharacterException("Character to add must be a letter");
|
||||
}
|
||||
|
||||
logger.debug("Setting character to add");
|
||||
|
||||
if(!preserveCapitals){
|
||||
this.characterToAdd = Character.toUpperCase(characterToAdd);
|
||||
}
|
||||
else{
|
||||
this.characterToAdd = characterToAdd;
|
||||
}
|
||||
|
||||
logger.debug("Character to add for padding {}", characterToAdd);
|
||||
}
|
||||
//Returns a list of integers that represents the location of the characters of the keyword in alphabetic order
|
||||
private ArrayList<Integer> getKeywordAlphaLocations(){
|
||||
logger.debug("Creating an array of keyword letter locations");
|
||||
|
||||
ArrayList<Integer> orderedLocations = new ArrayList<>();
|
||||
//go through every letter and check it against the keyword
|
||||
//Go through every letter and check it against the keyword
|
||||
for(char ch = 'A';ch <= 'Z';++ch){
|
||||
for(int cnt = 0;cnt < keyword.length();++cnt){
|
||||
//If the current letter is the same as the letter we are looking for add the location to the array
|
||||
@@ -332,9 +389,12 @@ public class Columnar{
|
||||
}
|
||||
|
||||
//Return the alphabetic locations
|
||||
logger.debug("Array of keyword letters {}", orderedLocations);
|
||||
return orderedLocations;
|
||||
}
|
||||
private ArrayList<Integer> getKeywordOriginalLocations(){
|
||||
logger.debug("Creating array of original keyword locations");
|
||||
|
||||
//Figure out the order the columns are in
|
||||
ArrayList<Integer> orderedLocations = getKeywordAlphaLocations();
|
||||
//Figure out what order the columns need rearanged to
|
||||
@@ -347,10 +407,15 @@ public class Columnar{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Returning the locations
|
||||
logger.debug("Array of keyword letters {}", orderedLocations);
|
||||
return originalOrder;
|
||||
}
|
||||
//Rearanges the grid based on the list of numbers given
|
||||
private void rearangeGrid(ArrayList<Integer> listOrder){
|
||||
logger.debug("Rearanging grid");
|
||||
|
||||
//Create a new grid and make sure it is the same size as the original grid
|
||||
int numCol = grid.get(0).size();
|
||||
ArrayList<ArrayList<Character>> newGrid = new ArrayList<>(grid.size());
|
||||
@@ -366,10 +431,13 @@ public class Columnar{
|
||||
}
|
||||
|
||||
//Save the new grid
|
||||
logger.debug("New grid {}", newGrid);
|
||||
grid = newGrid;
|
||||
}
|
||||
//Encodes inputString using the Columnar cipher and stores the result in outputString
|
||||
private void encode(){
|
||||
logger.debug("Encoding");
|
||||
|
||||
//Create the grid
|
||||
createGridEncode();
|
||||
//Figure out the new column order
|
||||
@@ -381,6 +449,8 @@ public class Columnar{
|
||||
}
|
||||
//Decodes inputString using the Columnar cipher and stores the result in outputString
|
||||
private void decode(){
|
||||
logger.debug("Decoding");
|
||||
|
||||
//Create the grid
|
||||
createGridDecode();
|
||||
ArrayList<Integer> originalOrder = getKeywordOriginalLocations();
|
||||
@@ -440,6 +510,8 @@ public class Columnar{
|
||||
|
||||
//Makes sure all variables are empty
|
||||
public void reset(){
|
||||
logger.debug("Resetting fields");
|
||||
|
||||
inputString = "";
|
||||
outputString = "";
|
||||
keyword = "";
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
import java.security.InvalidKeyException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeyException;
|
||||
import com.mattrixwv.matrix.ModMatrix;
|
||||
import com.mattrixwv.matrix.exceptions.InvalidGeometryException;
|
||||
import com.mattrixwv.matrix.exceptions.InvalidScalarException;
|
||||
|
||||
@@ -1,15 +1,22 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/polySubstitution/Playfair.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-30-21
|
||||
//Modified: 02-17-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
|
||||
|
||||
public class Playfair{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Playfair.class);
|
||||
|
||||
//A class representing the location of a character in the grid
|
||||
private class CharLocation{
|
||||
private int x;
|
||||
@@ -26,7 +33,7 @@ public class Playfair{
|
||||
}
|
||||
}
|
||||
|
||||
//Variables
|
||||
//Fields
|
||||
private boolean preserveCapitals; //Whether to respect captials 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
|
||||
@@ -39,12 +46,16 @@ public class Playfair{
|
||||
private char[][] grid; //The grid used to encode/decode the message
|
||||
//Create the grid from the keyword
|
||||
private void createGrid(){
|
||||
logger.debug("Creating grid from keyword");
|
||||
|
||||
for(int row = 0;row < 5;++row){
|
||||
for(int col = 0;col < 5;++col){
|
||||
char letter = keyword.charAt((5 * row) + col);
|
||||
grid[row][col] = letter;
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Grid\n{}", getGrid());
|
||||
}
|
||||
//Strips invalid characters from the string that needs encoded/decoded
|
||||
private void setInputString(String inputString, boolean encoding) throws InvalidCharacterException, InvalidInputException{
|
||||
@@ -53,26 +64,35 @@ public class Playfair{
|
||||
throw new NullPointerException("The input string cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Original input string {}", inputString);
|
||||
|
||||
//Set the options
|
||||
if(!preserveCapitals){
|
||||
logger.debug("Removing case");
|
||||
|
||||
inputString = inputString.toUpperCase();
|
||||
}
|
||||
if(!preserveWhitespace){
|
||||
logger.debug("Removing whitespace");
|
||||
|
||||
inputString = inputString.replaceAll("\\s", "");
|
||||
}
|
||||
if(!preserveSymbols){
|
||||
logger.debug("Removing symbols");
|
||||
|
||||
inputString = inputString.replaceAll("[^a-zA-Z\\s]", "");
|
||||
}
|
||||
|
||||
//Make replace all of the replacers with replaced
|
||||
inputString = inputString.replaceAll(Character.toString(replaced), Character.toString(replacer));
|
||||
logger.debug("Replacing all {} with {}", replaced, replacer);
|
||||
inputString = inputString.replace(Character.toString(replaced), Character.toString(replacer));
|
||||
|
||||
//If there is nothing in the input string throw an exception
|
||||
if(inputString.isBlank()){
|
||||
throw new InvalidCharacterException("The input string cannot be blank");
|
||||
}
|
||||
|
||||
//If this is encoding parse it and clean up an problems
|
||||
//If this is encoding parse it and clean up any problems
|
||||
if(encoding){
|
||||
setEncodingInputString(inputString);
|
||||
}
|
||||
@@ -83,6 +103,7 @@ public class Playfair{
|
||||
throw new InvalidCharacterException("An encoded message cannot contain a letter that needs replaced");
|
||||
}
|
||||
|
||||
logger.debug("Clean input string '{}'", inputString);
|
||||
this.inputString = inputString;
|
||||
}
|
||||
|
||||
@@ -92,7 +113,7 @@ public class Playfair{
|
||||
}
|
||||
private void setEncodingInputString(String inputString){
|
||||
//Replace characters that need replaced
|
||||
inputString = inputString.replaceAll(Character.toString(replaced), Character.toString(replacer));
|
||||
inputString = inputString.replace(Character.toString(replaced), Character.toString(replacer));
|
||||
|
||||
//Check if there are any doubled characters
|
||||
StringBuilder cleanInput = new StringBuilder();
|
||||
@@ -152,12 +173,18 @@ public class Playfair{
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Cleaned input string '{}'", cleanInput);
|
||||
this.inputString = cleanInput.toString();
|
||||
}
|
||||
//Returns the input string ready for encoding
|
||||
private String getPreparedInputString(){
|
||||
logger.debug("Getting input string ready for encoding");
|
||||
|
||||
String cleanString = inputString.toUpperCase();
|
||||
cleanString = cleanString.replaceAll("[^A-Z]", "");
|
||||
|
||||
logger.debug("Prepared string '{}'", cleanString);
|
||||
|
||||
return cleanString;
|
||||
}
|
||||
//Strips invalid characters from the keyword and creates the grid
|
||||
@@ -166,19 +193,26 @@ public class Playfair{
|
||||
throw new NullPointerException("Keyword cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Original keyword {}", keyword);
|
||||
|
||||
//Change everything to uppercase
|
||||
logger.debug("Removing case");
|
||||
keyword = keyword.toUpperCase();
|
||||
|
||||
//Removing everything except capital letters
|
||||
logger.debug("Removing all non-letter characters");
|
||||
keyword = keyword.replaceAll("[^A-Z]", "");
|
||||
|
||||
//Add all letters in the alphabet to the key
|
||||
logger.debug("Appending the alphabet to the keyword");
|
||||
keyword += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
//Replace all replaced characters
|
||||
logger.debug("Replacing {} with {}", replaced, replacer);
|
||||
keyword = keyword.replaceAll(Character.toString(replaced), Character.toString(replacer));
|
||||
|
||||
//Remove all duplicate chatacters
|
||||
logger.debug("Removing duplicated characters");
|
||||
StringBuilder uniqueKey = new StringBuilder();
|
||||
keyword.chars().distinct().forEach(c -> uniqueKey.append((char)c));
|
||||
this.keyword = uniqueKey.toString();
|
||||
@@ -188,45 +222,69 @@ public class Playfair{
|
||||
}
|
||||
//Returns the location of the given character in the grid
|
||||
private CharLocation findChar(char letter) throws InvalidInputException{
|
||||
logger.debug("Finding character in grid {}", letter);
|
||||
|
||||
for(int row = 0;row < grid.length;++row){
|
||||
for(int col = 0;col < grid[row].length;++col){
|
||||
if(grid[row][col] == letter){
|
||||
logger.debug("Found at {}, {}", row, col);
|
||||
|
||||
return new CharLocation(row, col);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//If it was not found something went wrong
|
||||
throw new InvalidInputException("The character '" + letter + "' was not found in the grid");
|
||||
}
|
||||
//Returns the location in the grid of x and y, adjusting for out of bounds
|
||||
private char getGridChar(int x, int y){
|
||||
logger.debug("Getting character from grid[{}][{}]", x, y);
|
||||
|
||||
if(x < 0){
|
||||
x += 5;
|
||||
}
|
||||
if(y < 0){
|
||||
y += 5;
|
||||
}
|
||||
return grid[x % 5][y % 5];
|
||||
|
||||
char letter = grid[x % 5][y % 5];
|
||||
logger.debug("Character {}", letter);
|
||||
return letter;
|
||||
}
|
||||
//Adds characters that aren't letters to the output
|
||||
private void addCharactersToCleanString(String cleanString){
|
||||
logger.debug("Formatting output string");
|
||||
|
||||
int outputCnt = 0;
|
||||
StringBuilder fullOutput = new StringBuilder();
|
||||
for(int inputCnt = 0;inputCnt < inputString.length();++inputCnt){
|
||||
logger.debug("Working character {}", inputString.charAt(inputCnt));
|
||||
|
||||
if(Character.isUpperCase(inputString.charAt(inputCnt))){
|
||||
logger.debug("Adjusting uppercase");
|
||||
|
||||
fullOutput.append(cleanString.charAt(outputCnt++));
|
||||
}
|
||||
else if(Character.isLowerCase(inputString.charAt(inputCnt))){
|
||||
logger.debug("Adjusting lowercase");
|
||||
|
||||
fullOutput.append(Character.toLowerCase(cleanString.charAt(outputCnt++)));
|
||||
}
|
||||
else{
|
||||
logger.debug("Inserting symbol");
|
||||
|
||||
fullOutput.append(inputString.charAt(inputCnt));
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Formatted output '{}'", fullOutput);
|
||||
outputString = fullOutput.toString();
|
||||
}
|
||||
//Encodes inputString using the Playfair cipher and stores the result in outputString
|
||||
private String encode() throws InvalidInputException{
|
||||
logger.debug("Encoding");
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
int inputCnt = 0;
|
||||
String cleanString = getPreparedInputString();
|
||||
@@ -235,25 +293,31 @@ public class Playfair{
|
||||
char firstLetter = cleanString.charAt(inputCnt++);
|
||||
char secondLetter = cleanString.charAt(inputCnt++);
|
||||
|
||||
logger.debug("Letters {} {}", firstLetter, secondLetter);
|
||||
|
||||
//Find the letters in the grid
|
||||
CharLocation firstLocation = findChar(firstLetter);
|
||||
CharLocation secondLocation = findChar(secondLetter);
|
||||
|
||||
//Encode the letters
|
||||
if(firstLocation.getX() == secondLocation.getX()){
|
||||
logger.debug("Row encoding");
|
||||
firstLetter = getGridChar(firstLocation.getX(), firstLocation.getY() + 1);
|
||||
secondLetter = getGridChar(secondLocation.getX(), secondLocation.getY() + 1);
|
||||
}
|
||||
else if(firstLocation.getY() == secondLocation.getY()){
|
||||
logger.debug("Column encoding");
|
||||
firstLetter = getGridChar(firstLocation.getX() + 1, firstLocation.getY());
|
||||
secondLetter = getGridChar(secondLocation.getX() + 1, secondLocation.getY());
|
||||
}
|
||||
else{
|
||||
logger.debug("Corner encoding");
|
||||
firstLetter = getGridChar(firstLocation.getX(), secondLocation.getY());
|
||||
secondLetter = getGridChar(secondLocation.getX(), firstLocation.getY());
|
||||
}
|
||||
|
||||
//Add the new letters to the output string
|
||||
logger.debug("Encoded letters {} {}", firstLetter, secondLetter);
|
||||
output.append(firstLetter);
|
||||
output.append(secondLetter);
|
||||
}
|
||||
@@ -266,6 +330,8 @@ public class Playfair{
|
||||
}
|
||||
//Decodes inputString using the Playfair cipher and stores the result in outputString
|
||||
private String decode() throws InvalidInputException{
|
||||
logger.debug("Decoding");
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
int inputCnt = 0;
|
||||
String cleanString = getPreparedInputString();
|
||||
@@ -274,25 +340,31 @@ public class Playfair{
|
||||
char firstLetter = cleanString.charAt(inputCnt++);
|
||||
char secondLetter = cleanString.charAt(inputCnt++);
|
||||
|
||||
logger.debug("Letters {} {}", firstLetter, secondLetter);
|
||||
|
||||
//Find the letters in the grid
|
||||
CharLocation firstLocation = findChar(firstLetter);
|
||||
CharLocation secondLocation = findChar(secondLetter);
|
||||
|
||||
//Decode the letters
|
||||
if(firstLocation.getX() == secondLocation.getX()){
|
||||
logger.debug("Decoding row");
|
||||
firstLetter = getGridChar(firstLocation.getX(), firstLocation.getY() - 1);
|
||||
secondLetter = getGridChar(secondLocation.getX(), secondLocation.getY() - 1);
|
||||
}
|
||||
else if(firstLocation.getY() == secondLocation.getY()){
|
||||
logger.debug("Decoding col");
|
||||
firstLetter = getGridChar(firstLocation.getX() - 1, firstLocation.getY());
|
||||
secondLetter = getGridChar(secondLocation.getX() - 1, secondLocation.getY());
|
||||
}
|
||||
else{
|
||||
logger.debug("Decoding corners");
|
||||
firstLetter = getGridChar(firstLocation.getX(), secondLocation.getY());
|
||||
secondLetter = getGridChar(secondLocation.getX(), firstLocation.getY());
|
||||
}
|
||||
|
||||
//Add the new letters to the output string
|
||||
logger.debug("Decoded letters {} {}", firstLetter, secondLetter);
|
||||
output.append(firstLetter);
|
||||
output.append(secondLetter);
|
||||
}
|
||||
@@ -348,6 +420,8 @@ public class Playfair{
|
||||
|
||||
//Makes sure all variables are empty
|
||||
public void reset(){
|
||||
logger.debug("Resetting fields");
|
||||
|
||||
grid = new char[5][5];
|
||||
inputString = "";
|
||||
outputString = "";
|
||||
@@ -425,11 +499,15 @@ public class Playfair{
|
||||
return outputString;
|
||||
}
|
||||
public String getGrid(){
|
||||
StringBuilder gridString = new StringBuilder();
|
||||
logger.debug("Creating string from grid");
|
||||
|
||||
StringJoiner gridString = new StringJoiner("\n");
|
||||
for(char[] row : grid){
|
||||
StringJoiner rowString = new StringJoiner(" ", "[", "]");
|
||||
for(char col : row){
|
||||
gridString.append(col);
|
||||
rowString.add(Character.toString(col));
|
||||
}
|
||||
gridString.add(rowString.toString());
|
||||
}
|
||||
|
||||
return gridString.toString();
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/polySubstitution/PolybiusSquare.java
|
||||
//Mattrixwv
|
||||
// Created: 01-04-22
|
||||
//Modified: 02-17-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
|
||||
|
||||
public class PolybiusSquare{
|
||||
private static final Logger logger = LoggerFactory.getLogger(PolybiusSquare.class);
|
||||
|
||||
//A class representing the location of a character in the grid
|
||||
protected class CharLocation{
|
||||
private int x;
|
||||
@@ -28,7 +33,7 @@ public class PolybiusSquare{
|
||||
}
|
||||
}
|
||||
|
||||
//Variables
|
||||
//Fields
|
||||
protected String inputString; //The message that needs to be encoded/decoded
|
||||
protected String outputString; //The encoded/decoded message
|
||||
protected String keyword; //The keyword used to create the grid
|
||||
@@ -40,12 +45,16 @@ public class PolybiusSquare{
|
||||
|
||||
//Create the grid from the keyword
|
||||
protected void createGrid(){
|
||||
logger.debug("Creating grid from keyword");
|
||||
|
||||
for(int row = 0;row < 5;++row){
|
||||
for(int col = 0;col < 5;++col){
|
||||
char letter = keyword.charAt((5 * row) + col);
|
||||
grid[row][col] = letter;
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Created grid\n{}", getGrid());
|
||||
}
|
||||
//Strips invalid characters from the string that needs encoded/decoded
|
||||
protected void setInputStringEncoding(String inputString) throws InvalidCharacterException, InvalidInputException{
|
||||
@@ -53,7 +62,10 @@ public class PolybiusSquare{
|
||||
throw new NullPointerException("Input cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Setting input string for encoding '{}'", inputString);
|
||||
|
||||
//Make sure the string doesn't contain any numbers
|
||||
logger.debug("Checking for digits");
|
||||
for(char ch = '0';ch <= '9';++ch){
|
||||
if(inputString.contains(Character.toString(ch))){
|
||||
throw new InvalidCharacterException("Inputs for encoding cannot contain numbers");
|
||||
@@ -61,15 +73,20 @@ public class PolybiusSquare{
|
||||
}
|
||||
|
||||
//Change to upper case
|
||||
logger.debug("Removing case");
|
||||
inputString = inputString.toUpperCase();
|
||||
|
||||
//Remove any whitespace if selected
|
||||
if(!preserveWhitespace){
|
||||
logger.debug("Removing whitespace");
|
||||
|
||||
inputString = inputString.replaceAll("\\s", "");
|
||||
}
|
||||
|
||||
//Remove any symbols if selected
|
||||
if(!preserveSymbols){
|
||||
logger.debug("Removing symbols");
|
||||
|
||||
inputString = inputString.replaceAll("[^a-zA-Z\\s]", "");
|
||||
}
|
||||
|
||||
@@ -83,9 +100,11 @@ public class PolybiusSquare{
|
||||
}
|
||||
|
||||
//Replace any characters that need replaced
|
||||
inputString = inputString.replaceAll(Character.toString(replaced), Character.toString(replacer));
|
||||
logger.debug("Replacing {} with {}", replaced, replacer);
|
||||
inputString = inputString.replace(Character.toString(replaced), Character.toString(replacer));
|
||||
|
||||
//Save the string
|
||||
logger.debug("Cleaned input string '{}'", inputString);
|
||||
this.inputString = inputString;
|
||||
|
||||
if(this.inputString.isBlank() || getPreparedInputStringEncoding().isBlank()){
|
||||
@@ -96,7 +115,11 @@ public class PolybiusSquare{
|
||||
if(inputString == null){
|
||||
throw new NullPointerException("Input cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Setting input string for decoding '{}'", inputString);
|
||||
|
||||
//Make sure the string contains an even number of digits and no letters
|
||||
logger.debug("Checking for letters");
|
||||
int numberOfDigits = 0;
|
||||
for(int cnt = 0;cnt < inputString.length();++cnt){
|
||||
char ch = inputString.charAt(cnt);
|
||||
@@ -113,15 +136,20 @@ public class PolybiusSquare{
|
||||
|
||||
//Remove any whitespace if selected
|
||||
if(!preserveWhitespace){
|
||||
logger.debug("Removing whitespace");
|
||||
|
||||
inputString = inputString.replaceAll("\\s", "");
|
||||
}
|
||||
|
||||
//Remove any symbols if selected
|
||||
if(!preserveSymbols){
|
||||
logger.debug("Removing symbols");
|
||||
|
||||
inputString = inputString.replaceAll("[^0-9\\s]", "");
|
||||
}
|
||||
|
||||
//Save the string
|
||||
logger.debug("Cleaned input string '{}'", inputString);
|
||||
this.inputString = inputString;
|
||||
|
||||
if(this.inputString.isBlank() || getPreparedInputStringDecoding().isBlank()){
|
||||
@@ -130,93 +158,139 @@ public class PolybiusSquare{
|
||||
}
|
||||
//Returns the input string ready for encoding
|
||||
protected String getPreparedInputStringEncoding(){
|
||||
logger.debug("Preparing input string for encoding");
|
||||
|
||||
String cleanString = inputString.toUpperCase();
|
||||
cleanString = cleanString.replaceAll("[^A-Z]", "");
|
||||
|
||||
logger.debug("Prepared string '{}'", cleanString);
|
||||
return cleanString;
|
||||
}
|
||||
protected String getPreparedInputStringDecoding(){
|
||||
return inputString.replaceAll("\\D", "");
|
||||
logger.debug("Prepareing input string for decoding");
|
||||
|
||||
String cleanString = inputString.replaceAll("\\D", "");
|
||||
|
||||
logger.debug("Prepared string '{}'", cleanString);
|
||||
return cleanString;
|
||||
}
|
||||
//Strips invalid characters from the keyword and creates the grid
|
||||
protected void setKeyword(String keyword){
|
||||
if(keyword == null){
|
||||
throw new NullPointerException("Keyword cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Original keyword {}", keyword);
|
||||
|
||||
//Change everything to uppercase
|
||||
logger.debug("Removing case");
|
||||
keyword = keyword.toUpperCase();
|
||||
|
||||
//Remove everything except capital letters
|
||||
logger.debug("Removing all non-letters");
|
||||
keyword = keyword.replaceAll("[^A-Z]", "");
|
||||
|
||||
//Add all letters in the alphabet to the key
|
||||
logger.debug("Appending entire alphabet");
|
||||
keyword += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
//Replace all replaced characters
|
||||
logger.debug("Replacing {} with {}", replaced, replacer);
|
||||
keyword = keyword.replaceAll(Character.toString(replaced), Character.toString(replacer));
|
||||
|
||||
//Remove all duplicate characters
|
||||
StringBuilder uniqueKey = new StringBuilder();
|
||||
keyword.chars().distinct().forEach(c -> uniqueKey.append((char)c));
|
||||
this.keyword = uniqueKey.toString();
|
||||
logger.debug("Cleaned keyword {}", keyword);
|
||||
|
||||
//Create the grid from the sanitized keyword
|
||||
createGrid();
|
||||
}
|
||||
//Returns the location of the given charcter in the grid
|
||||
protected CharLocation findChar(char letter) throws InvalidInputException{
|
||||
logger.debug("Finding {} in grid", letter);
|
||||
|
||||
for(int row = 0;row < grid.length;++row){
|
||||
for(int col = 0;col < grid[row].length;++col){
|
||||
if(grid[row][col] == letter){
|
||||
logger.debug("Found at {}, {}", row, col);
|
||||
return new CharLocation(row, col);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//If it was not found something went wrong
|
||||
throw new InvalidInputException("The character '" + letter + "' was not found in the grid");
|
||||
}
|
||||
//Adds characters that aren't letters to the output
|
||||
protected void addCharactersToCleanStringEncode(String cleanString){
|
||||
logger.debug("Formatting output string for encoding");
|
||||
|
||||
int outputCnt = 0;
|
||||
StringBuilder fullOutput = new StringBuilder();
|
||||
for(int inputCnt = 0;inputCnt < inputString.length();++inputCnt){
|
||||
logger.debug("Working character {}", inputString.charAt(inputCnt));
|
||||
|
||||
//Add both numbers of any letters to the output
|
||||
if(Character.isAlphabetic(inputString.charAt(inputCnt))){
|
||||
logger.debug("Adding encoded characters");
|
||||
|
||||
fullOutput.append(cleanString.charAt(outputCnt++));
|
||||
fullOutput.append(cleanString.charAt(outputCnt++));
|
||||
}
|
||||
//Add any other characters that appear to the output
|
||||
else{
|
||||
logger.debug("Adding symbols");
|
||||
|
||||
fullOutput.append(inputString.charAt(inputCnt));
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Formatted output '{}'", fullOutput);
|
||||
outputString = fullOutput.toString();
|
||||
}
|
||||
protected void addCharactersToCleanStringDecode(String cleanString){
|
||||
logger.debug("Formatting output string to decoding");
|
||||
|
||||
int outputCnt = 0;
|
||||
StringBuilder fullOutput = new StringBuilder();
|
||||
for(int inputCnt = 0;inputCnt < inputString.length();++inputCnt){
|
||||
logger.debug("Working character {}", inputString.charAt(inputCnt));
|
||||
|
||||
//Add the letter to the output and skip the second number
|
||||
if(Character.isDigit(inputString.charAt(inputCnt))){
|
||||
logger.debug("Adding decoded characters");
|
||||
|
||||
fullOutput.append(cleanString.charAt(outputCnt++));
|
||||
++inputCnt;
|
||||
}
|
||||
//Add any other characters that appear to the output
|
||||
else{
|
||||
logger.debug("Adding symbols");
|
||||
|
||||
fullOutput.append(inputString.charAt(inputCnt));
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Formatted output '{}'", fullOutput);
|
||||
outputString = fullOutput.toString();
|
||||
}
|
||||
//Encodes inputString using the Playfair cipher and stores the result in outputString
|
||||
private String encode() throws InvalidInputException{
|
||||
logger.debug("Encoding");
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
String cleanString = getPreparedInputStringEncoding();
|
||||
for(int cnt = 0;cnt < cleanString.length();++cnt){
|
||||
//Get the next character to be encoded
|
||||
char ch = cleanString.charAt(cnt);
|
||||
|
||||
logger.debug("Working character {}", ch);
|
||||
|
||||
//Find the letter in the grid
|
||||
CharLocation location = findChar(ch);
|
||||
logger.debug("Location {}, {}", location.getX() + 1, location.getY() + 1);
|
||||
|
||||
//Add the grid location to the output
|
||||
output.append(location.getX() + 1);
|
||||
@@ -231,6 +305,8 @@ public class PolybiusSquare{
|
||||
}
|
||||
//Decodes inputString using the Playfair cipher and stores the result in outputString
|
||||
private String decode(){
|
||||
logger.debug("Decoding");
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
String cleanString = getPreparedInputStringDecoding();
|
||||
for(int cnt = 0;cnt < cleanString.length();){
|
||||
@@ -238,9 +314,13 @@ public class PolybiusSquare{
|
||||
char firstDigit = cleanString.charAt(cnt++);
|
||||
char secondDigit = cleanString.charAt(cnt++);
|
||||
|
||||
logger.debug("Digits to decode {} {}", firstDigit, secondDigit);
|
||||
|
||||
//Get the next character
|
||||
char letter = grid[Integer.valueOf(Character.toString(firstDigit)) - 1][Integer.valueOf(Character.toString(secondDigit)) - 1];
|
||||
|
||||
logger.debug("Decoded letter {}", letter);
|
||||
|
||||
//Add the new letter to the output
|
||||
output.append(letter);
|
||||
}
|
||||
@@ -296,6 +376,8 @@ public class PolybiusSquare{
|
||||
|
||||
//Makes sure all variables are empty
|
||||
public void reset(){
|
||||
logger.debug("Resetting fields");
|
||||
|
||||
grid = new char[5][5];
|
||||
inputString = "";
|
||||
outputString = "";
|
||||
@@ -340,11 +422,15 @@ public class PolybiusSquare{
|
||||
return outputString;
|
||||
}
|
||||
public String getGrid(){
|
||||
StringBuilder gridString = new StringBuilder();
|
||||
logger.debug("Creating string from grid");
|
||||
|
||||
StringJoiner gridString = new StringJoiner("\n");
|
||||
for(char[] row : grid){
|
||||
StringJoiner rowString = new StringJoiner(" ", "[", "]");
|
||||
for(char col : row){
|
||||
gridString.append(col);
|
||||
rowString.add(Character.toString(col));
|
||||
}
|
||||
gridString.add(rowString.toString());
|
||||
}
|
||||
|
||||
return gridString.toString();
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/polySubstitution/RailFence.java
|
||||
//Mattrixwv
|
||||
// Created: 03-21-22
|
||||
//Modified: 03-22-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidBaseException;
|
||||
|
||||
|
||||
public class RailFence{
|
||||
//Variables
|
||||
private static final Logger logger = LoggerFactory.getLogger(RailFence.class);
|
||||
|
||||
//Fields
|
||||
private String inputString; //The message that needs to be encoded/decoded
|
||||
private String outputString; //The encoded/decoded message
|
||||
private StringBuilder[] fence; //The fence used for encoding/decoding
|
||||
@@ -27,18 +32,27 @@ public class RailFence{
|
||||
throw new InvalidInputException("Input cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Original input string '{}'", inputString);
|
||||
|
||||
//Apply removal options
|
||||
if(!preserveCapitals){
|
||||
logger.debug("Removing case");
|
||||
|
||||
inputString = inputString.toUpperCase();
|
||||
}
|
||||
if(!preserveWhitespace){
|
||||
logger.debug("Removing whitespace");
|
||||
|
||||
inputString = inputString.replaceAll("\\s", "");
|
||||
}
|
||||
if(!preserveSymbols){
|
||||
logger.debug("Removing symbols");
|
||||
|
||||
inputString = inputString.replaceAll("[^a-zA-Z\\s]", "");
|
||||
}
|
||||
|
||||
//Save the string
|
||||
logger.debug("Clean input string '{}'", inputString);
|
||||
this.inputString = inputString;
|
||||
|
||||
//Ensure the string isn't blank
|
||||
@@ -52,6 +66,8 @@ public class RailFence{
|
||||
throw new InvalidBaseException("You must use at least 2 rails");
|
||||
}
|
||||
|
||||
logger.debug("Creating {} rails", numRails);
|
||||
|
||||
fence = new StringBuilder[numRails];
|
||||
for(int cnt = 0;cnt < numRails;++cnt){
|
||||
fence[cnt] = new StringBuilder();
|
||||
@@ -59,28 +75,43 @@ public class RailFence{
|
||||
}
|
||||
//Strip the inputString of all non-letter characters
|
||||
private String getCleanInputString(){
|
||||
logger.debug("Getting input string for encoding");
|
||||
|
||||
return inputString.replaceAll("[^a-zA-Z]", "");
|
||||
}
|
||||
//Ensures capitals, lowercase, and symbols are displayed in the output string
|
||||
private void formatOutput(String outputString){
|
||||
logger.debug("Formatting output string");
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
int outputLoc = 0;
|
||||
for(char ch : inputString.toCharArray()){
|
||||
logger.debug("Working character {}", ch);
|
||||
|
||||
if(Character.isUpperCase(ch)){
|
||||
logger.debug("Formatting uppercase");
|
||||
|
||||
output.append(Character.toUpperCase(outputString.charAt(outputLoc++)));
|
||||
}
|
||||
else if(Character.isLowerCase(ch)){
|
||||
logger.debug("Formatting lowercase");
|
||||
|
||||
output.append(Character.toLowerCase(outputString.charAt(outputLoc++)));
|
||||
}
|
||||
else{
|
||||
logger.debug("Inserting symbol");
|
||||
|
||||
output.append(ch);
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Formatted output '{}'", output);
|
||||
this.outputString = output.toString();
|
||||
}
|
||||
//Returns the decoded string found in the fence after all characters are placed correctly
|
||||
private String getDecodedStringFromFence(){
|
||||
logger.debug("Getting decoded string from the fence");
|
||||
|
||||
boolean down = true;
|
||||
int rail = 0;
|
||||
int outsideCol = 0;
|
||||
@@ -126,41 +157,56 @@ public class RailFence{
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Fence output '{}'", output);
|
||||
return output.toString();
|
||||
}
|
||||
//Encodes inputString using the RailFence cipher and stores the result in outputString
|
||||
private void encode(){
|
||||
logger.debug("Encoding");
|
||||
|
||||
boolean up = true;
|
||||
int rail = 0;
|
||||
for(char ch : getCleanInputString().toCharArray()){
|
||||
logger.debug("Working character {}", ch);
|
||||
|
||||
fence[rail].append(ch);
|
||||
//Advance to the next rail
|
||||
if(up){
|
||||
logger.debug("Moving up");
|
||||
++rail;
|
||||
}
|
||||
else{
|
||||
logger.debug("Moving down");
|
||||
--rail;
|
||||
}
|
||||
|
||||
//Make sure you're still in bounds
|
||||
if(rail == fence.length){
|
||||
logger.debug("Swapping to down");
|
||||
up = false;
|
||||
rail -= 2;
|
||||
}
|
||||
else if(rail == -1){
|
||||
logger.debug("Swapping to up");
|
||||
up = true;
|
||||
rail += 2;
|
||||
}
|
||||
}
|
||||
|
||||
//Append the fence rows to come up with a single string
|
||||
logger.debug("Appending rows from the fence");
|
||||
StringBuilder output = new StringBuilder();
|
||||
for(StringBuilder segment : fence){
|
||||
output.append(segment);
|
||||
}
|
||||
|
||||
//Format the output
|
||||
formatOutput(output.toString());
|
||||
}
|
||||
//Decodes inputString using the RailFence cipher and stores the result in outputString
|
||||
private void decode(){
|
||||
logger.debug("Decoding");
|
||||
|
||||
//Determine the number of characters on each rail
|
||||
String cleanInputString = getCleanInputString();
|
||||
int cycleLength = 2 * (fence.length - 1);
|
||||
@@ -182,7 +228,12 @@ public class RailFence{
|
||||
middleNum = (cycleLength - (k.remainder(BigDecimal.ONE).multiply(new BigDecimal(cycleLength))).intValue());
|
||||
}
|
||||
|
||||
logger.debug("Number of characters in the top rail {}", numInTopRail);
|
||||
logger.debug("Number of characters in the middle rails {}", numInMiddleRails);
|
||||
logger.debug("Number of characters in the bottom rail {}", numInBottomRail);
|
||||
|
||||
//Add the correct number of characters to each rail
|
||||
logger.debug("Adding characters to the rails");
|
||||
fence[0].append(cleanInputString.substring(0, numInTopRail));
|
||||
int start = numInTopRail;
|
||||
int end = numInTopRail + numInMiddleRails;
|
||||
@@ -195,10 +246,12 @@ public class RailFence{
|
||||
end += numInMiddleRails;
|
||||
}
|
||||
end = start + numInBottomRail;
|
||||
logger.debug("Appending the bottom rail");
|
||||
fence[fence.length - 1].append(cleanInputString.substring(start, end));
|
||||
|
||||
//Get the decoded string from the constructed fence
|
||||
String output = getDecodedStringFromFence();
|
||||
logger.debug("Fence output '{}'", output);
|
||||
formatOutput(output);
|
||||
}
|
||||
|
||||
@@ -237,6 +290,8 @@ public class RailFence{
|
||||
|
||||
//Makes sure all variables are empty
|
||||
public void reset(){
|
||||
logger.debug("Resetting fields");
|
||||
|
||||
inputString = "";
|
||||
outputString = "";
|
||||
fence = null;
|
||||
|
||||
@@ -8,6 +8,9 @@ package com.mattrixwv.cipherstream.polysubstitution;
|
||||
import java.util.ArrayList;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
@@ -15,6 +18,8 @@ import com.mattrixwv.cipherstream.exceptions.InvalidBaseException;
|
||||
|
||||
|
||||
public class Trifid{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Trifid.class);
|
||||
|
||||
//A class representing the location of a character in the grid
|
||||
private class CharLocation{
|
||||
private int x;
|
||||
@@ -39,7 +44,7 @@ public class Trifid{
|
||||
}
|
||||
}
|
||||
|
||||
//Variables
|
||||
//Fields
|
||||
private String inputString; //The message that needs to be encoded/decoded
|
||||
private String outputString; //The encoded/decoded message
|
||||
private String keyword; //The keyword used to create the grid
|
||||
@@ -61,6 +66,8 @@ public class Trifid{
|
||||
throw new InvalidCharacterException("Fill in must not be a letter");
|
||||
}
|
||||
|
||||
logger.debug("Setting fill in {}", fillIn);
|
||||
|
||||
//Save the fillIn character
|
||||
this.fillIn = fillIn;
|
||||
}
|
||||
@@ -71,25 +78,35 @@ public class Trifid{
|
||||
throw new InvalidKeywordException("Keyword cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Original keyword {}", keyword);
|
||||
|
||||
//Change everything to uppercase
|
||||
logger.debug("Removing case");
|
||||
keyword = keyword.toUpperCase();
|
||||
|
||||
//Remove everything except capital letters
|
||||
logger.debug("Removing all invalid characters");
|
||||
keyword = keyword.replaceAll("[^A-Z" + fillIn + "]", "");
|
||||
|
||||
//Add all letters in the alphabet and fillIn to the key
|
||||
logger.debug("Appending entire alphabet to keyword");
|
||||
keyword += "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + fillIn;
|
||||
|
||||
//Remove all duplicate characters
|
||||
logger.debug("Removing duplicated characters");
|
||||
StringBuilder uniqueKey = new StringBuilder();
|
||||
keyword.chars().distinct().forEach(c -> uniqueKey.append((char)c));
|
||||
this.keyword = uniqueKey.toString();
|
||||
|
||||
logger.debug("Cleaned keyword {}", this.keyword);
|
||||
|
||||
//Create the grid from the sanitized keyword
|
||||
createGrid();
|
||||
}
|
||||
//Creates the grid from the keyword
|
||||
private void createGrid(){
|
||||
logger.debug("Creating grid from keyword");
|
||||
|
||||
for(int layerCnt = 0;layerCnt < grid.length;++layerCnt){
|
||||
for(int rowCnt = 0;rowCnt < grid[layerCnt].length;++rowCnt){
|
||||
for(int colCnt = 0;colCnt < grid[layerCnt][rowCnt].length;++colCnt){
|
||||
@@ -99,6 +116,8 @@ public class Trifid{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Completed grid\n{}", getGrid());
|
||||
}
|
||||
//Ensures groupSize constraints
|
||||
private void setGroupSize(int groupSize) throws InvalidBaseException{
|
||||
@@ -106,6 +125,8 @@ public class Trifid{
|
||||
throw new InvalidBaseException("Group size must be > 0");
|
||||
}
|
||||
|
||||
logger.debug("Setting group size");
|
||||
|
||||
this.groupSize = groupSize;
|
||||
}
|
||||
//Ensures inputString constraints
|
||||
@@ -115,21 +136,27 @@ public class Trifid{
|
||||
throw new InvalidInputException("Input cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Original input string '{}'", inputString);
|
||||
|
||||
//Apply removal options
|
||||
if(!preserveCapitals){
|
||||
logger.debug("Removing case");
|
||||
inputString = inputString.toUpperCase();
|
||||
}
|
||||
if(!preserveWhitespace){
|
||||
if(Character.isWhitespace(fillIn)){
|
||||
throw new InvalidInputException("If fillIn is whitespace, whitespace must be preserved");
|
||||
}
|
||||
logger.debug("Removing whitespace");
|
||||
inputString = inputString.replaceAll("\\s", "");
|
||||
}
|
||||
if(!preserveSymbols){
|
||||
logger.debug("Removing symbols");
|
||||
inputString = inputString.replaceAll("[^a-zA-Z" + fillIn + "\\s]", "");
|
||||
}
|
||||
|
||||
//Save the string
|
||||
logger.debug("Cleaned input string '{}'", inputString);
|
||||
this.inputString = inputString;
|
||||
|
||||
//Ensure the string isn't blank
|
||||
@@ -139,14 +166,19 @@ public class Trifid{
|
||||
}
|
||||
//Returns the inputString with only letters
|
||||
private String getCleanInputString(){
|
||||
logger.debug("Cleaning input string for encoding");
|
||||
return inputString.toUpperCase().replaceAll("[^A-Z" + fillIn + "]", "");
|
||||
}
|
||||
//Returns the location of the given character in the grid
|
||||
private CharLocation findChar(char letter) throws InvalidCharacterException{
|
||||
logger.debug("Finding character {} in grid", letter);
|
||||
|
||||
for(int layer = 0;layer < grid.length;++layer){
|
||||
for(int row = 0;row < grid[layer].length;++row){
|
||||
for(int col = 0;col < grid[layer][row].length;++col){
|
||||
if(grid[layer][row][col] == letter){
|
||||
logger.debug("Found at {} {} {}", layer, row, col);
|
||||
|
||||
return new CharLocation(row, col, layer);
|
||||
}
|
||||
}
|
||||
@@ -168,32 +200,44 @@ public class Trifid{
|
||||
throw new InvalidCharacterException("z cannot be larget than 2");
|
||||
}
|
||||
|
||||
logger.debug("Getting character at {} {} {}", location.getZ(), location.getX(), location.getY());
|
||||
|
||||
return grid[location.getZ()][location.getX()][location.getY()];
|
||||
}
|
||||
//Adds all non-letter characters back to the output string
|
||||
private void formatOutput(String outputString){
|
||||
logger.debug("Formatting output");
|
||||
|
||||
//Keep track of where you are in the output
|
||||
int outputCnt = 0;
|
||||
StringBuilder output = new StringBuilder();
|
||||
//Check every character in the input and apply the correct rules to the output
|
||||
for(char ch : inputString.toCharArray()){
|
||||
logger.debug("Working character {}", ch);
|
||||
if(Character.isUpperCase(ch)){
|
||||
logger.debug("Formatting uppercase");
|
||||
output.append(Character.toUpperCase(outputString.charAt(outputCnt++)));
|
||||
}
|
||||
else if(Character.isLowerCase(ch)){
|
||||
logger.debug("Formatting lowercase");
|
||||
output.append(Character.toLowerCase(outputString.charAt(outputCnt++)));
|
||||
}
|
||||
else{
|
||||
logger.debug("Appending symbol");
|
||||
output.append(ch);
|
||||
}
|
||||
}
|
||||
|
||||
//Save the output
|
||||
logger.debug("Formatted output '{}'", output);
|
||||
this.outputString = output.toString();
|
||||
}
|
||||
//Encodes inputString using a polybius square and stores the result in outputString
|
||||
private void encode() throws InvalidCharacterException{
|
||||
logger.debug("Encoding");
|
||||
|
||||
//Step through every element in the sanitized inputString encoding the letters
|
||||
logger.debug("Conveting letters to coordinates");
|
||||
ArrayList<CharLocation> locations = new ArrayList<>();
|
||||
for(char ch : getCleanInputString().toCharArray()){
|
||||
//Get the location of the char in the grid
|
||||
@@ -202,6 +246,7 @@ public class Trifid{
|
||||
}
|
||||
|
||||
//Split the locations up by group
|
||||
logger.debug("Splitting locations into groups");
|
||||
int numGroups = inputString.length() / groupSize;
|
||||
if(numGroups == 0){
|
||||
numGroups = 1;
|
||||
@@ -220,6 +265,7 @@ public class Trifid{
|
||||
}
|
||||
|
||||
//Split the coordinates into rows
|
||||
logger.debug("Splitting groups into rows");
|
||||
ArrayList<Integer> coordinates = new ArrayList<>(locations.size() * 3);
|
||||
for(ArrayList<CharLocation> group : groups){
|
||||
//Split the coordinates up into 3 rows
|
||||
@@ -236,6 +282,7 @@ public class Trifid{
|
||||
coordinates.addAll(cols);
|
||||
}
|
||||
//Create new locations from the rows of coordinates
|
||||
logger.debug("Converting split locations into new locations");
|
||||
ArrayList<CharLocation> newLocations = new ArrayList<>(locations.size());
|
||||
for(int cnt = 0;cnt < coordinates.size();){
|
||||
int z = coordinates.get(cnt++);
|
||||
@@ -245,6 +292,7 @@ public class Trifid{
|
||||
}
|
||||
|
||||
//Get the new letters from the grid
|
||||
logger.debug("Converting new locations into characters");
|
||||
StringBuilder output = new StringBuilder();
|
||||
for(CharLocation loc : newLocations){
|
||||
output.append(getChar(loc));
|
||||
@@ -255,7 +303,10 @@ public class Trifid{
|
||||
}
|
||||
//Decodes inputString using a polybius square and stores the result in outputString
|
||||
private void decode() throws InvalidCharacterException{
|
||||
logger.debug("Decoding");
|
||||
|
||||
//Step through every element in the sanitized inputString encoding the letters
|
||||
logger.debug("Converting letters to coordinates");
|
||||
ArrayList<CharLocation> locations = new ArrayList<>();
|
||||
for(char ch : getCleanInputString().toCharArray()){
|
||||
//Get the location of the char in the grid
|
||||
@@ -264,6 +315,7 @@ public class Trifid{
|
||||
}
|
||||
|
||||
//Split the locations up by group
|
||||
logger.debug("Splitting locations into groups");
|
||||
int numGroups = inputString.length() / groupSize;
|
||||
if(numGroups == 0){
|
||||
numGroups = 1;
|
||||
@@ -282,6 +334,7 @@ public class Trifid{
|
||||
}
|
||||
|
||||
//Split the coordinates into rows by group and create the original grid locations
|
||||
logger.debug("Putting locations into rows");
|
||||
ArrayList<CharLocation> originalLocations = new ArrayList<>(locations.size());
|
||||
for(ArrayList<CharLocation> group : groups){
|
||||
//Read all of the coordinates from the group out into a row
|
||||
@@ -293,6 +346,7 @@ public class Trifid{
|
||||
}
|
||||
|
||||
//Read out the coordinates into new locations
|
||||
logger.debug("Converting locations into new locations");
|
||||
ArrayList<CharLocation> originalGroup = new ArrayList<>(group.size());
|
||||
for(int cnt = 0;cnt < group.size();++cnt){
|
||||
originalGroup.add(new CharLocation(0, 0, 0));
|
||||
@@ -311,6 +365,7 @@ public class Trifid{
|
||||
}
|
||||
|
||||
//Get the original letters from the grid
|
||||
logger.debug("Converting new locations into letters");
|
||||
StringBuilder output = new StringBuilder();
|
||||
for(CharLocation loc : originalLocations){
|
||||
output.append(getChar(loc));
|
||||
@@ -374,6 +429,8 @@ public class Trifid{
|
||||
|
||||
//Makes sure all variables are empty
|
||||
public void reset(){
|
||||
logger.debug("Resetting fields");
|
||||
|
||||
inputString = "";
|
||||
outputString = "";
|
||||
keyword = "";
|
||||
@@ -397,6 +454,8 @@ public class Trifid{
|
||||
return fillIn;
|
||||
}
|
||||
public String getGrid(){
|
||||
logger.debug("Creating string from grid");
|
||||
|
||||
StringJoiner layers = new StringJoiner("\n\n");
|
||||
|
||||
for(char[][] layer : grid){
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/combination/TestADFGVX.java
|
||||
//Mattrixwv
|
||||
// Created: 01-26-22
|
||||
//Modified: 01-26-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.combination;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
@@ -25,14 +25,14 @@ public class TestADFGVX{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "axgvdavfxgagfaafagaaxdxfgdagda";
|
||||
String output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
squareKeyword = "SquareKeyword";
|
||||
keyword = "keyword";
|
||||
correctOutput = "AXGVDAVFXGAGFAAFAGAAXDXFGDAGDA";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
@@ -40,7 +40,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "axgvdavfxgagfa afag aaxdxfgdagda";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
@@ -48,7 +48,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "axgvdavfxgagfa*afag+aaxdxfgdagda";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "Message to-encode";
|
||||
@@ -56,7 +56,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "AXgvdavfxgagfa afag-aaxdxfgdagda";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -68,14 +68,14 @@ public class TestADFGVX{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
String output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no capital lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
squareKeyword = "SquareKeyword";
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no capital uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
@@ -83,7 +83,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAGAGADFAGAXXD AXDX ADAFAFXDDGDF";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no capital whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode-";
|
||||
@@ -91,7 +91,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAGAGADFAGAXXD*AXDX+ADAFAFXDDGDF-";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no capital symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
@@ -99,7 +99,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAGAGADFAGAXXD AXDX^ADAFAFXDDGDF";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no capital mixed case, whitesapce, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -111,14 +111,14 @@ public class TestADFGVX{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
|
||||
String output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no whitespace lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
squareKeyword = "SquareKeyword";
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no whitespace uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
@@ -126,7 +126,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no whitespace whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode-";
|
||||
@@ -134,7 +134,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "aagagadfagaxxd*axdx+adafafxddgdf-";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no whitespace symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
@@ -142,7 +142,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAgagadfagaxxdaxdx^adafafxddgdf";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no whitespace mixed case, whitesapce, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -154,14 +154,14 @@ public class TestADFGVX{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
|
||||
String output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no symbol lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
squareKeyword = "SquareKeyword";
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no symbol uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
@@ -169,7 +169,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "aagagadfagaxxd axdx adafafxddgdf";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no symbol whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode-";
|
||||
@@ -177,7 +177,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no symbol symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
@@ -185,7 +185,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAgagadfagaxxd axdxadafafxddgdf";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no symbol mixed case, whitesapce, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -197,14 +197,14 @@ public class TestADFGVX{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
String output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed secure lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
squareKeyword = "SquareKeyword";
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed secure uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
@@ -212,7 +212,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed secure whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode-";
|
||||
@@ -220,7 +220,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed secure symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
@@ -228,7 +228,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed secure mixed case, whitesapce, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@@ -242,14 +242,14 @@ public class TestADFGVX{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "AXGVDAVFXGAGFAAFAGAAXDXFGDAGDA";
|
||||
squareKeyword = "SquareKeyword";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "axgvdavfxgagfa afag aaxdxfgdagda";
|
||||
@@ -257,7 +257,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "axgvdavfxgagfa*afag+aaxdxfgdagda-";
|
||||
@@ -265,7 +265,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "message*to+encode-";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "AXgvdavfxgagfa afag^aaxdxfgdagda";
|
||||
@@ -273,7 +273,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "Message to^encode";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -285,14 +285,14 @@ public class TestADFGVX{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed no capital lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "AXGVDAVFXGAGFAAFAGAAXDXFGDAGDA";
|
||||
squareKeyword = "SquareKeyword";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed no capital uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "axgvdavfxgagfa afag aaxdxfgdagda";
|
||||
@@ -300,7 +300,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE TO ENCODE";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed no capital whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "axgvdavfxgagfa*afag+aaxdxfgdagda-";
|
||||
@@ -308,7 +308,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE*TO+ENCODE-";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed no capital symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "AXgvdavfxgagfa afag^aaxdxfgdagda";
|
||||
@@ -316,7 +316,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE TO^ENCODE";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed no capital mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -328,14 +328,14 @@ public class TestADFGVX{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed no whitespace lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "AXGVDAVFXGAGFAAFAGAAXDXFGDAGDA";
|
||||
squareKeyword = "SquareKeyword";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed no whitespace uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "axgvdavfxgagfa afag aaxdxfgdagda";
|
||||
@@ -343,7 +343,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "axgvdavfxgagfa*afag+aaxdxfgdagda-";
|
||||
@@ -351,7 +351,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "message*to+encode-";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed no whitespace symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "AXgvdavfxgagfa afag^aaxdxfgdagda";
|
||||
@@ -359,7 +359,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "Messageto^encode";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed no whitespace mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -371,14 +371,14 @@ public class TestADFGVX{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed no symbol lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "AXGVDAVFXGAGFAAFAGAAXDXFGDAGDA";
|
||||
squareKeyword = "SquareKeyword";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed no symbol uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "axgvdavfxgagfa afag aaxdxfgdagda";
|
||||
@@ -386,7 +386,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed no symbol whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "axgvdavfxgagfa*afag+aaxdxfgdagda-";
|
||||
@@ -394,7 +394,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed no symbol symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "AXgvdavfxgagfa afag^aaxdxfgdagda";
|
||||
@@ -402,7 +402,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "Message toencode";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed no symbol mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -414,14 +414,14 @@ public class TestADFGVX{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed secure lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "AXGVDAVFXGAGFAAFAGAAXDXFGDAGDA";
|
||||
squareKeyword = "SquareKeyword";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed secure uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "axgvdavfxgagfa afag aaxdxfgdagda";
|
||||
@@ -429,7 +429,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed secure whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "axgvdavfxgagfa*afag+aaxdxfgdagda-";
|
||||
@@ -437,7 +437,7 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed secure symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "AXgvdavfxgagfa afag^aaxdxfgdagda";
|
||||
@@ -445,6 +445,6 @@ public class TestADFGVX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGVX failed secure mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamjava/combination/TestADFGX.java
|
||||
//Mattrixwv
|
||||
// Created: 01-25-22
|
||||
//Modified: 01-25-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.combination;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
@@ -25,14 +25,14 @@ public class TestADFGX{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
|
||||
String output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
squareKeyword = "SquareKeyword";
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
@@ -40,7 +40,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "aagagadfagaxxd axdx adafafxddgdf";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode-";
|
||||
@@ -48,7 +48,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "aagagadfagaxxd*axdx+adafafxddgdf-";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
@@ -56,7 +56,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAgagadfagaxxd axdx^adafafxddgdf";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed mixed case, whitesapce, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -68,14 +68,14 @@ public class TestADFGX{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
String output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no capital lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
squareKeyword = "SquareKeyword";
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no capital uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
@@ -83,7 +83,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAGAGADFAGAXXD AXDX ADAFAFXDDGDF";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no capital whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode-";
|
||||
@@ -91,7 +91,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAGAGADFAGAXXD*AXDX+ADAFAFXDDGDF-";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no capital symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
@@ -99,7 +99,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAGAGADFAGAXXD AXDX^ADAFAFXDDGDF";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no capital mixed case, whitesapce, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -111,14 +111,14 @@ public class TestADFGX{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
|
||||
String output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no whitespace lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
squareKeyword = "SquareKeyword";
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no whitespace uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
@@ -126,7 +126,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no whitespace whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode-";
|
||||
@@ -134,7 +134,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "aagagadfagaxxd*axdx+adafafxddgdf-";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no whitespace symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
@@ -142,7 +142,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAgagadfagaxxdaxdx^adafafxddgdf";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no whitespace mixed case, whitesapce, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -154,14 +154,14 @@ public class TestADFGX{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
|
||||
String output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no symbol lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
squareKeyword = "SquareKeyword";
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no symbol uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
@@ -169,7 +169,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "aagagadfagaxxd axdx adafafxddgdf";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no symbol whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode-";
|
||||
@@ -177,7 +177,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "aagagadfagaxxdaxdxadafafxddgdf";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no symbol symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
@@ -185,7 +185,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAgagadfagaxxd axdxadafafxddgdf";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no symbol mixed case, whitesapce, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -197,14 +197,14 @@ public class TestADFGX{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
String output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
squareKeyword = "SquareKeyword";
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
@@ -212,7 +212,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode-";
|
||||
@@ -220,7 +220,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
@@ -228,7 +228,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
output = cipher.encode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed mixed case, whitesapce, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@@ -242,14 +242,14 @@ public class TestADFGX{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
squareKeyword = "SquareKeyword";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "aagagadfagaxxd axdx adafafxddgdf";
|
||||
@@ -257,7 +257,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "aagagadfagaxxd*axdx+adafafxddgdf-";
|
||||
@@ -265,7 +265,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "message*to+encode-";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "AAgagadfagaxxd axdx^adafafxddgdf";
|
||||
@@ -273,7 +273,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "Message to^encode";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed mixed case, whitesapce, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -285,14 +285,14 @@ public class TestADFGX{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no capital lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
squareKeyword = "SquareKeyword";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no capital uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "aagagadfagaxxd axdx adafafxddgdf";
|
||||
@@ -300,7 +300,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE TO ENCODE";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no capital whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "aagagadfagaxxd*axdx+adafafxddgdf-";
|
||||
@@ -308,7 +308,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE*TO+ENCODE-";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no capital symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "AAgagadfagaxxd axdx^adafafxddgdf";
|
||||
@@ -316,7 +316,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE TO^ENCODE";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no capital mixed case, whitesapce, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -328,14 +328,14 @@ public class TestADFGX{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no whitespace lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
squareKeyword = "SquareKeyword";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no whitespace uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "aagagadfagaxxd axdx adafafxddgdf";
|
||||
@@ -343,7 +343,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "aagagadfagaxxd*axdx+adafafxddgdf-";
|
||||
@@ -351,7 +351,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "message*to+encode-";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no whitespace symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "AAgagadfagaxxd axdx^adafafxddgdf";
|
||||
@@ -359,7 +359,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "Messageto^encode";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no whitespace mixed case, whitesapce, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -371,14 +371,14 @@ public class TestADFGX{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no symbol lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
squareKeyword = "SquareKeyword";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no symbol uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "aagagadfagaxxd axdx adafafxddgdf";
|
||||
@@ -386,7 +386,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no symbol whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "aagagadfagaxxd*axdx+adafafxddgdf-";
|
||||
@@ -394,7 +394,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no symbol symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "AAgagadfagaxxd axdx^adafafxddgdf";
|
||||
@@ -402,7 +402,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "Message toencode";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed no symbol mixed case, whitesapce, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -414,14 +414,14 @@ public class TestADFGX{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed secure lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "AAGAGADFAGAXXDAXDXADAFAFXDDGDF";
|
||||
squareKeyword = "SquareKeyword";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed secure uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "aagagadfagaxxd axdx adafafxddgdf";
|
||||
@@ -429,7 +429,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed secure whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "aagagadfagaxxd*axdx+adafafxddgdf-";
|
||||
@@ -437,7 +437,7 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed secure symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "AAgagadfagaxxd axdx^adafafxddgdf";
|
||||
@@ -445,6 +445,6 @@ public class TestADFGX{
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(squareKeyword, keyword, inputString);
|
||||
assertEquals("ADFGX failed secure mixed case, whitesapce, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/polySubstitution/TestAffine.java
|
||||
//Mattrixwv
|
||||
// Created: 01-26-22
|
||||
//Modified: 01-26-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
@@ -24,14 +24,14 @@ public class TestAffine{
|
||||
int key2 = 7;
|
||||
String correctOutput = "pbtthlbyzburzwb";
|
||||
String output = cipher.encode(key1, key2, inputString);
|
||||
assertEquals("Affine failed lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
key1 = 5;
|
||||
key2 = 7;
|
||||
correctOutput = "PBTTHLBYZBURZWB";
|
||||
output = cipher.encode(key1, key2, inputString);
|
||||
assertEquals("Affine failed uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
@@ -39,7 +39,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "pbtthlb yz burzwb";
|
||||
output = cipher.encode(key1, key2, inputString);
|
||||
assertEquals("Affine failed whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode-";
|
||||
@@ -47,7 +47,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "pbtthlb*yz+burzwb-";
|
||||
output = cipher.encode(key1, key2, inputString);
|
||||
assertEquals("Affine failed symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
@@ -55,7 +55,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "Pbtthlb yz^burzwb";
|
||||
output = cipher.encode(key1, key2, inputString);
|
||||
assertEquals("Affine failed mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalEncode() throws InvalidKeywordException, InvalidInputException{
|
||||
@@ -67,14 +67,14 @@ public class TestAffine{
|
||||
int key2 = 7;
|
||||
String correctOutput = "pbtthlbyzburzwb";
|
||||
String output = cipher.encode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no capital lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
key1 = 5;
|
||||
key2 = 7;
|
||||
correctOutput = "pbtthlbyzburzwb";
|
||||
output = cipher.encode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no capital uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
@@ -82,7 +82,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "pbtthlb yz burzwb";
|
||||
output = cipher.encode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no capital whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode-";
|
||||
@@ -90,7 +90,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "pbtthlb*yz+burzwb-";
|
||||
output = cipher.encode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no capital symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
@@ -98,7 +98,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "pbtthlb yz^burzwb";
|
||||
output = cipher.encode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no capital mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceEncode() throws InvalidKeywordException, InvalidInputException{
|
||||
@@ -110,14 +110,14 @@ public class TestAffine{
|
||||
int key2 = 7;
|
||||
String correctOutput = "pbtthlbyzburzwb";
|
||||
String output = cipher.encode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no whitespace lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
key1 = 5;
|
||||
key2 = 7;
|
||||
correctOutput = "PBTTHLBYZBURZWB";
|
||||
output = cipher.encode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no whitespace uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
@@ -125,7 +125,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "pbtthlbyzburzwb";
|
||||
output = cipher.encode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no whitespace whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode-";
|
||||
@@ -133,7 +133,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "pbtthlb*yz+burzwb-";
|
||||
output = cipher.encode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no whitespace symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
@@ -141,7 +141,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "Pbtthlbyz^burzwb";
|
||||
output = cipher.encode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no whitespace mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolEncode() throws InvalidKeywordException, InvalidInputException{
|
||||
@@ -153,14 +153,14 @@ public class TestAffine{
|
||||
int key2 = 7;
|
||||
String correctOutput = "pbtthlbyzburzwb";
|
||||
String output = cipher.encode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no symbol lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
key1 = 5;
|
||||
key2 = 7;
|
||||
correctOutput = "PBTTHLBYZBURZWB";
|
||||
output = cipher.encode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no symbol uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
@@ -168,7 +168,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "pbtthlb yz burzwb";
|
||||
output = cipher.encode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no symbol whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode-";
|
||||
@@ -176,7 +176,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "pbtthlbyzburzwb";
|
||||
output = cipher.encode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no symbol symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
@@ -184,7 +184,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "Pbtthlb yzburzwb";
|
||||
output = cipher.encode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no symbol mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidKeywordException, InvalidInputException{
|
||||
@@ -196,14 +196,14 @@ public class TestAffine{
|
||||
int key2 = 7;
|
||||
String correctOutput = "pbtthlbyzburzwb";
|
||||
String output = cipher.encode(key1, key2, inputString);
|
||||
assertEquals("Affine failed secure lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
key1 = 5;
|
||||
key2 = 7;
|
||||
correctOutput = "pbtthlbyzburzwb";
|
||||
output = cipher.encode(key1, key2, inputString);
|
||||
assertEquals("Affine failed secure uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
@@ -211,7 +211,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "pbtthlbyzburzwb";
|
||||
output = cipher.encode(key1, key2, inputString);
|
||||
assertEquals("Affine failed secure whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode-";
|
||||
@@ -219,7 +219,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "pbtthlbyzburzwb";
|
||||
output = cipher.encode(key1, key2, inputString);
|
||||
assertEquals("Affine failed secure symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
@@ -227,7 +227,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "pbtthlbyzburzwb";
|
||||
output = cipher.encode(key1, key2, inputString);
|
||||
assertEquals("Affine failed secure mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@@ -241,14 +241,14 @@ public class TestAffine{
|
||||
int key2 = 7;
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(key1, key2, inputString);
|
||||
assertEquals("Affine failed lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppsercase decoding
|
||||
inputString = "PBTTHLBYZBURZWB";
|
||||
key1 = 5;
|
||||
key2 = 7;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(key1, key2, inputString);
|
||||
assertEquals("Affine failed uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "pbtthlb yz burzwb";
|
||||
@@ -256,7 +256,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(key1, key2, inputString);
|
||||
assertEquals("Affine failed whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "pbtthlb*yz+burzwb-";
|
||||
@@ -264,7 +264,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "message*to+encode-";
|
||||
output = cipher.decode(key1, key2, inputString);
|
||||
assertEquals("Affine failed symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Pbtthlb yz^burzwb";
|
||||
@@ -272,7 +272,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "Message to^encode";
|
||||
output = cipher.decode(key1, key2, inputString);
|
||||
assertEquals("Affine failed mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalDecode() throws InvalidKeywordException, InvalidInputException{
|
||||
@@ -284,14 +284,14 @@ public class TestAffine{
|
||||
int key2 = 7;
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no capital lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppsercase decoding
|
||||
inputString = "PBTTHLBYZBURZWB";
|
||||
key1 = 5;
|
||||
key2 = 7;
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no capital uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "pbtthlb yz burzwb";
|
||||
@@ -299,7 +299,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no capital whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "pbtthlb*yz+burzwb-";
|
||||
@@ -307,7 +307,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "message*to+encode-";
|
||||
output = cipher.decode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no capital symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Pbtthlb yz^burzwb";
|
||||
@@ -315,7 +315,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "message to^encode";
|
||||
output = cipher.decode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no capital mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceDecode() throws InvalidKeywordException, InvalidInputException{
|
||||
@@ -327,14 +327,14 @@ public class TestAffine{
|
||||
int key2 = 7;
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no whitespace lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppsercase decoding
|
||||
inputString = "PBTTHLBYZBURZWB";
|
||||
key1 = 5;
|
||||
key2 = 7;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no whitespace uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "pbtthlb yz burzwb";
|
||||
@@ -342,7 +342,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "pbtthlb*yz+burzwb-";
|
||||
@@ -350,7 +350,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "message*to+encode-";
|
||||
output = cipher.decode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no whitespace symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Pbtthlb yz^burzwb";
|
||||
@@ -358,7 +358,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "Messageto^encode";
|
||||
output = cipher.decode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no whitespace mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolDecode() throws InvalidKeywordException, InvalidInputException{
|
||||
@@ -370,14 +370,14 @@ public class TestAffine{
|
||||
int key2 = 7;
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no symbol lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppsercase decoding
|
||||
inputString = "PBTTHLBYZBURZWB";
|
||||
key1 = 5;
|
||||
key2 = 7;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no symbol uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "pbtthlb yz burzwb";
|
||||
@@ -385,7 +385,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no symbol whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "pbtthlb*yz+burzwb-";
|
||||
@@ -393,7 +393,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no symbol symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Pbtthlb yz^burzwb";
|
||||
@@ -401,7 +401,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "Message toencode";
|
||||
output = cipher.decode(key1, key2, inputString);
|
||||
assertEquals("Affine failed no symbol mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidKeywordException, InvalidInputException{
|
||||
@@ -413,14 +413,14 @@ public class TestAffine{
|
||||
int key2 = 7;
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(key1, key2, inputString);
|
||||
assertEquals("Affine failed secure lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppsercase decoding
|
||||
inputString = "PBTTHLBYZBURZWB";
|
||||
key1 = 5;
|
||||
key2 = 7;
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(key1, key2, inputString);
|
||||
assertEquals("Affine failed secure uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "pbtthlb yz burzwb";
|
||||
@@ -428,7 +428,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(key1, key2, inputString);
|
||||
assertEquals("Affine failed secure whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "pbtthlb*yz+burzwb-";
|
||||
@@ -436,7 +436,7 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(key1, key2, inputString);
|
||||
assertEquals("Affine failed secure symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Pbtthlb yz^burzwb";
|
||||
@@ -444,6 +444,6 @@ public class TestAffine{
|
||||
key2 = 7;
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(key1, key2, inputString);
|
||||
assertEquals("Affine failed secure mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/monoSubstitution/TestAtbash.java
|
||||
//Mattrixwv
|
||||
// Created: 07-25-21
|
||||
//Modified: 02-22-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
|
||||
@@ -21,30 +21,30 @@ public class TestAtbash{
|
||||
String inputString = "messagetoencode";
|
||||
String correctOutput = "nvhhztvglvmxlwv";
|
||||
String output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
correctOutput = "NVHHZTVGLVMXLWV";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
correctOutput = "nvhhztv gl vmxlwv";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
correctOutput = "nvhhztv*gl+vmxlwv";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
correctOutput = "Nvhhztv gl^vmxlwv";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -55,30 +55,30 @@ public class TestAtbash{
|
||||
String inputString = "messagetoencode";
|
||||
String correctOutput = "NVHHZTVGLVMXLWV";
|
||||
String output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no capital lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
correctOutput = "NVHHZTVGLVMXLWV";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no capital uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
correctOutput = "NVHHZTV GL VMXLWV";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no capital whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
correctOutput = "NVHHZTV*GL+VMXLWV";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no capital symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
correctOutput = "NVHHZTV GL^VMXLWV";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no capital mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,30 +89,30 @@ public class TestAtbash{
|
||||
String inputString = "messagetoencode";
|
||||
String correctOutput = "nvhhztvglvmxlwv";
|
||||
String output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no whitespace lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
correctOutput = "NVHHZTVGLVMXLWV";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no whitespace uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
correctOutput = "nvhhztvglvmxlwv";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no whitespace whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
correctOutput = "nvhhztv*gl+vmxlwv";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no whitespace symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
correctOutput = "Nvhhztvgl^vmxlwv";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no whitespace mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -123,30 +123,30 @@ public class TestAtbash{
|
||||
String inputString = "messagetoencode";
|
||||
String correctOutput = "nvhhztvglvmxlwv";
|
||||
String output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no symbol lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
correctOutput = "NVHHZTVGLVMXLWV";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no symbol uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
correctOutput = "nvhhztv gl vmxlwv";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no symbol whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
correctOutput = "nvhhztvglvmxlwv";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no symbol symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
correctOutput = "Nvhhztv glvmxlwv";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no symbol mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -157,30 +157,30 @@ public class TestAtbash{
|
||||
String inputString = "messagetoencode";
|
||||
String correctOutput = "NVHHZTVGLVMXLWV";
|
||||
String output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed secure lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
correctOutput = "NVHHZTVGLVMXLWV";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed secure uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
correctOutput = "NVHHZTVGLVMXLWV";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed secure whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
correctOutput = "NVHHZTVGLVMXLWV";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed secure symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
correctOutput = "NVHHZTVGLVMXLWV";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed secure mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@@ -192,30 +192,30 @@ public class TestAtbash{
|
||||
String inputString = "nvhhztvglvmxlwv";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "NVHHZTVGLVMXLWV";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "nvhhztv gl vmxlwv";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "nvhhztv*gl+vmxlwv";
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "Nvhhztv gl^vmxlwv";
|
||||
correctOutput = "Message to^encode";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -226,30 +226,30 @@ public class TestAtbash{
|
||||
String inputString = "nvhhztvglvmxlwv";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no capital lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "NVHHZTVGLVMXLWV";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no capital uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "nvhhztv gl vmxlwv";
|
||||
correctOutput = "MESSAGE TO ENCODE";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no capital whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "nvhhztv*gl+vmxlwv";
|
||||
correctOutput = "MESSAGE*TO+ENCODE";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no capital symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "Nvhhztv gl^vmxlwv";
|
||||
correctOutput = "MESSAGE TO^ENCODE";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no capital mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -260,30 +260,30 @@ public class TestAtbash{
|
||||
String inputString = "nvhhztvglvmxlwv";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no whitespace lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "NVHHZTVGLVMXLWV";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no whitespace uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "nvhhztv gl vmxlwv";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "nvhhztv*gl+vmxlwv";
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no whitespace symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "Nvhhztv gl^vmxlwv";
|
||||
correctOutput = "Messageto^encode";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no whitespace mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -294,30 +294,30 @@ public class TestAtbash{
|
||||
String inputString = "nvhhztvglvmxlwv";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no symbol lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "NVHHZTVGLVMXLWV";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no symbol uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "nvhhztv gl vmxlwv";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no symbol whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "nvhhztv*gl+vmxlwv";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no symbol symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "Nvhhztv gl^vmxlwv";
|
||||
correctOutput = "Message toencode";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed no symbol mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -328,29 +328,29 @@ public class TestAtbash{
|
||||
String inputString = "nvhhztvglvmxlwv";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed secure lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "NVHHZTVGLVMXLWV";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed secure uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "nvhhztv gl vmxlwv";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed secure whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "nvhhztv*gl+vmxlwv";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed secure symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "Nvhhztv gl^vmxlwv";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Atbash failed secure mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/monoSubstitution/TestAutokey.java
|
||||
//Mattrixwv
|
||||
// Created: 07-26-21
|
||||
//Modified: 02-22-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
@@ -23,34 +23,34 @@ public class TestAutokey{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "wiqooxhfswfcuhx";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Autokey failed lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "WIQOOXHFSWFCUHX";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Autokey failed uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "wiqooxh fs wfcuhx";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Autokey failed whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "wiqooxh*fs+wfcuhx";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Autokey failed symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Wiqooxh fs^wfcuhx";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Autokey failed mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -62,34 +62,34 @@ public class TestAutokey{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "WIQOOXHFSWFCUHX";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Autokey failed no capital lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "WIQOOXHFSWFCUHX";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Autokey failed no capital uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "WIQOOXH FS WFCUHX";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Autokey failed no capital whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "WIQOOXH*FS+WFCUHX";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Autokey failed no capital symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "WIQOOXH FS^WFCUHX";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Autokey failed no capital mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,34 +101,34 @@ public class TestAutokey{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "wiqooxhfswfcuhx";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Autokey failed no whitespace lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "WIQOOXHFSWFCUHX";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Autokey failed no whitespace uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "wiqooxhfswfcuhx";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Autokey failed no whitespace whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "wiqooxh*fs+wfcuhx";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Autokey failed no whitespace symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Wiqooxhfs^wfcuhx";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Autokey failed no whitespace mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -140,34 +140,34 @@ public class TestAutokey{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "wiqooxhfswfcuhx";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Autokey failed no symbol lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "WIQOOXHFSWFCUHX";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Autokey failed no symbol uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "wiqooxh fs wfcuhx";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Autokey failed no symbol whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "wiqooxhfswfcuhx";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Autokey failed no symbol symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Wiqooxh fswfcuhx";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Autokey failed no symbol mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -179,34 +179,34 @@ public class TestAutokey{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "WIQOOXHFSWFCUHX";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Autokey failed secure lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "WIQOOXHFSWFCUHX";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Autokey failed secure uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "WIQOOXHFSWFCUHX";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Autokey failed secure whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "WIQOOXHFSWFCUHX";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Autokey failed secure symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "WIQOOXHFSWFCUHX";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Autokey failed secure mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@@ -219,34 +219,34 @@ public class TestAutokey{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Autokey failed lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "WIQOOXHFSWFCUHX";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Autokey failed uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "wiqooxh fs wfcuhx";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Autokey failed whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "wiqooxh*fs+wfcuhx";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Autokey failed symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Wiqooxh fs^wfcuhx";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Message to^encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Autokey failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -258,34 +258,34 @@ public class TestAutokey{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Autokey failed no capital lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "WIQOOXHFSWFCUHX";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Autokey failed no capital uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "WIQOOXH FS WFCUHX";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE TO ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Autokey failed no capital whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "WIQOOXH*FS+WFCUHX";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE*TO+ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Autokey failed no capital symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "WIQOOXH FS^WFCUHX";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE TO^ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Autokey failed no capital mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -297,34 +297,34 @@ public class TestAutokey{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Autokey failed no whitespace lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "WIQOOXHFSWFCUHX";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Autokey failed no whitespace uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "wiqooxh fs wfcuhx";
|
||||
keyword = "keyword";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Autokey failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "wiqooxh*fs+wfcuhx";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Autokey failed no whitespace symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Wiqooxh fs^wfcuhx";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Messageto^encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Autokey failed no whitespace mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -336,34 +336,34 @@ public class TestAutokey{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Autokey failed no symbol lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "WIQOOXHFSWFCUHX";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Autokey failed no symbol uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "wiqooxh fs wfcuhx";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Autokey failed no symbol whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "wiqooxh*fs+wfcuhx";
|
||||
keyword = "keyword";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Autokey failed no symbol symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Wiqooxh fs^wfcuhx";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Message toencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Autokey failed no symbol mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -375,34 +375,34 @@ public class TestAutokey{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Autokey failed secure lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "WIQOOXHFSWFCUHX";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Autokey failed secure uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "WIQOOXH FS WFCUHX";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Autokey failed secure whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "WIQOOXH*FS+WFCUHX";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Autokey failed secure symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "WIQOOXH FS^WFCUHX";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Autokey failed secure mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@@ -415,7 +415,7 @@ public class TestAutokey{
|
||||
String correctOutput = "XYZ";
|
||||
cipher.setKeyword(keyword);
|
||||
String output = cipher.getKeyword();
|
||||
assertEquals("Autokey failed keyword with whitespace.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test keyword with symbol
|
||||
@@ -423,7 +423,7 @@ public class TestAutokey{
|
||||
correctOutput = "XYZ";
|
||||
cipher.setKeyword(keyword);
|
||||
output = cipher.getKeyword();
|
||||
assertEquals("Autokey failed keyword with symbol.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test keyword with mixed case
|
||||
@@ -431,13 +431,13 @@ public class TestAutokey{
|
||||
correctOutput = "XYZ";
|
||||
cipher.setKeyword(keyword);
|
||||
output = cipher.getKeyword();
|
||||
assertEquals("Autokey failed keyword with mixed case.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test keyword with whitespace, symbol and keyword
|
||||
keyword = "x Y%z ";
|
||||
correctOutput = "XYZ";
|
||||
cipher.setKeyword(keyword);
|
||||
output = cipher.getKeyword();
|
||||
assertEquals("Autokey failed keyword with space, symbol, and mixed case.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/TestBaconian.java
|
||||
//Mattrixwv
|
||||
// Created: 01-12-22
|
||||
//Modified: 01-12-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
@@ -22,18 +22,18 @@ public class TestBaconian{
|
||||
String inputString = "messagetoencode";
|
||||
String correctOutput = "ababb aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
String output = cipher.encode(inputString);
|
||||
assertEquals("Baconian failed lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
correctOutput = "ABABB AABAA BAAAB BAAAB AAAAA AABBA AABAA BAABA ABBAB AABAA ABBAA AAABA ABBAB AAABB AABAA";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Baconian failed uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "Message to-encode";
|
||||
correctOutput = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Baconian failed mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testEncodeNoCapital() throws InvalidInputException{
|
||||
@@ -43,18 +43,18 @@ public class TestBaconian{
|
||||
String inputString = "messagetoencode";
|
||||
String correctOutput = "ababb aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
String output = cipher.encode(inputString);
|
||||
assertEquals("Baconian failed no capital lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
correctOutput = "ababb aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Baconian failed no capital uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "Message to-encode";
|
||||
correctOutput = "ababb aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Baconian failed no capital mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@@ -66,18 +66,18 @@ public class TestBaconian{
|
||||
String inputString = "ababb aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(inputString);
|
||||
assertEquals("Baconian failed lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "ABABB AABAA BAAAB BAAAB AAAAA AABBA AABAA BAABA ABBAB AABAA ABBAA AAABA ABBAB AAABB AABAA";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Baconian failed uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
correctOutput = "Messagetoencode";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Baconian failed mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testDecodeNoCapital() throws InvalidCharacterException, InvalidInputException{
|
||||
@@ -87,17 +87,17 @@ public class TestBaconian{
|
||||
String inputString = "ababb aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(inputString);
|
||||
assertEquals("Baconian failed no capital lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "ABABB AABAA BAAAB BAAAB AAAAA AABBA AABAA BAABA ABBAB AABAA ABBAA AAABA ABBAB AAABB AABAA";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Baconian failed no capital uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Baconian failed no capital mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/monoSubstitution/TestBaseX.java
|
||||
//Mattrixwv
|
||||
// Created: 01-08-22
|
||||
//Modified: 01-09-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidBaseException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
@@ -23,30 +23,30 @@ public class TestBaseX{
|
||||
String inputString = "a";
|
||||
String correctOutput = "1100001";
|
||||
String output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed binary lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "A";
|
||||
correctOutput = "1000001";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed binary uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "A B\tC\n";
|
||||
correctOutput = "1000001 100000 1000010 1001 1000011 1010";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed binary whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "A@B-C+";
|
||||
correctOutput = "1000001 1000000 1000010 101101 1000011 101011";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed binary symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "A+B@C d\te\nf";
|
||||
correctOutput = "1000001 101011 1000010 1000000 1000011 100000 1100100 1001 1100101 1010 1100110";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed binary mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testOctalEncode() throws InvalidBaseException, InvalidInputException{
|
||||
@@ -56,30 +56,30 @@ public class TestBaseX{
|
||||
String inputString = "a";
|
||||
String correctOutput = "141";
|
||||
String output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed octal lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "A";
|
||||
correctOutput = "101";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed octal uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "A B\tC\n";
|
||||
correctOutput = "101 40 102 11 103 12";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed octal whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "A@B-C+";
|
||||
correctOutput = "101 100 102 55 103 53";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed octal symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "A+B@C d\te\nf";
|
||||
correctOutput = "101 53 102 100 103 40 144 11 145 12 146";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed octal mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testDecimalEncode() throws InvalidBaseException, InvalidInputException{
|
||||
@@ -89,30 +89,30 @@ public class TestBaseX{
|
||||
String inputString = "a";
|
||||
String correctOutput = "97";
|
||||
String output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed decimal lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "A";
|
||||
correctOutput = "65";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed decimal uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "A B\tC\n";
|
||||
correctOutput = "65 32 66 9 67 10";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed decimal whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "A@B-C+";
|
||||
correctOutput = "65 64 66 45 67 43";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed decimal symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "A+B@C d\te\nf";
|
||||
correctOutput = "65 43 66 64 67 32 100 9 101 10 102";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed decimal mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testHexEncode() throws InvalidBaseException, InvalidInputException{
|
||||
@@ -122,30 +122,30 @@ public class TestBaseX{
|
||||
String correctOutput = "61";
|
||||
String inputString = "a";
|
||||
String output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed hex lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "A";
|
||||
correctOutput = "41";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed hex uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "A B\tC\n";
|
||||
correctOutput = "41 20 42 9 43 A";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed hex whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "A@B-C+";
|
||||
correctOutput = "41 40 42 2D 43 2B";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed hex symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "A+B@C d\te\nf";
|
||||
correctOutput = "41 2B 42 40 43 20 64 9 65 A 66";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed hex mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@@ -157,30 +157,30 @@ public class TestBaseX{
|
||||
String inputString = "1100001";
|
||||
String correctOutput = "a";
|
||||
String output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed binary lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "1000001";
|
||||
correctOutput = "A";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed binary uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "1000001 100000 1000010 1001 1000011 1010";
|
||||
correctOutput = "A B\tC\n";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed binary whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "1000001 1000000 1000010 101101 1000011 101011";
|
||||
correctOutput = "A@B-C+";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed binary symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "1000001 101011 1000010 1000000 1000011 100000 1100100 1001 1100101 1010 1100110";
|
||||
correctOutput = "A+B@C d\te\nf";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed binary mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testOctalDecode() throws InvalidCharacterException, InvalidBaseException, InvalidInputException{
|
||||
@@ -190,30 +190,30 @@ public class TestBaseX{
|
||||
String inputString = "141";
|
||||
String correctOutput = "a";
|
||||
String output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed octal lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "101";
|
||||
correctOutput = "A";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed octal uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "101 40 102 11 103 12";
|
||||
correctOutput = "A B\tC\n";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed octal whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "101 100 102 55 103 53";
|
||||
correctOutput = "A@B-C+";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed octal symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "101 53 102 100 103 40 144 11 145 12 146";
|
||||
correctOutput = "A+B@C d\te\nf";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed octal mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testDecimalDecode() throws InvalidCharacterException, InvalidBaseException, InvalidInputException{
|
||||
@@ -223,30 +223,30 @@ public class TestBaseX{
|
||||
String inputString = "97";
|
||||
String correctOutput = "a";
|
||||
String output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed decimal lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "65";
|
||||
correctOutput = "A";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed decimal uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "65 32 66 9 67 10";
|
||||
correctOutput = "A B\tC\n";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed decimal whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "65 64 66 45 67 43";
|
||||
correctOutput = "A@B-C+";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed decimal symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "65 43 66 64 67 32 100 9 101 10 102";
|
||||
correctOutput = "A+B@C d\te\nf";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed decimal mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testHexDecode() throws InvalidCharacterException, InvalidBaseException, InvalidInputException{
|
||||
@@ -256,29 +256,29 @@ public class TestBaseX{
|
||||
String inputString = "61";
|
||||
String correctOutput = "a";
|
||||
String output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed hex lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "41";
|
||||
correctOutput = "A";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed hex uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "41 20 42 9 43 A";
|
||||
correctOutput = "A B\tC\n";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed hex whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "41 40 42 2D 43 2B";
|
||||
correctOutput = "A@B-C+";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed hex symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "41 2B 42 40 43 20 64 9 65 A 66";
|
||||
correctOutput = "A+B@C d\te\nf";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed hex mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/monoSubstitution/TestBeaufort.java
|
||||
//Mattrixwv
|
||||
// Created: 02-23-22
|
||||
//Modified: 02-23-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
@@ -23,34 +23,34 @@ public class TestBeaufort{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "yageolzrqujmdag";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "YAGEOLZRQUJMDAG";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "yageolz rq ujmdag";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "yageolz*rq+ujmdag";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Yageolz rq^ujmdag";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -62,34 +62,34 @@ public class TestBeaufort{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "YAGEOLZRQUJMDAG";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no capital lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "YAGEOLZRQUJMDAG";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no capital uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "YAGEOLZ RQ UJMDAG";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no capital whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "YAGEOLZ*RQ+UJMDAG";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no capital symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "YAGEOLZ RQ^UJMDAG";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no capital mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,34 +101,34 @@ public class TestBeaufort{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "yageolzrqujmdag";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no whitespace lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "YAGEOLZRQUJMDAG";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no whitespace uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "yageolzrqujmdag";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no whitespace whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "yageolz*rq+ujmdag";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no whitespace symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Yageolzrq^ujmdag";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no whitespace mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -140,34 +140,34 @@ public class TestBeaufort{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "yageolzrqujmdag";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no symbol lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "YAGEOLZRQUJMDAG";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no symbol uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "yageolz rq ujmdag";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no symbol whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "yageolzrqujmdag";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no symbol symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Yageolz rqujmdag";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no symbol mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -179,34 +179,34 @@ public class TestBeaufort{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "YAGEOLZRQUJMDAG";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed secure lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "YAGEOLZRQUJMDAG";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed secure uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "YAGEOLZRQUJMDAG";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed secure whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "YAGEOLZRQUJMDAG";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed secure symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "YAGEOLZRQUJMDAG";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Beaufort failed secure mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@@ -219,34 +219,34 @@ public class TestBeaufort{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "YAGEOLZRQUJMDAG";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "yageolz rq ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "yageolz*rq+ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Yageolz rq^ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Message to^encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -258,34 +258,34 @@ public class TestBeaufort{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no capital lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "YAGEOLZRQUJMDAG";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no capital uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "yageolz rq ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE TO ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no capital whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "yageolz*rq+ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE*TO+ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no capital symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Yageolz rq^ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE TO^ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no capital mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -297,34 +297,34 @@ public class TestBeaufort{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no whitespace lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "YAGEOLZRQUJMDAG";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no whitespace uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "yageolz rq ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "yageolz*rq+ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no whitespace symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Yageolz rq^ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Messageto^encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no whitespace mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -336,34 +336,34 @@ public class TestBeaufort{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no symbol lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "YAGEOLZRQUJMDAG";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no symbol uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "yageolz rq ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no symbol whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "yageolz*rq+ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no symbol symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Yageolz rq^ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Message toencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed no symbol mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -375,33 +375,33 @@ public class TestBeaufort{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed secure lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "YAGEOLZRQUJMDAG";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed secure uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "yageolz rq ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed secure whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "yageolz*rq+ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed secure symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Yageolz rq^ujmdag";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Beaufort failed secure mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/TestCaesar.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-25-21
|
||||
//Modified: 01-04-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
|
||||
@@ -22,13 +22,13 @@ public class TestCaesar{
|
||||
int shift = 3;
|
||||
String correctOutput = "def";
|
||||
String output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
input = "ABC";
|
||||
shift = 3;
|
||||
correctOutput = "DEF";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Ceasar failed uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test out of bounds shift encoding
|
||||
@@ -36,13 +36,13 @@ public class TestCaesar{
|
||||
shift = 29;
|
||||
correctOutput = "def";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed out of bounds shift encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test out of bounds shift encoding negative
|
||||
input = "abc";
|
||||
shift = -23;
|
||||
correctOutput = "def";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Causar failed out of bounds shift negative encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace encoding
|
||||
@@ -50,7 +50,7 @@ public class TestCaesar{
|
||||
shift = 3;
|
||||
correctOutput = "def ghi";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol encoding
|
||||
@@ -58,7 +58,7 @@ public class TestCaesar{
|
||||
shift = 3;
|
||||
correctOutput = "def-ghi@";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
@@ -66,13 +66,13 @@ public class TestCaesar{
|
||||
shift = 23;
|
||||
correctOutput = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whitespace, and symbol encoding with negative shift
|
||||
input = "The quick brown fox jumps over - the lazy dog";
|
||||
shift = -3;
|
||||
correctOutput = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed mixed case, whitespace, and symbol encoding with negative shift.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalEncode() throws InvalidInputException{
|
||||
@@ -83,13 +83,13 @@ public class TestCaesar{
|
||||
int shift = 3;
|
||||
String correctOutput = "def";
|
||||
String output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed no capital lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
input = "ABC";
|
||||
shift = 3;
|
||||
correctOutput = "def";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Ceasar failed no capital uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test out of bounds shift encoding
|
||||
@@ -97,13 +97,13 @@ public class TestCaesar{
|
||||
shift = 29;
|
||||
correctOutput = "def";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed no capital out of bounds shift encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test out of bounds shift encoding negative
|
||||
input = "abc";
|
||||
shift = -23;
|
||||
correctOutput = "def";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed no capital out of bounds shift negative encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace encoding
|
||||
@@ -111,7 +111,7 @@ public class TestCaesar{
|
||||
shift = 3;
|
||||
correctOutput = "def ghi";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed no capital whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
@@ -119,7 +119,7 @@ public class TestCaesar{
|
||||
shift = 3;
|
||||
correctOutput = "def-ghi@";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed no capital symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
@@ -127,13 +127,13 @@ public class TestCaesar{
|
||||
shift = 23;
|
||||
correctOutput = "qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed no capital mixed case, whitespace, and symbol ecoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whitespace, and symbol encoding with negative shift
|
||||
input = "The quick brown fox jumps over - the lazy dog";
|
||||
shift = -3;
|
||||
correctOutput = "qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed no capital mixed case, whitespace, and symbol encoding with negative shift.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceEncode() throws InvalidInputException{
|
||||
@@ -144,13 +144,13 @@ public class TestCaesar{
|
||||
int shift = 3;
|
||||
String correctOutput = "def";
|
||||
String output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed no whitespace lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
input = "ABC";
|
||||
shift = 3;
|
||||
correctOutput = "DEF";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Ceasar failed no whitespace uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test out of bounds shift encoding
|
||||
@@ -158,13 +158,13 @@ public class TestCaesar{
|
||||
shift = 29;
|
||||
correctOutput = "def";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed no whitespace out of bounds shift encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test out of bounds shift encoding negative
|
||||
input = "abc";
|
||||
shift = -23;
|
||||
correctOutput = "def";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed no whitespace out of bounds shift negative encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace encoding
|
||||
@@ -172,7 +172,7 @@ public class TestCaesar{
|
||||
shift = 3;
|
||||
correctOutput = "defghi";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed no whitespace whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol encoding
|
||||
@@ -180,7 +180,7 @@ public class TestCaesar{
|
||||
shift = 3;
|
||||
correctOutput = "def-ghi@";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed no whitespace symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Testing mixed case, whitespace, and symbol encoding
|
||||
@@ -188,13 +188,13 @@ public class TestCaesar{
|
||||
shift = 23;
|
||||
correctOutput = "Qebnrfzhyoltkclugrjmplsbo-qebixwvald";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed no whitespace mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Testing mixed case, whitespace, and symbol encoding
|
||||
input = "The quick brown fox jumps over - the lazy dog";
|
||||
shift = -3;
|
||||
correctOutput = "Qebnrfzhyoltkclugrjmplsbo-qebixwvald";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed no whitespace mixed case, whitespace, and symbol encoding with negative shift.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolEncode() throws InvalidInputException{
|
||||
@@ -205,13 +205,13 @@ public class TestCaesar{
|
||||
int shift = 3;
|
||||
String correctOutput = "def";
|
||||
String output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed no symbol lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
input = "ABC";
|
||||
shift = 3;
|
||||
correctOutput = "DEF";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Ceasar failed no symbol uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test out of bounds shift encoding
|
||||
@@ -219,13 +219,13 @@ public class TestCaesar{
|
||||
shift = 29;
|
||||
correctOutput = "def";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed no symbol out of bounds shift encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test out of bounds shift encoding negative
|
||||
input = "abc";
|
||||
shift = -23;
|
||||
correctOutput = "def";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed no symbol out of bounds shift negative encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace encoding
|
||||
@@ -233,7 +233,7 @@ public class TestCaesar{
|
||||
shift = 3;
|
||||
correctOutput = "def ghi";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed no symbol whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
@@ -241,7 +241,7 @@ public class TestCaesar{
|
||||
shift = 3;
|
||||
correctOutput = "defghi";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
@@ -249,13 +249,13 @@ public class TestCaesar{
|
||||
shift = 23;
|
||||
correctOutput = "Qeb nrfzh yoltk clu grjmp lsbo qeb ixwv ald";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//test mixed case, whitespace, and symbol encoding with negative shift
|
||||
input = "The quick brown fox jumps over - the lazy dog";
|
||||
shift = -3;
|
||||
correctOutput = "Qeb nrfzh yoltk clu grjmp lsbo qeb ixwv ald";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed mixed case, whitespace, and symbol encoding with negative shift.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidInputException{
|
||||
@@ -266,13 +266,13 @@ public class TestCaesar{
|
||||
int shift = 3;
|
||||
String correctOutput = "def";
|
||||
String output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed secure lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
input = "ABC";
|
||||
shift = 3;
|
||||
correctOutput = "def";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Ceasar failed secure uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test out of bounds shift encoding
|
||||
@@ -280,13 +280,13 @@ public class TestCaesar{
|
||||
shift = 29;
|
||||
correctOutput = "def";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed secure out of bounds shift encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test out of bounds shift encoding negative
|
||||
input = "abc";
|
||||
shift = 29;
|
||||
correctOutput = "def";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed secure out of bounds shift negative encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace encoding
|
||||
@@ -294,7 +294,7 @@ public class TestCaesar{
|
||||
shift = 3;
|
||||
correctOutput = "defghi";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed secure whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol encoding
|
||||
@@ -302,7 +302,7 @@ public class TestCaesar{
|
||||
shift = 3;
|
||||
correctOutput = "defghi";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed secure symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
@@ -310,13 +310,13 @@ public class TestCaesar{
|
||||
shift = 23;
|
||||
correctOutput = "qebnrfzhyoltkclugrjmplsboqebixwvald";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed secure mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whitespace, and symbol encoding with negative shift
|
||||
input = "The quick brown fox jumps over - the lazy dog";
|
||||
shift = -3;
|
||||
correctOutput = "qebnrfzhyoltkclugrjmplsboqebixwvald";
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed secure mixed case, whitespace, and symbol encoding with negative shift.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@@ -329,13 +329,13 @@ public class TestCaesar{
|
||||
int shift = 3;
|
||||
String correctOutput = "abc";
|
||||
String output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "DEF";
|
||||
shift = 3;
|
||||
correctOutput = "ABC";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test out of bounds shift decoding
|
||||
@@ -343,13 +343,13 @@ public class TestCaesar{
|
||||
shift = 29;
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed out of bounds shift decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test out of bounds shift negative decoding
|
||||
input = "def";
|
||||
shift = -23;
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed out of bounds shift negative decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
@@ -357,7 +357,7 @@ public class TestCaesar{
|
||||
shift = 3;
|
||||
correctOutput = "abc def";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
@@ -365,7 +365,7 @@ public class TestCaesar{
|
||||
shift = 3;
|
||||
correctOutput = "abc-def@";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
@@ -373,13 +373,13 @@ public class TestCaesar{
|
||||
shift = 23;
|
||||
correctOutput = "The quick brown fox jumps over - the lazy dog";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whitespace, and symbol decoding with negative shift
|
||||
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
shift = -3;
|
||||
correctOutput = "The quick brown fox jumps over - the lazy dog";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed mixed case, whitespace, and symbol decoding with negative shift.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalDecode() throws InvalidInputException{
|
||||
@@ -390,13 +390,13 @@ public class TestCaesar{
|
||||
int shift = 3;
|
||||
String correctOutput = "abc";
|
||||
String output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no capital lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "DEF";
|
||||
shift = 3;
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no capital uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test out of bounds shift decoding
|
||||
@@ -404,13 +404,13 @@ public class TestCaesar{
|
||||
shift = 29;
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no capital out of bounds shift decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test out of bounds shift negative decoding
|
||||
input = "def";
|
||||
shift = -23;
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no capital out of bounds shift negative decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
@@ -418,7 +418,7 @@ public class TestCaesar{
|
||||
shift = 3;
|
||||
correctOutput = "abc def";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesare failed no capital whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
@@ -426,7 +426,7 @@ public class TestCaesar{
|
||||
shift = 3;
|
||||
correctOutput = "abc-def@";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no capital symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
@@ -434,13 +434,13 @@ public class TestCaesar{
|
||||
shift = 23;
|
||||
correctOutput = "the quick brown fox jumps over - the lazy dog";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no capital mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whitespace, and symbol with negative shift
|
||||
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
shift = -3;
|
||||
correctOutput = "the quick brown fox jumps over - the lazy dog";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no capital mixed case, whitespace, and symbol decoding with negative shift.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceDecode() throws InvalidInputException{
|
||||
@@ -451,13 +451,13 @@ public class TestCaesar{
|
||||
int shift = 3;
|
||||
String correctOutput = "abc";
|
||||
String output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no whitespace lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "DEF";
|
||||
shift = 3;
|
||||
correctOutput = "ABC";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no whitespace uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test out of bounds shift decoding
|
||||
@@ -465,13 +465,13 @@ public class TestCaesar{
|
||||
shift = 29;
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no whitespace out of bounds shift decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test out of bounds shift negative decoding
|
||||
input = "def";
|
||||
shift = -23;
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no whitespace out of bounds shift negative decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
@@ -479,7 +479,7 @@ public class TestCaesar{
|
||||
shift = 3;
|
||||
correctOutput = "abcdef";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
@@ -487,7 +487,7 @@ public class TestCaesar{
|
||||
shift = 3;
|
||||
correctOutput = "abc-def@";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no whitespace symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
@@ -495,13 +495,13 @@ public class TestCaesar{
|
||||
shift = 23;
|
||||
correctOutput = "Thequickbrownfoxjumpsover-thelazydog";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no whitespace mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whitespace, and symbol decoding with negative shift
|
||||
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
shift = -3;
|
||||
correctOutput = "Thequickbrownfoxjumpsover-thelazydog";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no whitespace mixed case, whitespace, and symbol decoding with negative shift.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolDecode() throws InvalidInputException{
|
||||
@@ -512,13 +512,13 @@ public class TestCaesar{
|
||||
int shift = 3;
|
||||
String correctOutput = "abc";
|
||||
String output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no symbol lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "DEF";
|
||||
shift = 3;
|
||||
correctOutput = "ABC";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no symbol uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test out of bounds shift decoding
|
||||
@@ -526,13 +526,13 @@ public class TestCaesar{
|
||||
shift = 29;
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no symbol out of bounds shift decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test out of bounds shift negative decoding
|
||||
input = "def";
|
||||
shift = -23;
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no symbol out of bounds shift negative decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test whitepace decoding
|
||||
@@ -540,7 +540,7 @@ public class TestCaesar{
|
||||
shift = 3;
|
||||
correctOutput = "abc def";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no symbol whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
@@ -548,7 +548,7 @@ public class TestCaesar{
|
||||
shift = 3;
|
||||
correctOutput = "abcdef";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no symbol symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
@@ -556,13 +556,13 @@ public class TestCaesar{
|
||||
shift = 23;
|
||||
correctOutput = "The quick brown fox jumps over the lazy dog";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no symbol mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whitespace, and symbol decoding with negative shift
|
||||
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
shift = -3;
|
||||
correctOutput = "The quick brown fox jumps over the lazy dog";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no symbol mixed case, whitespace, and symbol decoding with negative shift.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidInputException{
|
||||
@@ -573,13 +573,13 @@ public class TestCaesar{
|
||||
int shift = 3;
|
||||
String correctOutput = "abc";
|
||||
String output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed secure lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "DEF";
|
||||
shift = 3;
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed secure uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test out of bounds shift decoding
|
||||
@@ -587,13 +587,13 @@ public class TestCaesar{
|
||||
shift = 29;
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed secure out of bounds shift decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test out of bounds shift negative decoding
|
||||
input = "def";
|
||||
shift = -23;
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed secure out of bounds shift negative decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
@@ -601,7 +601,7 @@ public class TestCaesar{
|
||||
shift = 3;
|
||||
correctOutput = "abcdef";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed secure whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
@@ -609,7 +609,7 @@ public class TestCaesar{
|
||||
shift = 3;
|
||||
correctOutput = "abcdef";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed secure symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
@@ -617,12 +617,12 @@ public class TestCaesar{
|
||||
shift = 23;
|
||||
correctOutput = "thequickbrownfoxjumpsoverthelazydog";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed secure mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whitespace, and symbol decoding with negative shift
|
||||
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
shift = -3;
|
||||
correctOutput = "thequickbrownfoxjumpsoverthelazydog";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed secure mixed case, whitespace, and symbol decoding with negative shift.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/monoSubstitution/TestOneTimePad.java
|
||||
//Mattrixwv
|
||||
// Created: 02-23-22
|
||||
//Modified: 02-23-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
@@ -23,34 +23,34 @@ public class TestOneTimePad{
|
||||
String keyword = "keywordThatIsTotallyRandom";
|
||||
String correctOutput = "wiqooxhmvegkgws";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "WIQOOXHMVEGKGWS";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "wiqooxh mv egkgws";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "wiqooxh*mv+egkgws";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whtiespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "Wiqooxh mv^egkgws";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -62,34 +62,34 @@ public class TestOneTimePad{
|
||||
String keyword = "keywordThatIsTotallyRandom";
|
||||
String correctOutput = "WIQOOXHMVEGKGWS";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no capital lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "WIQOOXHMVEGKGWS";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no capital uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "WIQOOXH MV EGKGWS";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no capital whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "WIQOOXH*MV+EGKGWS";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no capital symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whtiespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "WIQOOXH MV^EGKGWS";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no capital mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,34 +101,34 @@ public class TestOneTimePad{
|
||||
String keyword = "keywordThatIsTotallyRandom";
|
||||
String correctOutput = "wiqooxhmvegkgws";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no whitespace lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "WIQOOXHMVEGKGWS";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no whitespace uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "wiqooxhmvegkgws";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no whitespace whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "wiqooxh*mv+egkgws";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no whitespace symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whtiespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "Wiqooxhmv^egkgws";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no whitespace mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -140,34 +140,34 @@ public class TestOneTimePad{
|
||||
String keyword = "keywordThatIsTotallyRandom";
|
||||
String correctOutput = "wiqooxhmvegkgws";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no symbol lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "WIQOOXHMVEGKGWS";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no symbol uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "wiqooxh mv egkgws";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no symbol whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "wiqooxhmvegkgws";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no symbol symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whtiespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "Wiqooxh mvegkgws";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no symbol mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -179,34 +179,34 @@ public class TestOneTimePad{
|
||||
String keyword = "keywordThatIsTotallyRandom";
|
||||
String correctOutput = "WIQOOXHMVEGKGWS";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed secure lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "WIQOOXHMVEGKGWS";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed secure uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "WIQOOXHMVEGKGWS";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed secure whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "WIQOOXHMVEGKGWS";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed secure symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whtiespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "WIQOOXHMVEGKGWS";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed secure mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@@ -219,34 +219,34 @@ public class TestOneTimePad{
|
||||
String keyword = "keywordThatIsTotallyRandom";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "WIQOOXHMVEGKGWS";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "wiqooxh mv egkgws";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "wiqooxh*mv+egkgws";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whtiespace, symbol decoding
|
||||
inputString = "Wiqooxh mv^egkgws";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "Message to^encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -258,34 +258,34 @@ public class TestOneTimePad{
|
||||
String keyword = "keywordThatIsTotallyRandom";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no capital lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "WIQOOXHMVEGKGWS";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no capital uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "wiqooxh mv egkgws";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "MESSAGE TO ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no capital whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "wiqooxh*mv+egkgws";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "MESSAGE*TO+ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no capital symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whtiespace, symbol decoding
|
||||
inputString = "Wiqooxh mv^egkgws";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "MESSAGE TO^ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no capital mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -297,34 +297,34 @@ public class TestOneTimePad{
|
||||
String keyword = "keywordThatIsTotallyRandom";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no whitespace lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "WIQOOXHMVEGKGWS";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no whitespace uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "wiqooxh mv egkgws";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "wiqooxh*mv+egkgws";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no whitespace symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whtiespace, symbol decoding
|
||||
inputString = "Wiqooxh mv^egkgws";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "Messageto^encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no whitespace mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -336,34 +336,34 @@ public class TestOneTimePad{
|
||||
String keyword = "keywordThatIsTotallyRandom";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no symbol lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "WIQOOXHMVEGKGWS";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no symbol uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "wiqooxh mv egkgws";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no symbol whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "wiqooxh*mv+egkgws";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no symbol symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whtiespace, symbol decoding
|
||||
inputString = "Wiqooxh mv^egkgws";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "Message toencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed no symbol mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -375,33 +375,33 @@ public class TestOneTimePad{
|
||||
String keyword = "keywordThatIsTotallyRandom";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed secure lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "WIQOOXHMVEGKGWS";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed secure uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "wiqooxh mv egkgws";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed secure whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "wiqooxh*mv+egkgws";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed secure symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whtiespace, symbol decoding
|
||||
inputString = "Wiqooxh mv^egkgws";
|
||||
keyword = "keywordThatIsTotallyRandom";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("OneTimePad failed secure mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/monoSubstitution/TestPorta.java
|
||||
//Mattrixwv
|
||||
// Created: 02-28-22
|
||||
//Modified: 02-28-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
@@ -23,34 +23,34 @@ public class TestPorta{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "rtghuosbmqcwgrw";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Porta failed lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "RTGHUOSBMQCWGRW";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Porta failed uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "rtghuos bm qcwgrw";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Porta failed whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "rtghuos*bm+qcwgrw";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Porta failed symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Rtghuos bm^qcwgrw";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Porta failed mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -62,34 +62,34 @@ public class TestPorta{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "RTGHUOSBMQCWGRW";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Porta failed no capital lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "RTGHUOSBMQCWGRW";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Porta failed no capital uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "RTGHUOS BM QCWGRW";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Porta failed no capital whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "RTGHUOS*BM+QCWGRW";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Porta failed no capital symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "RTGHUOS BM^QCWGRW";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Porta failed no capital mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,34 +101,34 @@ public class TestPorta{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "rtghuosbmqcwgrw";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Porta failed no whitespace lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "RTGHUOSBMQCWGRW";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Porta failed no whitespace uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "rtghuosbmqcwgrw";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Porta failed no whitespace whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "rtghuos*bm+qcwgrw";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Porta failed no whitespace symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Rtghuosbm^qcwgrw";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Porta failed no whitespace mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -140,34 +140,34 @@ public class TestPorta{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "rtghuosbmqcwgrw";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Porta failed no symbol lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "RTGHUOSBMQCWGRW";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Porta failed no symbol uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "rtghuos bm qcwgrw";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Porta failed no symbol whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "rtghuosbmqcwgrw";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Porta failed no symbol symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Rtghuos bmqcwgrw";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Porta failed no symbol mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -179,34 +179,34 @@ public class TestPorta{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "RTGHUOSBMQCWGRW";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Porta failed secure lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "RTGHUOSBMQCWGRW";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Porta failed secure uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "RTGHUOSBMQCWGRW";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Porta failed secure whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "RTGHUOSBMQCWGRW";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Porta failed secure symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "RTGHUOSBMQCWGRW";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Porta failed secure mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@@ -219,34 +219,34 @@ public class TestPorta{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Porta failed lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "RTGHUOSBMQCWGRW";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Porta failed uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "rtghuos bm qcwgrw";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Porta failed whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "rtghuos*bm+qcwgrw";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Porta failed symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Rtghuos bm^qcwgrw";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Message to^encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Porta failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -258,34 +258,34 @@ public class TestPorta{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Porta failed no capital lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "RTGHUOSBMQCWGRW";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Porta failed no capital uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "rtghuos bm qcwgrw";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE TO ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Porta failed no capital whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "rtghuos*bm+qcwgrw";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE*TO+ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Porta failed no capital symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Rtghuos bm^qcwgrw";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE TO^ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Porta failed no capital mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -297,34 +297,34 @@ public class TestPorta{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Porta failed no whitespace lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "RTGHUOSBMQCWGRW";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Porta failed no whitespace uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "rtghuos bm qcwgrw";
|
||||
keyword = "keyword";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Porta failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "rtghuos*bm+qcwgrw";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Porta failed no whitespace symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Rtghuos bm^qcwgrw";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Messageto^encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Porta failed no whitespace mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -336,34 +336,34 @@ public class TestPorta{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Porta failed lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "RTGHUOSBMQCWGRW";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Porta failed uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "rtghuos bm qcwgrw";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Porta failed whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "rtghuos*bm+qcwgrw";
|
||||
keyword = "keyword";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Porta failed symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Rtghuos bm^qcwgrw";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Message toencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Porta failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -375,33 +375,33 @@ public class TestPorta{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Porta failed secure lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "RTGHUOSBMQCWGRW";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Porta failed secure uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "rtghuos bm qcwgrw";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Porta failed secure whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "rtghuos*bm+qcwgrw";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Porta failed secure symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Rtghuos bm^qcwgrw";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Porta failed secure mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/monoSubstitution/TestSubstitution.java
|
||||
//Mattrixwv
|
||||
// Created: 02-22-22
|
||||
//Modified: 02-22-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
@@ -23,40 +23,40 @@ public class TestSubstitution{
|
||||
String key = "cdefghijklmnopqrstuvwxyzab";
|
||||
String correctOutput = "oguucigvqgpeqfg";
|
||||
String output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "OGUUCIGVQGPEQFG";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "oguucig vq gpeqfg";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "oguucig*vq+gpeqfg";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "Oguucig vq^gpeqfg";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol, number encoding with long key
|
||||
inputString = "Message to&encode 123";
|
||||
key = "cdefghijklmnopqrstuvwxyzab9876543210";
|
||||
correctOutput = "Oguucig vq&gpeqfg 876";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed mixed case, whitespace, symbol, number encoding with long key.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,40 +68,40 @@ public class TestSubstitution{
|
||||
String key = "cdefghijklmnopqrstuvwxyzab";
|
||||
String correctOutput = "OGUUCIGVQGPEQFG";
|
||||
String output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed no capital lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "OGUUCIGVQGPEQFG";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed no capital uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "OGUUCIG VQ GPEQFG";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed no capital whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "OGUUCIG*VQ+GPEQFG";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed no capital symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "OGUUCIG VQ^GPEQFG";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed no capital mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol, number encoding with long key
|
||||
inputString = "Message to&encode 123";
|
||||
key = "cdefghijklmnopqrstuvwxyzab9876543210";
|
||||
correctOutput = "OGUUCIG VQ&GPEQFG 876";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed no capital mixed case, whitespace, symbol, number encoding with long key.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -113,40 +113,40 @@ public class TestSubstitution{
|
||||
String key = "cdefghijklmnopqrstuvwxyzab";
|
||||
String correctOutput = "oguucigvqgpeqfg";
|
||||
String output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed no whitespace lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "OGUUCIGVQGPEQFG";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed no whitespace uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "oguucigvqgpeqfg";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed no whitespace whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "oguucig*vq+gpeqfg";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed no whitespace symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "Oguucigvq^gpeqfg";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed no whitespace mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol, number encoding with long key
|
||||
inputString = "Message to&encode 123";
|
||||
key = "cdefghijklmnopqrstuvwxyzab9876543210";
|
||||
correctOutput = "Oguucigvq&gpeqfg876";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed no whitespace mixed case, whitespace, symbol, number encoding with long key.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -158,40 +158,40 @@ public class TestSubstitution{
|
||||
String key = "cdefghijklmnopqrstuvwxyzab";
|
||||
String correctOutput = "oguucigvqgpeqfg";
|
||||
String output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed no symbol lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "OGUUCIGVQGPEQFG";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed no symbol uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "oguucig vq gpeqfg";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed no symbol whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "oguucigvqgpeqfg";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed no symbol symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "Oguucig vqgpeqfg";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed no symbol mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol, number encoding with long key
|
||||
inputString = "Message to&encode 123";
|
||||
key = "cdefghijklmnopqrstuvwxyzab9876543210";
|
||||
correctOutput = "Oguucig vqgpeqfg ";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed no symbol mixed case, whitespace, symbol, number encoding with long key.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -203,40 +203,40 @@ public class TestSubstitution{
|
||||
String key = "cdefghijklmnopqrstuvwxyzab";
|
||||
String correctOutput = "OGUUCIGVQGPEQFG";
|
||||
String output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed no capital lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "OGUUCIGVQGPEQFG";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed no capital uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "OGUUCIGVQGPEQFG";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed no capital whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "OGUUCIGVQGPEQFG";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed no capital symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "OGUUCIGVQGPEQFG";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed no capital mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol, number encoding with long key
|
||||
inputString = "Message to&encode 123";
|
||||
key = "cdefghijklmnopqrstuvwxyzab9876543210";
|
||||
correctOutput = "OGUUCIGVQGPEQFG";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Substitution failed no capital mixed case, whitespace, symbol, number encoding with long key.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@@ -249,40 +249,40 @@ public class TestSubstitution{
|
||||
String key = "cdefghijklmnopqrstuvwxyzab";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "OGUUCIGVQGPEQFG";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "oguucig vq gpeqfg";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "oguucig*vq+gpeqfg";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Oguucig vq^gpeqfg";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "Message to^encode";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol, number decoding with long key
|
||||
inputString = "Oguucig vq&gpeqfg 876";
|
||||
key = "cdefghijklmnopqrstuvwxyzab9876543210";
|
||||
correctOutput = "Message to&encode 123";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed mixed case, whitespace, symbol, number decoding with long key.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -294,40 +294,40 @@ public class TestSubstitution{
|
||||
String key = "cdefghijklmnopqrstuvwxyzab";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed no capital lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "OGUUCIGVQGPEQFG";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed no capital uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "oguucig vq gpeqfg";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "MESSAGE TO ENCODE";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed no capital whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "oguucig*vq+gpeqfg";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "MESSAGE*TO+ENCODE";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed no capital whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Oguucig vq^gpeqfg";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "MESSAGE TO^ENCODE";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed no capital mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol, number decoding with long key
|
||||
inputString = "Oguucig vq&gpeqfg 876";
|
||||
key = "cdefghijklmnopqrstuvwxyzab9876543210";
|
||||
correctOutput = "MESSAGE TO&ENCODE 123";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed no capital mixed case, whitespace, symbol, number decoding with long key.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -339,40 +339,40 @@ public class TestSubstitution{
|
||||
String key = "cdefghijklmnopqrstuvwxyzab";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed no whitespace lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "OGUUCIGVQGPEQFG";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed no whitespace uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "oguucig vq gpeqfg";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "oguucig*vq+gpeqfg";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Oguucig vq^gpeqfg";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "Messageto^encode";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed no whitespace mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol, number decoding with long key
|
||||
inputString = "Oguucig vq&gpeqfg 876";
|
||||
key = "cdefghijklmnopqrstuvwxyzab9876543210";
|
||||
correctOutput = "Messageto&encode123";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed no whitespace mixed case, whitespace, symbol, number decoding with long key.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -384,40 +384,40 @@ public class TestSubstitution{
|
||||
String key = "cdefghijklmnopqrstuvwxyzab";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed no symbol lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "OGUUCIGVQGPEQFG";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed no symbol uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "oguucig vq gpeqfg";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed no symbol whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "oguucig*vq+gpeqfg";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed no symbol whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Oguucig vq^gpeqfg";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "Message toencode";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed mixed no symbol case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol, number decoding with long key
|
||||
inputString = "Oguucig vq&gpeqfg 876";
|
||||
key = "cdefghijklmnopqrstuvwxyzab9876543210";
|
||||
correctOutput = "Message toencode ";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed no symbol mixed case, whitespace, symbol, number decoding with long key.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -429,39 +429,39 @@ public class TestSubstitution{
|
||||
String key = "cdefghijklmnopqrstuvwxyzab";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed secure lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "OGUUCIGVQGPEQFG";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed secure uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "oguucig vq gpeqfg";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed secure whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "oguucig*vq+gpeqfg";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed secure whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Oguucig vq^gpeqfg";
|
||||
key = "cdefghijklmnopqrstuvwxyzab";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed secure mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol, number decoding with long key
|
||||
inputString = "Oguucig vq&gpeqfg 876";
|
||||
key = "cdefghijklmnopqrstuvwxyzab9876543210";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Substitution failed secure mixed case, whitespace, symbol, number decoding with long key.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/monoSubstitution/TestVigenere.java
|
||||
//Mattrixwv
|
||||
// Created: 07-25-21
|
||||
//Modified: 02-22-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
@@ -23,34 +23,34 @@ public class TestVigenere{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "wiqooxhdscjqfgo";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Vigenere failed lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "WIQOOXHDSCJQFGO";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Vigenere failed uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "wiqooxh ds cjqfgo";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Vigenere failed whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "wiqooxh*ds+cjqfgo";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Vigenere failed symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Wiqooxh ds^cjqfgo";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -62,34 +62,34 @@ public class TestVigenere{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "WIQOOXHDSCJQFGO";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no capital lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "WIQOOXHDSCJQFGO";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no capital uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "WIQOOXH DS CJQFGO";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no capital whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "WIQOOXH*DS+CJQFGO";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no capital symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "WIQOOXH DS^CJQFGO";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no capital mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,34 +101,34 @@ public class TestVigenere{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "wiqooxhdscjqfgo";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no whitespace lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "WIQOOXHDSCJQFGO";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no whitespace uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "wiqooxhdscjqfgo";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no whitespace whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "wiqooxh*ds+cjqfgo";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no whitespace symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Wiqooxhds^cjqfgo";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no whitespace mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -140,34 +140,34 @@ public class TestVigenere{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "wiqooxhdscjqfgo";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no symbol lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "WIQOOXHDSCJQFGO";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no symbol uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "wiqooxh ds cjqfgo";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no symbol whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "wiqooxhdscjqfgo";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no symbol symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Wiqooxh dscjqfgo";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no symbol mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -179,34 +179,34 @@ public class TestVigenere{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "WIQOOXHDSCJQFGO";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Vigenere failed secure lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "WIQOOXHDSCJQFGO";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Vigenere failed secure uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "WIQOOXHDSCJQFGO";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Vigenere failed secure whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "WIQOOXHDSCJQFGO";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Vigenere failed secure symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "WIQOOXHDSCJQFGO";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Vigenere failed secure mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@@ -219,34 +219,34 @@ public class TestVigenere{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Vigenere failed lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "WIQOOXHDSCJQFGO";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Vigenere failed uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "wiqooxh ds cjqfgo";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Vigenere failed whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "wiqooxh*ds+cjqfgo";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Vigenere failed symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Wiqooxh ds^cjqfgo";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Message to^encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -258,34 +258,34 @@ public class TestVigenere{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no capital lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "WIQOOXHDSCJQFGO";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no capital uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "wiqooxh ds cjqfgo";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE TO ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no capital whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "wiqooxh*ds+cjqfgo";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE*TO+ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no capital symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Wiqooxh ds^cjqfgo";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE TO^ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no capital mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -297,34 +297,34 @@ public class TestVigenere{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no whitespace lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "WIQOOXHDSCJQFGO";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no whitespace uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "wiqooxh ds cjqfgo";
|
||||
keyword = "keyword";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "wiqooxh*ds+cjqfgo";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no whitespace symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Wiqooxh ds^cjqfgo";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Messageto^encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no whitespace mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -336,34 +336,34 @@ public class TestVigenere{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no symbol lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "WIQOOXHDSCJQFGO";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no symbol uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "wiqooxh ds cjqfgo";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no symbol whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "wiqooxh*ds+cjqfgo";
|
||||
keyword = "keyword";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no symbol symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Wiqooxh ds^cjqfgo";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Message toencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Vigenere failed no symbol mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -375,33 +375,33 @@ public class TestVigenere{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Vigenere failed secure lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "WIQOOXHDSCJQFGO";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Vigenere failed secure uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "wiqooxh ds cjqfgo";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Vigenere failed secure whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "wiqooxh*ds+cjqfgo";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Vigenere failed secure symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Wiqooxh ds^cjqfgo";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Vigenere failed secure mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/polySubstitution/TestBifid.java
|
||||
//Mattrixwv
|
||||
// Created: 03-03-22
|
||||
//Modified: 03-03-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
@@ -24,34 +24,34 @@ public class TestBifid{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "mqaoknekcvdodzd";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MQAOKNEKCVDODZD";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "mqaokne kc vdodzd";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "mqaokne*kc+vdodzd";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Mqaokne kc^vdodzd";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -63,34 +63,34 @@ public class TestBifid{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MQAOKNEKCVDODZD";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no capital lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MQAOKNEKCVDODZD";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no capital uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MQAOKNE KC VDODZD";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no capital whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MQAOKNE*KC+VDODZD";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no capital symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MQAOKNE KC^VDODZD";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no capital mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -102,34 +102,34 @@ public class TestBifid{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "mqaoknekcvdodzd";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no whitespace lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MQAOKNEKCVDODZD";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no whitespace uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "mqaoknekcvdodzd";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no whitespace whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "mqaokne*kc+vdodzd";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no whitespace symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Mqaoknekc^vdodzd";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no whitespace mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -141,34 +141,34 @@ public class TestBifid{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "mqaoknekcvdodzd";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no symbol lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MQAOKNEKCVDODZD";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no symbol uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "mqaokne kc vdodzd";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no symbol whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "mqaoknekcvdodzd";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no symbol symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Mqaokne kcvdodzd";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed no symbol mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -180,34 +180,34 @@ public class TestBifid{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MQAOKNEKCVDODZD";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed secure lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MQAOKNEKCVDODZD";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed secure uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MQAOKNEKCVDODZD";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed secure whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MQAOKNEKCVDODZD";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed secure symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MQAOKNEKCVDODZD";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Bifid failed secure mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@@ -220,34 +220,34 @@ public class TestBifid{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MQAOKNEKCVDODZD";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "mqaokne kc vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "mqaokne*kc+vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Mqaokne kc^vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Message to^encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -259,34 +259,34 @@ public class TestBifid{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no capital lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MQAOKNEKCVDODZD";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no capital uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "mqaokne kc vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE TO ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no capital whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "mqaokne*kc+vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE*TO+ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no capital symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Mqaokne kc^vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE TO^ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no capital mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -298,34 +298,34 @@ public class TestBifid{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no whitespace lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MQAOKNEKCVDODZD";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no whitespace uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "mqaokne kc vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "mqaokne*kc+vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no whitespace symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Mqaokne kc^vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Messageto^encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no whitespace mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -337,34 +337,34 @@ public class TestBifid{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no symbol lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MQAOKNEKCVDODZD";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no symbol uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "mqaokne kc vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no symbol whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "mqaokne*kc+vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no symbol symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Mqaokne kc^vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Message toencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed no symbol mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -376,33 +376,33 @@ public class TestBifid{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed secure lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MQAOKNEKCVDODZD";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed secure uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "mqaokne kc vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed secure whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "mqaokne*kc+vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed secure symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Mqaokne kc^vdodzd";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Bifid failed secure mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//Mattrixwv/src/test/java/com/mattrixwv/CipherStreamJava/polySubstitution/TestColumnar.java
|
||||
//Mattrixwv
|
||||
// Created: 01-16-22
|
||||
//Modified: 03-03-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
@@ -24,34 +24,34 @@ public class TestColumnar{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "edxeoxmteacxgoxsnxsex";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "EDXEOXMTEACXGOXsnxsex";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "edxeoxm te acxgoxsnxsex";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message@to-encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "edxeoxm@te-acxgoxsnxsex";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to*encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Edxeoxm te*acxgoxsnxsex";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -62,34 +62,34 @@ public class TestColumnar{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "EDXEOXMTEACXGOXSNXSEX";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed no capitals lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "EDXEOXMTEACXGOXSNXSEX";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed no capitals uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "EDXEOXM TE ACXGOXSNXSEX";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed no capitals whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message@to-encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "EDXEOXM@TE-ACXGOXSNXSEX";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed no capitals symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to*encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "EDXEOXM TE*ACXGOXSNXSEX";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed no capitals mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -100,34 +100,34 @@ public class TestColumnar{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "edxeoxmteacxgoxsnxsex";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed no whitespace lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "EDXEOXMTEACXGOXsnxsex";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed no whitespace uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "edxeoxmteacxgoxsnxsex";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed no whitespace whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message@to-encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "edxeoxm@te-acxgoxsnxsex";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed no whitespace symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to*encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Edxeoxmte*acxgoxsnxsex";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed no whitespace mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -138,34 +138,34 @@ public class TestColumnar{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "edxeoxmteacxgoxsnxsex";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed no symbol lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "EDXEOXMTEACXGOXsnxsex";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed no symbol uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "edxeoxm te acxgoxsnxsex";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed no symbol whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message@to-encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "edxeoxmteacxgoxsnxsex";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed no symbol symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to*encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Edxeoxm teacxgoxsnxsex";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed no symbol mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoPaddingEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -176,34 +176,34 @@ public class TestColumnar{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "edeomteacgosnse";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed no padding lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "EDEOMTEACGOSNSE";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed no padding uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "edeomte ac gosnse";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed no padding whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message@to-encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "edeomte@ac-gosnse";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed no padding symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message To*encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Edeomte Ac*gosnse";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed no padding mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -214,34 +214,34 @@ public class TestColumnar{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "EDXEOXMTEACXGOXSNXSEX";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed secure lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "EDXEOXMTEACXGOXSNXSEX";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed secure uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "EDXEOXMTEACXGOXSNXSEX";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed secure whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message@to-encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "EDXEOXMTEACXGOXSNXSEX";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed secure symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to*encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "EDXEOXMTEACXGOXSNXSEX";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Columnar failed secure mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@@ -254,34 +254,34 @@ public class TestColumnar{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencodexxxxxx";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "EDXEOXMTEACXGOXsnxsex";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODExxxxxx";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "edxeoxm te acxgoxsnxsex";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message to encodexxxxxx";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "edxeoxm@te-acxgoxsnxsex";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message@to-encodexxxxxx";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Edxeoxm te*acxgoxsnxsex";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Message to*encodexxxxxx";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -292,34 +292,34 @@ public class TestColumnar{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MESSAGETOENCODEXXXXXX";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed no capital lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "EDXEOXMTEACXGOXsnxsex";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODEXXXXXX";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed no capital uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "edxeoxm te acxgoxsnxsex";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE TO ENCODEXXXXXX";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed no capital whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "edxeoxm@te-acxgoxsnxsex";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE@TO-ENCODEXXXXXX";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed no capital symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Edxeoxm te*acxgoxsnxsex";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE TO*ENCODEXXXXXX";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed no capital mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -330,34 +330,34 @@ public class TestColumnar{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencodexxxxxx";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed no whitespace lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "EDXEOXMTEACXGOXsnxsex";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODExxxxxx";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed no whitespace uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "edxeoxm te acxgoxsnxsex";
|
||||
keyword = "keyword";
|
||||
correctOutput = "messagetoencodexxxxxx";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "edxeoxm@te-acxgoxsnxsex";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message@to-encodexxxxxx";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed no whitespace symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Edxeoxm te*acxgoxsnxsex";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Messageto*encodexxxxxx";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed no whitespace mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -368,34 +368,34 @@ public class TestColumnar{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencodexxxxxx";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed no symbol lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "EDXEOXMTEACXGOXsnxsex";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODExxxxxx";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed no symbol uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "edxeoxm te acxgoxsnxsex";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message to encodexxxxxx";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed no symbol whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "edxeoxm@te-acxgoxsnxsex";
|
||||
keyword = "keyword";
|
||||
correctOutput = "messagetoencodexxxxxx";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed no symbol symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Edxeoxm te*acxgoxsnxsex";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Message toencodexxxxxx";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed no symbol mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoPaddingDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -406,34 +406,34 @@ public class TestColumnar{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed no padding lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "EDEOMTEACGOSNSE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed no padding uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "edeomte ac gosnse";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed no padding whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "edeomte@ac-gosnse";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message@to-encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed no padding symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Edeomte ac*gosnse";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Message to*encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed no padding mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidCharacterException, InvalidKeywordException, InvalidInputException{
|
||||
@@ -444,33 +444,33 @@ public class TestColumnar{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MESSAGETOENCODEXXXXXX";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed secure lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "EDXEOXMTEACXGOXsnxsex";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODEXXXXXX";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed secure uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "edxeoxm te acxgoxsnxsex";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODEXXXXXX";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed secure whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "edxeoxm@te-acxgoxsnxsex";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODEXXXXXX";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed secure symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Edxeoxm te*acxgoxsnxsex";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODEXXXXXX";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Columnar failed secure mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamjava/polySubstitution/TestHill.java
|
||||
//Mattrixwv
|
||||
// Created: 01-31-22
|
||||
//Modified: 02-17-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.security.InvalidKeyException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidKeyException;
|
||||
|
||||
|
||||
public class TestHill{
|
||||
@@ -25,41 +24,41 @@ public class TestHill{
|
||||
int[][] key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
String correctOutput = "mgkeqgeulikhisp";
|
||||
String output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MGKEQGEULIKHISP";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "mgkeqge ul ikhisp";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "mgkeqge*ul+ikhisp";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test padding encoding
|
||||
inputString = "messagetoencod";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "mgkeqgeulikhul";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed padding encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "Mgkeqge ul^ikhisp";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,41 +70,41 @@ public class TestHill{
|
||||
int[][] key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
String correctOutput = "MGKEQGEULIKHISP";
|
||||
String output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed no capital lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MGKEQGEULIKHISP";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed no capital uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MGKEQGE UL IKHISP";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed no capital whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MGKEQGE*UL+IKHISP";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed no capital symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test padding encoding
|
||||
inputString = "messagetoencod";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MGKEQGEULIKHUL";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed no capital padding encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MGKEQGE UL^IKHISP";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed no capital mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,41 +116,41 @@ public class TestHill{
|
||||
int[][] key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
String correctOutput = "mgkeqgeulikhisp";
|
||||
String output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed no whitespace lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MGKEQGEULIKHISP";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed no whitespace uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "mgkeqgeulikhisp";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed no whitespace whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "mgkeqge*ul+ikhisp";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed no whitespace symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test padding encoding
|
||||
inputString = "messagetoencod";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "mgkeqgeulikhul";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed no whitespace padding encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "Mgkeqgeul^ikhisp";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed no whitespace mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -163,41 +162,41 @@ public class TestHill{
|
||||
int[][] key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
String correctOutput = "mgkeqgeulikhisp";
|
||||
String output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed no symbol lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MGKEQGEULIKHISP";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed no symbol uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "mgkeqge ul ikhisp";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed no symbol whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "mgkeqgeulikhisp";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed no symbol symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test padding encoding
|
||||
inputString = "messagetoencod";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "mgkeqgeulikhul";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed no symbol padding encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "Mgkeqge ulikhisp";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed no symbol mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -209,41 +208,41 @@ public class TestHill{
|
||||
int[][] key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
String correctOutput = "mgkeqgeulikhisp";
|
||||
String output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed no padding lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MGKEQGEULIKHISP";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed no padding uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "mgkeqge ul ikhisp";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed no padding whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "mgkeqge*ul+ikhisp";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed no padding symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test padding encoding
|
||||
inputString = "messagetoencod";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "mgkeqgeulikhulb";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed no padding padding encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "Mgkeqge ul^ikhisp";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed no padding mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -255,41 +254,41 @@ public class TestHill{
|
||||
int[][] key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
String correctOutput = "MGKEQGEULIKHISP";
|
||||
String output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed secure lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MGKEQGEULIKHISP";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed secure uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MGKEQGEULIKHISP";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed secure whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MGKEQGEULIKHISP";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed secure symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test padding encoding
|
||||
inputString = "messagetoencod";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MGKEQGEULIKHULB";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed secure padding encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MGKEQGEULIKHISP";
|
||||
output = cipher.encode(key, inputString);
|
||||
assertEquals("Hill failed secure mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@@ -302,34 +301,34 @@ public class TestHill{
|
||||
int[][] key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MGKEQGEULIKHISP";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "mgkeqge ul ikhisp";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "mgkeqge*ul+ikhisp";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "Mgkeqge ul^ikhisp";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "Message to^encode";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -341,34 +340,34 @@ public class TestHill{
|
||||
int[][] key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed no capital lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MGKEQGEULIKHISP";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed no capital uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "mgkeqge ul ikhisp";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MESSAGE TO ENCODE";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed no capital whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "mgkeqge*ul+ikhisp";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MESSAGE*TO+ENCODE";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed no capital symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "Mgkeqge ul^ikhisp";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MESSAGE TO^ENCODE";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed no capital mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -380,34 +379,34 @@ public class TestHill{
|
||||
int[][] key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed no whitespace lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MGKEQGEULIKHISP";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed no whitespace uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "mgkeqge ul ikhisp";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "mgkeqge*ul+ikhisp";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed no whitespace symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "Mgkeqge ul^ikhisp";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "Messageto^encode";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed no whitespace mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -419,34 +418,34 @@ public class TestHill{
|
||||
int[][] key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed no symbol lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MGKEQGEULIKHISP";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed no symbol uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "mgkeqge ul ikhisp";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed no symbol whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "mgkeqge*ul+ikhisp";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed no symbol symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "Mgkeqge ul^ikhisp";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "Message toencode";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed no symbol mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -458,34 +457,34 @@ public class TestHill{
|
||||
int[][] key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed no padding lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MGKEQGEULIKHISP";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed no padding uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "mgkeqge ul ikhisp";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed no padding whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "mgkeqge*ul+ikhisp";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed no padding symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "Mgkeqge ul^ikhisp";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "Message to^encode";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed no padding mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -497,33 +496,33 @@ public class TestHill{
|
||||
int[][] key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed secure lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MGKEQGEULIKHISP";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed secure uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "mgkeqge ul ikhisp";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed secure whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "mgkeqge*ul+ikhisp";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed secure symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "Mgkeqge ul^ikhisp";
|
||||
key = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(key, inputString);
|
||||
assertEquals("Hill failed secure mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/TestMorse.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-28-21
|
||||
//Modified: 01-04-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
public class TestMorse{
|
||||
@@ -19,19 +19,19 @@ public class TestMorse{
|
||||
String input = "sos";
|
||||
String correctOutput = "... --- ...";
|
||||
String output = cipher.encode(input);
|
||||
assertEquals("Morse Encoding failed the first test", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test 2
|
||||
input = "MORSE, CODE";
|
||||
correctOutput = "-- --- .-. ... . -.-. --- -.. .";
|
||||
output = cipher.encode(input);
|
||||
assertEquals("Morse Encoding failed the second test", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test 3
|
||||
input = "1.23 987";
|
||||
correctOutput = ".---- ..--- ...-- ----. ---.. --...";
|
||||
output = cipher.encode(input);
|
||||
assertEquals("Morse Encoding failed the third test", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testDecode(){
|
||||
@@ -41,18 +41,18 @@ public class TestMorse{
|
||||
String input = "... --- ...";
|
||||
String correctOutput = "SOS";
|
||||
String output = cipher.decode(input);
|
||||
assertEquals("Morse Decoding failed the first test", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test 2
|
||||
input = "-- --- .-. ... . -.-. --- -.. .";
|
||||
correctOutput = "MORSECODE";
|
||||
output = cipher.decode(input);
|
||||
assertEquals("Morse Decoding failed the second test", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test 3
|
||||
input = ".---- ..--- ...-- ----. ---.. --...";
|
||||
correctOutput = "123987";
|
||||
output = cipher.decode(input);
|
||||
assertEquals("Morse Decoding failed the third test", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/TestPlayfair.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-30-21
|
||||
//Modified: 01-04-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
@@ -23,46 +23,46 @@ public class TestPlayfair{
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "bmodzbxdnabekudmuixMmouvif";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "HIDETHEGOLDINTHETREESTUMP";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test odd letter count encoding
|
||||
inputString = "hidethegoldinthetrexestum";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmodzbxdnabekudmuixmmouviM";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed odd letter count encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "hide the gold in the tree stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmod zbx dnab ek udm uixMm ouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "hidethegoldin-the@tree+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmodzbxdnabek-udm@uixMm+ouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "Bmod zbx dnab ek - udm@uixMm+ouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol encoding with mangled keyword
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "Bmod zbx dnab ek - udm@uixMm+ouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceEncode() throws InvalidCharacterException, InvalidInputException{
|
||||
@@ -73,46 +73,46 @@ public class TestPlayfair{
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "bmodzbxdnabekudmuixMmouvif";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "HIDETHEGOLDINTHETREESTUMP";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test odd letter count encoding
|
||||
inputString = "hidethegoldinthetreestum";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmodzbxdnabekudmuixMmouviM";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace odd letter count encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "hide the gold in the tree stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmodzbxdnabekudmuixMmouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "hidethegoldin-the@tree+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmodzbxdnabek-udm@uixMm+ouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "Bmodzbxdnabek-udm@uixMm+ouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol encoding with mangled keyword
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "Bmodzbxdnabek-udm@uixMm+ouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalEncode() throws InvalidCharacterException, InvalidInputException{
|
||||
@@ -123,46 +123,46 @@ public class TestPlayfair{
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "HIDETHEGOLDINTHETREESTUMP";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test odd letter count encoding
|
||||
inputString = "hidethegoldinthetreestum";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIM";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital odd letter count encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "hide the gold in the tree stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMOD ZBX DNAB EK UDM UIXMM OUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "hidethegoldin-the@tree+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEK-UDM@UIXMM+OUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMOD ZBX DNAB EK - UDM@UIXMM+OUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol encoding with mangled keyword
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "BMOD ZBX DNAB EK - UDM@UIXMM+OUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolEncode() throws InvalidCharacterException, InvalidInputException{
|
||||
@@ -173,46 +173,46 @@ public class TestPlayfair{
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "bmodzbxdnabekudmuixMmouvif";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "HIDETHEGOLDINTHETREESTUMP";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test odd letter count encoding
|
||||
inputString = "hidethegoldinthetreestum";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmodzbxdnabekudmuixMmouviM";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol odd letter count encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "hide the gold in the tree stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmod zbx dnab ek udm uixMm ouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "hidethegoldin-the@tree+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmodzbxdnabekudmuixMmouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "Bmod zbx dnab ek udmuixMmouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol encoding with mangled keyword
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "Bmod zbx dnab ek udmuixMmouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidCharacterException, InvalidInputException{
|
||||
@@ -223,46 +223,46 @@ public class TestPlayfair{
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "HIDETHEGOLDINTHETREESTUMP";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test odd letter count encoding
|
||||
inputString = "hidethegoldinthetreestum";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIM";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure odd letter count encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "hide the gold in the tree stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "hidethegoldin-the@tree+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol encoding with mangled keyword
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testDecode() throws InvalidCharacterException, InvalidInputException{
|
||||
@@ -273,46 +273,46 @@ public class TestPlayfair{
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "hidethegoldinthetrexestump";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test odd letter count decoding
|
||||
inputString = "bmodzbxdnabekudmuixmmouvim";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hidethegoldinthetrexestumx";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed odd letter count decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "bmod zbx dnab ek udm uixmm ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hide the gold in the trexe stump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "bmodzbxdnabek-udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hidethegoldin-the@trexe+stump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "Hide the gold in - the@trexe+stump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whtiespace, symbol decoding with mangled keyword
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "Hide the gold in - the@trexe+stump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceDecode() throws InvalidCharacterException, InvalidInputException{
|
||||
@@ -323,46 +323,46 @@ public class TestPlayfair{
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "hidethegoldinthetrexestump";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test odd letter count decoding
|
||||
inputString = "bmodzbxdnabekudmuixmmouvim";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hidethegoldinthetrexestumx";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace odd letter count decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "bmodzbxdnabekudmuixmmouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hidethegoldinthetrexestump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "bmodzbxdnabek-udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hidethegoldin-the@trexe+stump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whtiespace, symbol decoding
|
||||
inputString = "Bmodzbxdnabek-udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "Hidethegoldin-the@trexe+stump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whtiespace, symbol decoding with mangled keyword
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "Hidethegoldin-the@trexe+stump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalDecode() throws InvalidCharacterException, InvalidInputException{
|
||||
@@ -373,46 +373,46 @@ public class TestPlayfair{
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test odd letter count decoding
|
||||
inputString = "bmodzbxdnabekudmuixmmouvim";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMX";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital odd letter count decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "bmod zbx dnab ek udm uixmm ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDE THE GOLD IN THE TREXE STUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "bmodzbxdnabek-udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDIN-THE@TREXE+STUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whtiespace, symbol decoding
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDE THE GOLD IN - THE@TREXE+STUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whtiespace, symbol decoding with mangled keyword
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "HIDE THE GOLD IN - THE@TREXE+STUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolDecode() throws InvalidCharacterException, InvalidInputException{
|
||||
@@ -423,46 +423,46 @@ public class TestPlayfair{
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "hidethegoldinthetrexestump";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test odd letter count decoding
|
||||
inputString = "bmodzbxdnabekudmuixmmouvim";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hidethegoldinthetrexestumx";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol odd letter count decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "bmod zbx dnab ek udm uixmm ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hide the gold in the trexe stump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "bmodzbxdnabek-udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hidethegoldinthetrexestump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whtiespace, symbol decoding
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "Hide the gold in thetrexestump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whtiespace, symbol decoding with mangled keyword
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "Hide the gold in thetrexestump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidCharacterException, InvalidInputException{
|
||||
@@ -473,45 +473,45 @@ public class TestPlayfair{
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test odd letter count decoding
|
||||
inputString = "bmodzbxdnabekudmuixmmouvim";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMX";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure odd letter count decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "bmod zbx dnab ek udm uixmm ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "bmodzbxdnabek-udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whtiespace, symbol decoding
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test mixed case, whtiespace, symbol decoding with mangled keyword
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/TestPolybiusSquare.java
|
||||
//Mattrixwv
|
||||
// Created: 01-04-22
|
||||
//Modified: 01-09-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
@@ -23,34 +23,34 @@ public class TestPolybiusSquare{
|
||||
String keyword = "";
|
||||
String correctOutput = "121144";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed simple encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "B A T";
|
||||
keyword = "";
|
||||
correctOutput = "12 11 44";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "B@A+T-";
|
||||
keyword = "";
|
||||
correctOutput = "12@11+44-";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace, symbol decoding
|
||||
inputString = "B A-T";
|
||||
keyword = "";
|
||||
correctOutput = "12 11-44";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test whitespace, symbol decoding with mangled keyword
|
||||
inputString = "B A-T";
|
||||
keyword = "Z Y+ X-";
|
||||
correctOutput = "15 14-52";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceEncode() throws InvalidCharacterException, InvalidInputException{
|
||||
@@ -61,34 +61,34 @@ public class TestPolybiusSquare{
|
||||
String keyword = "";
|
||||
String correctOutput = "121144";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no whitespace simple encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "B A T";
|
||||
keyword = "";
|
||||
correctOutput = "121144";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no whitespace whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "B@A+T-";
|
||||
keyword = "";
|
||||
correctOutput = "12@11+44-";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no whitespace symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace, symbol decoding
|
||||
inputString = "B A-T";
|
||||
keyword = "";
|
||||
correctOutput = "1211-44";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no whitespace whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test whitespace, symbol decoding with mangled keyword
|
||||
inputString = "B A-T";
|
||||
keyword = "Z Y+ X-";
|
||||
correctOutput = "1514-52";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no whitespace whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolEncode() throws InvalidCharacterException, InvalidInputException{
|
||||
@@ -99,34 +99,34 @@ public class TestPolybiusSquare{
|
||||
String keyword = "";
|
||||
String correctOutput = "121144";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no symbol simple encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "B A T";
|
||||
keyword = "";
|
||||
correctOutput = "12 11 44";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no symbol whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "B@A+T-";
|
||||
keyword = "";
|
||||
correctOutput = "121144";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no symbol symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace, symbol decoding
|
||||
inputString = "B A-T";
|
||||
keyword = "";
|
||||
correctOutput = "12 1144";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test whitespace, symbol decoding with mangled keyword
|
||||
inputString = "B A-T";
|
||||
keyword = "Z Y+ X-";
|
||||
correctOutput = "15 1452";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no symbol whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceSymbolEncode() throws InvalidCharacterException, InvalidInputException{
|
||||
@@ -137,13 +137,13 @@ public class TestPolybiusSquare{
|
||||
String keyword = "";
|
||||
String correctOutput = "12 11 44";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed secure simple encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "B A T";
|
||||
keyword = "";
|
||||
correctOutput = "12 11 44";
|
||||
assertEquals("PolybiusSquare failed secure whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
output = cipher.encode(keyword, inputString);
|
||||
|
||||
//Test symbol encoding
|
||||
@@ -151,20 +151,20 @@ public class TestPolybiusSquare{
|
||||
keyword = "";
|
||||
correctOutput = "12 11 44";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed secure symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace, symbol decoding
|
||||
inputString = "B A-T";
|
||||
keyword = "";
|
||||
correctOutput = "12 11 44";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed secure whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test whitespace, symbol decoding with mangled keyword
|
||||
inputString = "B A-T";
|
||||
keyword = "Z Y+ X-";
|
||||
correctOutput = "15 14 52";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed secure whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testDecode() throws InvalidCharacterException, InvalidInputException{
|
||||
@@ -175,34 +175,34 @@ public class TestPolybiusSquare{
|
||||
String keyword = "";
|
||||
String correctOutput = "BAT";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed simple decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "12 11 44";
|
||||
keyword = "";
|
||||
correctOutput = "B A T";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "12@11+44-";
|
||||
keyword = "";
|
||||
correctOutput = "B@A+T-";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace, symbol decoding
|
||||
inputString = "12 11-44";
|
||||
keyword = "";
|
||||
correctOutput = "B A-T";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test whitespace, symbol decoding with mangled keyword
|
||||
inputString = "15 14-52";
|
||||
keyword = "Z Y+ X-";
|
||||
correctOutput = "B A-T";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceDecode() throws InvalidCharacterException, InvalidInputException{
|
||||
@@ -213,34 +213,34 @@ public class TestPolybiusSquare{
|
||||
String keyword = "";
|
||||
String correctOutput = "BAT";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no whitespace simple decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "12 11 44";
|
||||
keyword = "";
|
||||
correctOutput = "BAT";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "12@11+44-";
|
||||
keyword = "";
|
||||
correctOutput = "B@A+T-";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no whitespace symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace, symbol decoding
|
||||
inputString = "12 11-44";
|
||||
keyword = "";
|
||||
correctOutput = "BA-T";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no whitespace whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test whitespace, symbol decoding with mangled keyword
|
||||
inputString = "15 14-52";
|
||||
keyword = "Z Y+ X-";
|
||||
correctOutput = "BA-T";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no whitespace whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolDeocde() throws InvalidCharacterException, InvalidInputException{
|
||||
@@ -251,34 +251,34 @@ public class TestPolybiusSquare{
|
||||
String keyword = "";
|
||||
String correctOutput = "BAT";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no symbol simple decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "12 11 44";
|
||||
keyword = "";
|
||||
correctOutput = "B A T";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no symbol whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "12@11+44-";
|
||||
keyword = "";
|
||||
correctOutput = "BAT";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no symbol symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace, symbol decoding
|
||||
inputString = "12 11-44";
|
||||
keyword = "";
|
||||
correctOutput = "B AT";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no symbol whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test whitespace, symbol decoding with mangled keyword
|
||||
inputString = "15 14-52";
|
||||
keyword = "Z Y+ X-";
|
||||
correctOutput = "B AT";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no symbol whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceSymbolDecode() throws InvalidCharacterException, InvalidInputException{
|
||||
@@ -289,33 +289,33 @@ public class TestPolybiusSquare{
|
||||
String keyword = "";
|
||||
String correctOutput = "BAT";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed secure simple decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "12 11 44";
|
||||
keyword = "";
|
||||
correctOutput = "BAT";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed secure whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "12@11+44-";
|
||||
keyword = "";
|
||||
correctOutput = "BAT";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed secure symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace, symbol decoding
|
||||
inputString = "12 11-44";
|
||||
keyword = "";
|
||||
correctOutput = "BAT";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed secure whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test whitespace, symbol decoding with mangled keyword
|
||||
inputString = "15 14-52";
|
||||
keyword = "Z Y+ X-";
|
||||
correctOutput = "BAT";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed secure whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/polySubstitution/TestRailFence.java
|
||||
//Mattrixwv
|
||||
// Created: 03-21-22
|
||||
//Modified: 03-22-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidBaseException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
@@ -23,47 +23,47 @@ public class TestRailFence{
|
||||
int numRails = 3;
|
||||
String correctOutput = "maooesgtecdsene";
|
||||
String output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
numRails = 3;
|
||||
correctOutput = "MAOOESGTECDSENE";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test rail length encoding
|
||||
inputString = "messagetoencode";
|
||||
numRails = 5;
|
||||
correctOutput = "moetesenesgcdao";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed rail length encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
numRails = 3;
|
||||
correctOutput = "maooesg te cdsene";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
numRails = 3;
|
||||
correctOutput = "maooesg*te+cdsene";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
numRails = 3;
|
||||
correctOutput = "Maooesg te^cdsene";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed mixedCase, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in rail length for good measure
|
||||
inputString = "Message to^encode";
|
||||
numRails = 5;
|
||||
correctOutput = "Moetese ne^sgcdao";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed mixedCase, whitespace, symbol, railLength encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,47 +75,47 @@ public class TestRailFence{
|
||||
int numRails = 3;
|
||||
String correctOutput = "MAOOESGTECDSENE";
|
||||
String output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed no capital lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
numRails = 3;
|
||||
correctOutput = "MAOOESGTECDSENE";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed no capital uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test rail length encoding
|
||||
inputString = "messagetoencode";
|
||||
numRails = 5;
|
||||
correctOutput = "MOETESENESGCDAO";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed no capital rail length encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
numRails = 3;
|
||||
correctOutput = "MAOOESG TE CDSENE";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed no capital whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
numRails = 3;
|
||||
correctOutput = "MAOOESG*TE+CDSENE";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed no capital symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
numRails = 3;
|
||||
correctOutput = "MAOOESG TE^CDSENE";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed no capital mixedCase, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in rail length for good measure
|
||||
inputString = "Message to^encode";
|
||||
numRails = 5;
|
||||
correctOutput = "MOETESE NE^SGCDAO";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed no capital mixedCase, whitespace, symbol, railLength encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -127,47 +127,47 @@ public class TestRailFence{
|
||||
int numRails = 3;
|
||||
String correctOutput = "maooesgtecdsene";
|
||||
String output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed no whitespace lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
numRails = 3;
|
||||
correctOutput = "MAOOESGTECDSENE";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed no whitespace uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test rail length encoding
|
||||
inputString = "messagetoencode";
|
||||
numRails = 5;
|
||||
correctOutput = "moetesenesgcdao";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed no whitespace rail length encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
numRails = 3;
|
||||
correctOutput = "maooesgtecdsene";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed no whitespace whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
numRails = 3;
|
||||
correctOutput = "maooesg*te+cdsene";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed no whitespace symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
numRails = 3;
|
||||
correctOutput = "Maooesgte^cdsene";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed no whitespace mixedCase, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in rail length for good measure
|
||||
inputString = "Message to^encode";
|
||||
numRails = 5;
|
||||
correctOutput = "Moetesene^sgcdao";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed no whitespace mixedCase, whitespace, symbol, railLength encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -179,47 +179,47 @@ public class TestRailFence{
|
||||
int numRails = 3;
|
||||
String correctOutput = "maooesgtecdsene";
|
||||
String output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed no symbol lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
numRails = 3;
|
||||
correctOutput = "MAOOESGTECDSENE";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed no symbol uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test rail length encoding
|
||||
inputString = "messagetoencode";
|
||||
numRails = 5;
|
||||
correctOutput = "moetesenesgcdao";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed no symbol rail length encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
numRails = 3;
|
||||
correctOutput = "maooesg te cdsene";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed no symbol whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
numRails = 3;
|
||||
correctOutput = "maooesgtecdsene";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed no symbol symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
numRails = 3;
|
||||
correctOutput = "Maooesg tecdsene";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed no symbol mixedCase, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in rail length for good measure
|
||||
inputString = "Message to^encode";
|
||||
numRails = 5;
|
||||
correctOutput = "Moetese nesgcdao";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed no symbol mixedCase, whitespace, symbol, railLength encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -231,47 +231,47 @@ public class TestRailFence{
|
||||
int numRails = 3;
|
||||
String correctOutput = "MAOOESGTECDSENE";
|
||||
String output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed secure lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
numRails = 3;
|
||||
correctOutput = "MAOOESGTECDSENE";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed secure uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test rail length encoding
|
||||
inputString = "messagetoencode";
|
||||
numRails = 5;
|
||||
correctOutput = "MOETESENESGCDAO";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed secure rail length encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
numRails = 3;
|
||||
correctOutput = "MAOOESGTECDSENE";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed secure whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to+encode";
|
||||
numRails = 3;
|
||||
correctOutput = "MAOOESGTECDSENE";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed secure symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
numRails = 3;
|
||||
correctOutput = "MAOOESGTECDSENE";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed secure mixedCase, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in rail length for good measure
|
||||
inputString = "Message to^encode";
|
||||
numRails = 5;
|
||||
correctOutput = "MOETESENESGCDAO";
|
||||
output = cipher.encode(numRails, inputString);
|
||||
assertEquals("RailFence failed secure mixedCase, whitespace, symbol, railLength encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@@ -284,47 +284,47 @@ public class TestRailFence{
|
||||
int numRails = 3;
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MAOOESGTECDSENE";
|
||||
numRails = 3;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test rail length decoding
|
||||
inputString = "moetesenesgcdao";
|
||||
numRails = 5;
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed rail length decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "maooesg te cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "maooesg*te+cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Maooesg te^cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "Message to^encode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed mixedCase, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in rail length for good measure
|
||||
inputString = "Moetese ne^sgcdao";
|
||||
numRails = 5;
|
||||
correctOutput = "Message to^encode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed mixedCase, whitespace, symbol, railLength decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -336,47 +336,47 @@ public class TestRailFence{
|
||||
int numRails = 3;
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed no capital lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MAOOESGTECDSENE";
|
||||
numRails = 3;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed no capital uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test rail length decoding
|
||||
inputString = "moetesenesgcdao";
|
||||
numRails = 5;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed no capital rail length decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "maooesg te cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "MESSAGE TO ENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed no capital whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "maooesg*te+cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "MESSAGE*TO+ENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed no capital symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Maooesg te^cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "MESSAGE TO^ENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed no capital mixedCase, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in rail length for good measure
|
||||
inputString = "Moetese ne^sgcdao";
|
||||
numRails = 5;
|
||||
correctOutput = "MESSAGE TO^ENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed no capital mixedCase, whitespace, symbol, railLength decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -388,47 +388,47 @@ public class TestRailFence{
|
||||
int numRails = 3;
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed no whitespace lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MAOOESGTECDSENE";
|
||||
numRails = 3;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed no whitespace uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test rail length decoding
|
||||
inputString = "moetesenesgcdao";
|
||||
numRails = 5;
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed no whitespace rail length decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "maooesg te cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "maooesg*te+cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "message*to+encode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed no whitespace symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Maooesg te^cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "Messageto^encode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed no whitespace mixedCase, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in rail length for good measure
|
||||
inputString = "Moetese ne^sgcdao";
|
||||
numRails = 5;
|
||||
correctOutput = "Messageto^encode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed no whitespace mixedCase, whitespace, symbol, railLength decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -440,47 +440,47 @@ public class TestRailFence{
|
||||
int numRails = 3;
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed no symbol lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MAOOESGTECDSENE";
|
||||
numRails = 3;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed no symbol uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test rail length decoding
|
||||
inputString = "moetesenesgcdao";
|
||||
numRails = 5;
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed no symbol rail length decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "maooesg te cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed no symbol whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "maooesg*te+cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed no symbol symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Maooesg te^cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "Message toencode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed no symbol mixedCase, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in rail length for good measure
|
||||
inputString = "Moetese ne^sgcdao";
|
||||
numRails = 5;
|
||||
correctOutput = "Message toencode";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed no symbol mixedCase, whitespace, symbol, railLength decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -492,46 +492,46 @@ public class TestRailFence{
|
||||
int numRails = 3;
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed secure lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "MAOOESGTECDSENE";
|
||||
numRails = 3;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed secure uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test rail length decoding
|
||||
inputString = "moetesenesgcdao";
|
||||
numRails = 5;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed secure rail length decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "maooesg te cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed secure whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "maooesg*te+cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed secure symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Maooesg te^cdsene";
|
||||
numRails = 3;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed secure mixedCase, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in rail length for good measure
|
||||
inputString = "Moetese ne^sgcdao";
|
||||
numRails = 5;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(numRails, inputString);
|
||||
assertEquals("RailFence failed secure mixedCase, whitespace, symbol, railLength decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/polySubstitution/TestTrifid.java
|
||||
//Mattrixwv
|
||||
// Created: 03-03-22
|
||||
//Modified: 03-03-22
|
||||
//Modified: 07-09-22
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidBaseException;
|
||||
import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
|
||||
@@ -25,13 +25,13 @@ public class TestTrifid{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "gqdokpdodljvflf";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Trifid failed lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "GQDOKPDODLJVFLF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Trifid failed uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test groupLength encoding
|
||||
inputString = "messagetoencode";
|
||||
@@ -39,35 +39,35 @@ public class TestTrifid{
|
||||
int groupLength = 3;
|
||||
correctOutput = "gpjqdvdofodlklf";
|
||||
output = cipher.encode(keyword, groupLength, inputString);
|
||||
assertEquals("Trifid failed groupLength encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "gqdokpd od ljvflf";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Trifid failed whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to-encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "gqdokpd*od-ljvflf";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Trifid failed symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Gqdokpd od^ljvflf";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Trifid failed mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in groupLength for good measure
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
groupLength = 3;
|
||||
correctOutput = "Gpjqdvd of^odlklf";
|
||||
output = cipher.encode(keyword, groupLength, inputString);
|
||||
assertEquals("Trifid failed mixed case, whitespace, symbol, groupLength encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,13 +79,13 @@ public class TestTrifid{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "GQDOKPDODLJVFLF";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Trifid failed no capital lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "GQDOKPDODLJVFLF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Trifid failed no capital uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test groupLength encoding
|
||||
inputString = "messagetoencode";
|
||||
@@ -93,35 +93,35 @@ public class TestTrifid{
|
||||
int groupLength = 3;
|
||||
correctOutput = "GPJQDVDOFODLKLF";
|
||||
output = cipher.encode(keyword, groupLength, inputString);
|
||||
assertEquals("Trifid failed no capital groupLength encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "GQDOKPD OD LJVFLF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Trifid failed no capital whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to-encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "GQDOKPD*OD-LJVFLF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Trifid failed no capital symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "GQDOKPD OD^LJVFLF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Trifid failed no capital mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in groupLength for good measure
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
groupLength = 3;
|
||||
correctOutput = "GPJQDVD OF^ODLKLF";
|
||||
output = cipher.encode(keyword, groupLength, inputString);
|
||||
assertEquals("Trifid failed no capital mixed case, whitespace, symbol, groupLength encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -133,13 +133,13 @@ public class TestTrifid{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "gqdokpdodljvflf";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Trifid failed no whitespace lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "GQDOKPDODLJVFLF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Trifid failed no whitespace uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test groupLength encoding
|
||||
inputString = "messagetoencode";
|
||||
@@ -147,35 +147,35 @@ public class TestTrifid{
|
||||
int groupLength = 3;
|
||||
correctOutput = "gpjqdvdofodlklf";
|
||||
output = cipher.encode(keyword, groupLength, inputString);
|
||||
assertEquals("Trifid failed no whitespace groupLength encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "gqdokpdodljvflf";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Trifid failed no whitespace whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to-encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "gqdokpd*od-ljvflf";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Trifid failed no whitespace symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Gqdokpdod^ljvflf";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Trifid failed no whitespace mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in groupLength for good measure
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
groupLength = 3;
|
||||
correctOutput = "Gpjqdvdof^odlklf";
|
||||
output = cipher.encode(keyword, groupLength, inputString);
|
||||
assertEquals("Trifid failed no whitespace mixed case, whitespace, symbol, groupLength encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -187,13 +187,13 @@ public class TestTrifid{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "gqdokpdodljvflf";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Trifid failed no symbol lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "GQDOKPDODLJVFLF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Trifid failed no symbol uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test groupLength encoding
|
||||
inputString = "messagetoencode";
|
||||
@@ -201,35 +201,35 @@ public class TestTrifid{
|
||||
int groupLength = 3;
|
||||
correctOutput = "gpjqdvdofodlklf";
|
||||
output = cipher.encode(keyword, groupLength, inputString);
|
||||
assertEquals("Trifid failed no symbol groupLength encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "gqdokpd od ljvflf";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Trifid failed no symbol whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to-encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "gqdokpdodljvflf";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Trifid failed no symbol symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Gqdokpd odljvflf";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Trifid failed no symbol mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in groupLength for good measure
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
groupLength = 3;
|
||||
correctOutput = "Gpjqdvd ofodlklf";
|
||||
output = cipher.encode(keyword, groupLength, inputString);
|
||||
assertEquals("Trifid failed no symbol mixed case, whitespace, symbol, groupLength encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -241,13 +241,13 @@ public class TestTrifid{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "GQDOKPDODLJVFLF";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Trifid failed secure lowercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "MESSAGETOENCODE";
|
||||
keyword = "keyword";
|
||||
correctOutput = "GQDOKPDODLJVFLF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Trifid failed secure uppercase encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test groupLength encoding
|
||||
inputString = "messagetoencode";
|
||||
@@ -255,35 +255,35 @@ public class TestTrifid{
|
||||
int groupLength = 3;
|
||||
correctOutput = "GPJQDVDOFODLKLF";
|
||||
output = cipher.encode(keyword, groupLength, inputString);
|
||||
assertEquals("Trifid failed secure groupLength encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "message to encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "GQDOKPDODLJVFLF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Trifid failed secure whitespace encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "message*to-encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "GQDOKPDODLJVFLF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Trifid failed secure symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
correctOutput = "GQDOKPDODLJVFLF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Trifid failed secure mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in groupLength for good measure
|
||||
inputString = "Message to^encode";
|
||||
keyword = "keyword";
|
||||
groupLength = 3;
|
||||
correctOutput = "GPJQDVDOFODLKLF";
|
||||
output = cipher.encode(keyword, groupLength, inputString);
|
||||
assertEquals("Trifid failed secure mixed case, whitespace, symbol, groupLength encoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@@ -296,13 +296,13 @@ public class TestTrifid{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Trifid failed lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "GQDOKPDODLJVFLF";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Trifid failed uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test groupLength decoding
|
||||
inputString = "gpjqdvdofodlklf";
|
||||
@@ -310,35 +310,35 @@ public class TestTrifid{
|
||||
int groupLength = 3;
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(keyword, groupLength, inputString);
|
||||
assertEquals("Trifid failed groupLength decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "gqdokpd od ljvflf";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Trifid failed whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "gqdokpd*od-ljvflf";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message*to-encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Trifid failed symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Gqdokpd od^ljvflf";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Message to^encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Trifid failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in groupLength for good measure
|
||||
inputString = "Gpjqdvd of^odlklf";
|
||||
keyword = "keyword";
|
||||
groupLength = 3;
|
||||
correctOutput = "Message to^encode";
|
||||
output = cipher.decode(keyword, groupLength, inputString);
|
||||
assertEquals("Trifid failed mixed case, whitespace, symbol, groupLength decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -350,13 +350,13 @@ public class TestTrifid{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Trifid failed no capital lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "GQDOKPDODLJVFLF";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Trifid failed no capital uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test groupLength decoding
|
||||
inputString = "gpjqdvdofodlklf";
|
||||
@@ -364,35 +364,35 @@ public class TestTrifid{
|
||||
int groupLength = 3;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, groupLength, inputString);
|
||||
assertEquals("Trifid failed no capital groupLength decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "gqdokpd od ljvflf";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE TO ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Trifid failed no capital whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "gqdokpd*od-ljvflf";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE*TO-ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Trifid failed no capital symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Gqdokpd od^ljvflf";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGE TO^ENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Trifid failed no capital mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in groupLength for good measure
|
||||
inputString = "Gpjqdvd of^odlklf";
|
||||
keyword = "keyword";
|
||||
groupLength = 3;
|
||||
correctOutput = "MESSAGE TO^ENCODE";
|
||||
output = cipher.decode(keyword, groupLength, inputString);
|
||||
assertEquals("Trifid failed no capital mixed case, whitespace, symbol, groupLength decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -404,13 +404,13 @@ public class TestTrifid{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Trifid failed no whitespace lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "GQDOKPDODLJVFLF";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Trifid failed no whitespace uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test groupLength decoding
|
||||
inputString = "gpjqdvdofodlklf";
|
||||
@@ -418,35 +418,35 @@ public class TestTrifid{
|
||||
int groupLength = 3;
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(keyword, groupLength, inputString);
|
||||
assertEquals("Trifid failed no whitespace groupLength decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "gqdokpd od ljvflf";
|
||||
keyword = "keyword";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Trifid failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "gqdokpd*od-ljvflf";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message*to-encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Trifid failed no whitespace symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Gqdokpd od^ljvflf";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Messageto^encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Trifid failed no whitespace mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in groupLength for good measure
|
||||
inputString = "Gpjqdvd of^odlklf";
|
||||
keyword = "keyword";
|
||||
groupLength = 3;
|
||||
correctOutput = "Messageto^encode";
|
||||
output = cipher.decode(keyword, groupLength, inputString);
|
||||
assertEquals("Trifid failed no whitespace mixed case, whitespace, symbol, groupLength decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -458,13 +458,13 @@ public class TestTrifid{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Trifid failed no symbol lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "GQDOKPDODLJVFLF";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Trifid failed no symbol uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test groupLength decoding
|
||||
inputString = "gpjqdvdofodlklf";
|
||||
@@ -472,35 +472,35 @@ public class TestTrifid{
|
||||
int groupLength = 3;
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(keyword, groupLength, inputString);
|
||||
assertEquals("Trifid failed no symbol groupLength decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "gqdokpd od ljvflf";
|
||||
keyword = "keyword";
|
||||
correctOutput = "message to encode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Trifid failed no symbol whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "gqdokpd*od-ljvflf";
|
||||
keyword = "keyword";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Trifid failed no symbol symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Gqdokpd od^ljvflf";
|
||||
keyword = "keyword";
|
||||
correctOutput = "Message toencode";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Trifid failed no symbol mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in groupLength for good measure
|
||||
inputString = "Gpjqdvd of^odlklf";
|
||||
keyword = "keyword";
|
||||
groupLength = 3;
|
||||
correctOutput = "Message toencode";
|
||||
output = cipher.decode(keyword, groupLength, inputString);
|
||||
assertEquals("Trifid failed no symbol mixed case, whitespace, symbol, groupLength decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -512,13 +512,13 @@ public class TestTrifid{
|
||||
String keyword = "keyword";
|
||||
String correctOutput = "MESSAGETOENCODE";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Trifid failed secure lowercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "GQDOKPDODLJVFLF";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Trifid failed secure uppercase decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test groupLength decoding
|
||||
inputString = "gpjqdvdofodlklf";
|
||||
@@ -526,34 +526,34 @@ public class TestTrifid{
|
||||
int groupLength = 3;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, groupLength, inputString);
|
||||
assertEquals("Trifid failed secure groupLength decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "gqdokpd od ljvflf";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Trifid failed secure whitespace decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "gqdokpd*od-ljvflf";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Trifid failed secure symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Gqdokpd od^ljvflf";
|
||||
keyword = "keyword";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Trifid failed secure mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
//Throw in groupLength for good measure
|
||||
inputString = "Gpjqdvd of^odlklf";
|
||||
keyword = "keyword";
|
||||
groupLength = 3;
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(keyword, groupLength, inputString);
|
||||
assertEquals("Trifid failed secure mixed case, whitespace, symbol, groupLength decoding.", correctOutput, output);
|
||||
assertEquals(correctOutput, output);
|
||||
}
|
||||
}
|
||||
|
||||
17
version-rules.xml
Normal file
17
version-rules.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ruleset xmlns="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" comparisonMethod="maven"
|
||||
xsi:schemaLocation="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0 https://www.mojohaus.org/versions-maven-plugin/xsd/rule-2.0.0.xsd">
|
||||
<ignoreVersions>
|
||||
<!-- Ignore Alpha's, Beta's, release candidates and milestones -->
|
||||
<ignoreVersion type="regex">(?i).*Alpha(?:-?\d+)?</ignoreVersion>
|
||||
<ignoreVersion type="regex">(?i).*a(?:-?\d+)?</ignoreVersion>
|
||||
<ignoreVersion type="regex">(?i).*Beta(?:-?\d+)?</ignoreVersion>
|
||||
<ignoreVersion type="regex">(?i).*-B(?:-?\d+)?</ignoreVersion>
|
||||
<ignoreVersion type="regex">(?i).*RC(?:-?\d+)?</ignoreVersion>
|
||||
<ignoreVersion type="regex">(?i).*CR(?:-?\d+)?</ignoreVersion>
|
||||
<ignoreVersion type="regex">(?i).*M(?:-?\d+)?</ignoreVersion>
|
||||
</ignoreVersions>
|
||||
<rules>
|
||||
</rules>
|
||||
</ruleset>
|
||||
Reference in New Issue
Block a user