Added exceptions
This commit is contained in:
@@ -4,11 +4,12 @@
|
|||||||
//Modified: 01-16-22
|
//Modified: 01-16-22
|
||||||
package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
||||||
|
|
||||||
|
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
|
||||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidKeywordException;
|
import com.mattrixwv.CipherStreamJava.exceptions.InvalidKeywordException;
|
||||||
|
|
||||||
public class Autokey extends Vigenere{
|
public class Autokey extends Vigenere{
|
||||||
//Special rules for setting the strings for encoding
|
//Special rules for setting the strings for encoding
|
||||||
private void encodeSet(String key, String input) throws InvalidKeywordException{
|
private void encodeSet(String key, String input) throws InvalidKeywordException, InvalidInputException{
|
||||||
//Set the input
|
//Set the input
|
||||||
setInputString(input);
|
setInputString(input);
|
||||||
|
|
||||||
@@ -30,11 +31,10 @@ public class Autokey extends Vigenere{
|
|||||||
setOffset();
|
setOffset();
|
||||||
}
|
}
|
||||||
//Setting the strings for decoding
|
//Setting the strings for decoding
|
||||||
private void decodeSet(String key, String input) throws InvalidKeywordException{
|
private void decodeSet(String key, String input) throws InvalidKeywordException, InvalidInputException{
|
||||||
//Remove all unneccessary elements from the key
|
//Remove all unneccessary elements from the key
|
||||||
setKeyword(key);
|
setKeyword(key);
|
||||||
//Remove all unneccessary elements from the input
|
//Remove all unneccessary elements from the input
|
||||||
inputString = "";
|
|
||||||
setInputString(input);
|
setInputString(input);
|
||||||
}
|
}
|
||||||
//Decodes the inputString
|
//Decodes the inputString
|
||||||
@@ -91,15 +91,14 @@ public class Autokey extends Vigenere{
|
|||||||
super(preserveCapitals, preserveWhitespace, preserveSymbols);
|
super(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||||
}
|
}
|
||||||
//Encodes inputString using the Autokey cipher
|
//Encodes inputString using the Autokey cipher
|
||||||
public String encode(String key, String input) throws InvalidKeywordException{
|
public String encode(String key, String input) throws InvalidKeywordException, InvalidInputException{
|
||||||
reset();
|
reset();
|
||||||
encodeSet(key, input);
|
encodeSet(key, input);
|
||||||
return encode();
|
return encode();
|
||||||
}
|
}
|
||||||
//Decodes inputString using the Autokey cipher
|
//Decodes inputString using the Autokey cipher
|
||||||
public String decode(String key, String input) throws InvalidKeywordException{
|
public String decode(String key, String input) throws InvalidKeywordException, InvalidInputException{
|
||||||
reset();
|
reset();
|
||||||
setInputString(input);
|
|
||||||
decodeSet(key, input);
|
decodeSet(key, input);
|
||||||
return decode();
|
return decode();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import java.util.Arrays;
|
|||||||
import java.util.StringJoiner;
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidCharacterException;
|
import com.mattrixwv.CipherStreamJava.exceptions.InvalidCharacterException;
|
||||||
|
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
|
||||||
|
|
||||||
public class Baconian{
|
public class Baconian{
|
||||||
private static final ArrayList<String> code = new ArrayList<String>(Arrays.asList(
|
private static final ArrayList<String> code = new ArrayList<String>(Arrays.asList(
|
||||||
@@ -20,7 +21,11 @@ public class Baconian{
|
|||||||
private boolean preserveCapitals; //Whether to respect capitals in the output string
|
private boolean preserveCapitals; //Whether to respect capitals in the output string
|
||||||
|
|
||||||
//Sets the input string
|
//Sets the input string
|
||||||
private void setInputStringEncode(String inputString){
|
private void setInputStringEncode(String inputString) throws InvalidInputException{
|
||||||
|
if(inputString == null){
|
||||||
|
throw new NullPointerException("Input cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
//Remove all whitespace and symbols
|
//Remove all whitespace and symbols
|
||||||
inputString = inputString.replaceAll("[^A-Za-z]", "");
|
inputString = inputString.replaceAll("[^A-Za-z]", "");
|
||||||
if(!preserveCapitals){
|
if(!preserveCapitals){
|
||||||
@@ -28,8 +33,16 @@ public class Baconian{
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.inputString = inputString;
|
this.inputString = inputString;
|
||||||
|
|
||||||
|
if(this.inputString.isBlank()){
|
||||||
|
throw new InvalidInputException("Input must contain at least 1 letter");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private void setInputStringDecode(String inputString) throws InvalidCharacterException{
|
private void setInputStringDecode(String inputString) throws InvalidCharacterException, InvalidInputException{
|
||||||
|
if(inputString == null){
|
||||||
|
throw new NullPointerException("Input cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
if(!preserveCapitals){
|
if(!preserveCapitals){
|
||||||
inputString = inputString.toLowerCase();
|
inputString = inputString.toLowerCase();
|
||||||
}
|
}
|
||||||
@@ -48,6 +61,10 @@ public class Baconian{
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.inputString = inputString;
|
this.inputString = inputString;
|
||||||
|
|
||||||
|
if(this.inputString.isBlank()){
|
||||||
|
throw new InvalidInputException("Input cannot be null");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//Encodes the inputString and stores the result in outputString
|
//Encodes the inputString and stores the result in outputString
|
||||||
private String encode(){
|
private String encode(){
|
||||||
@@ -115,13 +132,13 @@ public class Baconian{
|
|||||||
return inputString;
|
return inputString;
|
||||||
}
|
}
|
||||||
//Sets the inputString and encodes the message
|
//Sets the inputString and encodes the message
|
||||||
public String encode(String inputString){
|
public String encode(String inputString) throws InvalidInputException{
|
||||||
reset();
|
reset();
|
||||||
setInputStringEncode(inputString);
|
setInputStringEncode(inputString);
|
||||||
return encode();
|
return encode();
|
||||||
}
|
}
|
||||||
//Sets the inputString and decodes the message
|
//Sets the inputString and decodes the message
|
||||||
public String decode(String inputString) throws InvalidCharacterException{
|
public String decode(String inputString) throws InvalidCharacterException, InvalidInputException{
|
||||||
reset();
|
reset();
|
||||||
setInputStringDecode(inputString);
|
setInputStringDecode(inputString);
|
||||||
return decode();
|
return decode();
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import java.util.StringJoiner;
|
|||||||
|
|
||||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidBaseException;
|
import com.mattrixwv.CipherStreamJava.exceptions.InvalidBaseException;
|
||||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidCharacterException;
|
import com.mattrixwv.CipherStreamJava.exceptions.InvalidCharacterException;
|
||||||
|
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
|
||||||
|
|
||||||
|
|
||||||
public class BaseX{
|
public class BaseX{
|
||||||
@@ -17,10 +18,22 @@ public class BaseX{
|
|||||||
private int base; //The base that the number will be encoded at
|
private int base; //The base that the number will be encoded at
|
||||||
|
|
||||||
//Sets the input string
|
//Sets the input string
|
||||||
private void setInputStringEncode(String inputString){
|
private void setInputStringEncode(String inputString) throws InvalidInputException{
|
||||||
|
if(inputString == null){
|
||||||
|
throw new NullPointerException("Input cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
this.inputString = inputString;
|
this.inputString = inputString;
|
||||||
|
|
||||||
|
if(this.inputString.isBlank()){
|
||||||
|
throw new InvalidInputException("Input must contain at least 1 letter");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private void setInputStringDecode(String inputString) throws InvalidCharacterException{
|
private void setInputStringDecode(String inputString) throws InvalidCharacterException, InvalidInputException{
|
||||||
|
if(inputString == null){
|
||||||
|
throw new NullPointerException("Input cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
StringBuilder validNumbers = new StringBuilder();
|
StringBuilder validNumbers = new StringBuilder();
|
||||||
for(int cnt = 0;cnt < base;++cnt){
|
for(int cnt = 0;cnt < base;++cnt){
|
||||||
validNumbers.append(Integer.toString(cnt, base).toUpperCase());
|
validNumbers.append(Integer.toString(cnt, base).toUpperCase());
|
||||||
@@ -29,6 +42,10 @@ public class BaseX{
|
|||||||
if(!this.inputString.equals(inputString)){
|
if(!this.inputString.equals(inputString)){
|
||||||
throw new InvalidCharacterException("inputString cannot contain anything except numbers 0-" + Integer.toString(base - 1, base) + ", and whitespace");
|
throw new InvalidCharacterException("inputString cannot contain anything except numbers 0-" + Integer.toString(base - 1, base) + ", and whitespace");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(this.inputString.isBlank()){
|
||||||
|
throw new InvalidInputException("Input must contain at least 1 letter");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//Sets the numeric base
|
//Sets the numeric base
|
||||||
private void setBase(int base) throws InvalidBaseException{
|
private void setBase(int base) throws InvalidBaseException{
|
||||||
@@ -100,24 +117,24 @@ public class BaseX{
|
|||||||
return base;
|
return base;
|
||||||
}
|
}
|
||||||
//Sets the inputString and encodes the message
|
//Sets the inputString and encodes the message
|
||||||
public String encode(String inputString){
|
public String encode(String inputString) throws InvalidInputException{
|
||||||
reset();
|
reset();
|
||||||
setInputStringEncode(inputString);
|
setInputStringEncode(inputString);
|
||||||
return encode();
|
return encode();
|
||||||
}
|
}
|
||||||
public String encode(int base, String inputString) throws InvalidBaseException{
|
public String encode(int base, String inputString) throws InvalidBaseException, InvalidInputException{
|
||||||
reset();
|
reset();
|
||||||
setBase(base);
|
setBase(base);
|
||||||
setInputStringEncode(inputString);
|
setInputStringEncode(inputString);
|
||||||
return encode();
|
return encode();
|
||||||
}
|
}
|
||||||
//Sets the inputString and decodes the message
|
//Sets the inputString and decodes the message
|
||||||
public String decode(String inputString) throws InvalidCharacterException{
|
public String decode(String inputString) throws InvalidCharacterException, InvalidInputException{
|
||||||
reset();
|
reset();
|
||||||
setInputStringDecode(inputString);
|
setInputStringDecode(inputString);
|
||||||
return decode();
|
return decode();
|
||||||
}
|
}
|
||||||
public String decode(int base, String inputString) throws InvalidBaseException, InvalidCharacterException{
|
public String decode(int base, String inputString) throws InvalidBaseException, InvalidCharacterException, InvalidInputException{
|
||||||
reset();
|
reset();
|
||||||
setBase(base);
|
setBase(base);
|
||||||
setInputStringDecode(inputString);
|
setInputStringDecode(inputString);
|
||||||
|
|||||||
@@ -5,6 +5,9 @@
|
|||||||
package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
||||||
|
|
||||||
|
|
||||||
|
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
|
||||||
|
|
||||||
|
|
||||||
public class Caesar{
|
public class Caesar{
|
||||||
private String inputString; //The string that needs encoded/decoded
|
private String inputString; //The string that needs encoded/decoded
|
||||||
private String outputString; //The encoded/decoded string
|
private String outputString; //The encoded/decoded string
|
||||||
@@ -18,7 +21,11 @@ public class Caesar{
|
|||||||
shift = shiftAmount % 26;
|
shift = shiftAmount % 26;
|
||||||
}
|
}
|
||||||
//Sets the input string
|
//Sets the input string
|
||||||
private void setInputString(String inputString){
|
private void setInputString(String inputString) throws InvalidInputException{
|
||||||
|
if(inputString == null){
|
||||||
|
throw new NullPointerException("Input cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
if(!preserveCapitals){
|
if(!preserveCapitals){
|
||||||
inputString = inputString.toLowerCase();
|
inputString = inputString.toLowerCase();
|
||||||
}
|
}
|
||||||
@@ -26,9 +33,14 @@ public class Caesar{
|
|||||||
inputString = inputString.replaceAll("\\s+", "");
|
inputString = inputString.replaceAll("\\s+", "");
|
||||||
}
|
}
|
||||||
if(!preserveSymbols){
|
if(!preserveSymbols){
|
||||||
inputString = inputString.replaceAll("[^a-zA-Z0-9\\s]", "");
|
inputString = inputString.replaceAll("[^a-zA-Z\\s]", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.inputString = inputString;
|
this.inputString = inputString;
|
||||||
|
|
||||||
|
if(this.inputString.isBlank()){
|
||||||
|
throw new InvalidInputException("Input must contain at least 1 letter");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//Encodes the inputString and stores the result in outputString
|
//Encodes the inputString and stores the result in outputString
|
||||||
private String encode(){
|
private String encode(){
|
||||||
@@ -127,14 +139,14 @@ public class Caesar{
|
|||||||
return outputString;
|
return outputString;
|
||||||
}
|
}
|
||||||
//Sets the shift and inputString and encodes the message
|
//Sets the shift and inputString and encodes the message
|
||||||
public String encode(int shiftAmount, String inputString){
|
public String encode(int shiftAmount, String inputString) throws InvalidInputException{
|
||||||
reset();
|
reset();
|
||||||
setShift(shiftAmount);
|
setShift(shiftAmount);
|
||||||
setInputString(inputString);
|
setInputString(inputString);
|
||||||
return encode();
|
return encode();
|
||||||
}
|
}
|
||||||
//Sets the shift and inputString and decodes the message
|
//Sets the shift and inputString and decodes the message
|
||||||
public String decode(int shiftAmount, String inputString){
|
public String decode(int shiftAmount, String inputString) throws InvalidInputException{
|
||||||
reset();
|
reset();
|
||||||
setShift(shiftAmount);
|
setShift(shiftAmount);
|
||||||
setInputString(inputString);
|
setInputString(inputString);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
|
||||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidKeywordException;
|
import com.mattrixwv.CipherStreamJava.exceptions.InvalidKeywordException;
|
||||||
|
|
||||||
|
|
||||||
@@ -31,7 +32,11 @@ public class Vigenere{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Sets inputString
|
//Sets inputString
|
||||||
protected void setInputString(String inputString){
|
protected void setInputString(String inputString) throws InvalidInputException{
|
||||||
|
if(inputString == null){
|
||||||
|
throw new NullPointerException("Input cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
if(!preserveCapitals){
|
if(!preserveCapitals){
|
||||||
inputString = inputString.toLowerCase();
|
inputString = inputString.toLowerCase();
|
||||||
}
|
}
|
||||||
@@ -39,25 +44,35 @@ public class Vigenere{
|
|||||||
inputString = inputString.replaceAll("\\s+", "");
|
inputString = inputString.replaceAll("\\s+", "");
|
||||||
}
|
}
|
||||||
if(!preserveSymbols){
|
if(!preserveSymbols){
|
||||||
inputString = inputString.replaceAll("[^a-zA-Z0-9\\s]", "");
|
inputString = inputString.replaceAll("[^a-zA-Z\\s]", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.inputString = inputString;
|
this.inputString = inputString;
|
||||||
|
|
||||||
|
if(this.inputString.isBlank()){
|
||||||
|
throw new InvalidInputException("Input must contain at least 1 letter");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//Sets keyword
|
//Sets keyword
|
||||||
protected void setKeyword(String key) throws InvalidKeywordException{
|
protected void setKeyword(String keyword) throws InvalidKeywordException{
|
||||||
|
if(keyword == null){
|
||||||
|
throw new NullPointerException("Keyword cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
//Convert all letters to uppercase
|
//Convert all letters to uppercase
|
||||||
key = key.toUpperCase();
|
keyword = keyword.toUpperCase();
|
||||||
//Remove all characters except capital letters
|
//Remove all characters except capital letters
|
||||||
key = key.replaceAll("[^A-Z]", "");
|
keyword = keyword.replaceAll("[^A-Z]", "");
|
||||||
//Save the string
|
//Save the string
|
||||||
keyword = key;
|
this.keyword = keyword;
|
||||||
|
|
||||||
//Make sure offset is empty before adding to it
|
//Make sure offset is empty before adding to it
|
||||||
offset.clear();
|
offset.clear();
|
||||||
setOffset();
|
setOffset();
|
||||||
|
|
||||||
//If after all the eliminating of unusable characters the keyword is empty throw an exception
|
//If after all the eliminating of unusable characters the keyword is empty throw an exception
|
||||||
if(keyword == ""){
|
if(this.keyword.isBlank()){
|
||||||
throw new InvalidKeywordException("The keyword cannot be empty");
|
throw new InvalidKeywordException("Keyword must contain at least 2 letters");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Encodes inputString and stores the result in outputString
|
//Encodes inputString and stores the result in outputString
|
||||||
@@ -160,14 +175,14 @@ public class Vigenere{
|
|||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
//Encodes input using key and returns the result
|
//Encodes input using key and returns the result
|
||||||
public String encode(String key, String input) throws InvalidKeywordException{
|
public String encode(String key, String input) throws InvalidKeywordException, InvalidInputException{
|
||||||
reset();
|
reset();
|
||||||
setKeyword(key);
|
setKeyword(key);
|
||||||
setInputString(input);
|
setInputString(input);
|
||||||
return encode();
|
return encode();
|
||||||
}
|
}
|
||||||
//Decodes input using key and returns the result
|
//Decodes input using key and returns the result
|
||||||
public String decode(String key, String input) throws InvalidKeywordException{
|
public String decode(String key, String input) throws InvalidKeywordException, InvalidInputException{
|
||||||
reset();
|
reset();
|
||||||
setKeyword(key);
|
setKeyword(key);
|
||||||
setInputString(input);
|
setInputString(input);
|
||||||
|
|||||||
@@ -47,10 +47,10 @@ public class Playfair{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Strips invalid characters from the string that needs encoded/decoded
|
//Strips invalid characters from the string that needs encoded/decoded
|
||||||
private void setInputString(String inputString, boolean encoding) throws InvalidCharacterException{
|
private void setInputString(String inputString, boolean encoding) throws InvalidCharacterException, InvalidInputException{
|
||||||
//Make sure the input string is not null
|
//Make sure the input string is not null
|
||||||
if(inputString == null){
|
if(inputString == null){
|
||||||
throw new InvalidCharacterException("The input string cannot be null");
|
throw new NullPointerException("The input string cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Set the options
|
//Set the options
|
||||||
@@ -61,7 +61,7 @@ public class Playfair{
|
|||||||
inputString = inputString.replaceAll("\\s+", "");
|
inputString = inputString.replaceAll("\\s+", "");
|
||||||
}
|
}
|
||||||
if(!preserveSymbols){
|
if(!preserveSymbols){
|
||||||
inputString = inputString.replaceAll("[^a-zA-Z0-9\\s]", "");
|
inputString = inputString.replaceAll("[^a-zA-Z\\s]", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Make replace all of the replacers with replaced
|
//Make replace all of the replacers with replaced
|
||||||
@@ -146,6 +146,10 @@ public class Playfair{
|
|||||||
|
|
||||||
this.inputString = inputString;
|
this.inputString = inputString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(this.inputString.isBlank() || getPreparedInputString().isBlank()){
|
||||||
|
throw new InvalidInputException("Input must have at least 1 letter");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//Returns the input string ready for encoding
|
//Returns the input string ready for encoding
|
||||||
private String getPreparedInputString(){
|
private String getPreparedInputString(){
|
||||||
@@ -154,23 +158,27 @@ public class Playfair{
|
|||||||
return cleanString;
|
return cleanString;
|
||||||
}
|
}
|
||||||
//Strips invalid characters from the keyword and creates the grid
|
//Strips invalid characters from the keyword and creates the grid
|
||||||
private void setKeyword(String key){
|
private void setKeyword(String keyword){
|
||||||
|
if(keyword == null){
|
||||||
|
throw new NullPointerException("Keyword cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
//Change everything to uppercase
|
//Change everything to uppercase
|
||||||
key = key.toUpperCase();
|
keyword = keyword.toUpperCase();
|
||||||
|
|
||||||
//Removing everything except capital letters
|
//Removing everything except capital letters
|
||||||
key = key.replaceAll("[^A-Z]", "");
|
keyword = keyword.replaceAll("[^A-Z]", "");
|
||||||
|
|
||||||
//Add all letters in the alphabet to the key
|
//Add all letters in the alphabet to the key
|
||||||
key += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
keyword += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
|
||||||
//Replace all replaced characters
|
//Replace all replaced characters
|
||||||
key = key.replaceAll(Character.toString(replaced), Character.toString(replacer));
|
keyword = keyword.replaceAll(Character.toString(replaced), Character.toString(replacer));
|
||||||
|
|
||||||
//Remove all duplicate chatacters
|
//Remove all duplicate chatacters
|
||||||
StringBuilder uniqueKey = new StringBuilder();
|
StringBuilder uniqueKey = new StringBuilder();
|
||||||
key.chars().distinct().forEach(c -> uniqueKey.append((char)c));
|
keyword.chars().distinct().forEach(c -> uniqueKey.append((char)c));
|
||||||
keyword = uniqueKey.toString();
|
this.keyword = uniqueKey.toString();
|
||||||
|
|
||||||
//Create the grid from the sanitized keyword
|
//Create the grid from the sanitized keyword
|
||||||
createGrid();
|
createGrid();
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ public class PolybiusSquare{
|
|||||||
private char[][] grid; //The grid used to encode/decode the message
|
private char[][] grid; //The grid used to encode/decode the message
|
||||||
private char replaced; //The letter that will need to be replaced in the grid and any input string or keyword
|
private char replaced; //The letter that will need to be replaced in the grid and any input string or keyword
|
||||||
private char replacer; //The letter that replaces replaced in the input string or keyword
|
private char replacer; //The letter that replaces replaced in the input string or keyword
|
||||||
private boolean leaveWhitespace; //Whether to respect whitespace in the output string
|
private boolean preserveWhitespace; //Whether to respect whitespace in the output string
|
||||||
private boolean leaveSymbols; //Whether to respect symbols in the output string
|
private boolean preserveSymbols; //Whether to respect symbols in the output string
|
||||||
|
|
||||||
//Create the grid from the keyword
|
//Create the grid from the keyword
|
||||||
public void createGrid(){
|
public void createGrid(){
|
||||||
@@ -48,7 +48,11 @@ public class PolybiusSquare{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Strips invalid characters from the string that needs encoded/decoded
|
//Strips invalid characters from the string that needs encoded/decoded
|
||||||
public void setInputStringEncoding(String inputString) throws InvalidCharacterException{
|
public void setInputStringEncoding(String inputString) throws InvalidCharacterException, InvalidInputException{
|
||||||
|
if(inputString == null){
|
||||||
|
throw new NullPointerException("Input cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
//Make sure the string doesn't contain any numbers
|
//Make sure the string doesn't contain any numbers
|
||||||
for(char ch = '0';ch <= '9';++ch){
|
for(char ch = '0';ch <= '9';++ch){
|
||||||
if(inputString.contains(Character.toString(ch))){
|
if(inputString.contains(Character.toString(ch))){
|
||||||
@@ -60,16 +64,16 @@ public class PolybiusSquare{
|
|||||||
inputString = inputString.toUpperCase();
|
inputString = inputString.toUpperCase();
|
||||||
|
|
||||||
//Remove any whitespace if selected
|
//Remove any whitespace if selected
|
||||||
if(!leaveWhitespace){
|
if(!preserveWhitespace){
|
||||||
inputString = inputString.replaceAll("\\s+", "");
|
inputString = inputString.replaceAll("\\s+", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Remove any symbols if selected
|
//Remove any symbols if selected
|
||||||
if(!leaveSymbols){
|
if(!preserveSymbols){
|
||||||
inputString = inputString.replaceAll("[^a-zA-Z0-9\\s]", "");
|
inputString = inputString.replaceAll("[^a-zA-Z\\s]", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!leaveWhitespace && !leaveSymbols){
|
if(!preserveWhitespace && !preserveSymbols){
|
||||||
//Add whitespace after every character for the default look
|
//Add whitespace after every character for the default look
|
||||||
StringJoiner spacedString = new StringJoiner(" ");
|
StringJoiner spacedString = new StringJoiner(" ");
|
||||||
for(int cnt = 0;cnt < inputString.length();++cnt){
|
for(int cnt = 0;cnt < inputString.length();++cnt){
|
||||||
@@ -83,8 +87,15 @@ public class PolybiusSquare{
|
|||||||
|
|
||||||
//Save the string
|
//Save the string
|
||||||
this.inputString = inputString;
|
this.inputString = inputString;
|
||||||
|
|
||||||
|
if(this.inputString.isBlank() || getPreparedInputStringEncoding().isBlank()){
|
||||||
|
throw new InvalidInputException("Input must contain at least 1 letter");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void setInputStringDecoding(String inputString) throws InvalidCharacterException{
|
public void setInputStringDecoding(String inputString) throws InvalidCharacterException, InvalidInputException{
|
||||||
|
if(inputString == null){
|
||||||
|
throw new NullPointerException("Input cannot be null");
|
||||||
|
}
|
||||||
//Make sure the string contains an even number of digits and no letters
|
//Make sure the string contains an even number of digits and no letters
|
||||||
int numberOfDigits = 0;
|
int numberOfDigits = 0;
|
||||||
for(int cnt = 0;cnt < inputString.length();++cnt){
|
for(int cnt = 0;cnt < inputString.length();++cnt){
|
||||||
@@ -101,17 +112,21 @@ public class PolybiusSquare{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Remove any whitespace if selected
|
//Remove any whitespace if selected
|
||||||
if(!leaveWhitespace){
|
if(!preserveWhitespace){
|
||||||
inputString = inputString.replaceAll("\\s+", "");
|
inputString = inputString.replaceAll("\\s+", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Remove any symbols if selected
|
//Remove any symbols if selected
|
||||||
if(!leaveSymbols){
|
if(!preserveSymbols){
|
||||||
inputString = inputString.replaceAll("[^0-9\\s]", "");
|
inputString = inputString.replaceAll("[^0-9\\s]", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Save the string
|
//Save the string
|
||||||
this.inputString = inputString;
|
this.inputString = inputString;
|
||||||
|
|
||||||
|
if(this.inputString.isBlank() || getPreparedInputStringDecoding().isBlank()){
|
||||||
|
throw new InvalidInputException("Input must contain at least 1 letter");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//Returns the input string ready for encoding
|
//Returns the input string ready for encoding
|
||||||
public String getPreparedInputStringEncoding(){
|
public String getPreparedInputStringEncoding(){
|
||||||
@@ -124,23 +139,26 @@ public class PolybiusSquare{
|
|||||||
return cleanString;
|
return cleanString;
|
||||||
}
|
}
|
||||||
//Strips invalid characters from the keyword and creates the grid
|
//Strips invalid characters from the keyword and creates the grid
|
||||||
public void setKeyword(String key){
|
public void setKeyword(String keyword){
|
||||||
|
if(keyword == null){
|
||||||
|
throw new NullPointerException("Keyword cannot be null");
|
||||||
|
}
|
||||||
//Change everything to uppercase
|
//Change everything to uppercase
|
||||||
key = key.toUpperCase();
|
keyword = keyword.toUpperCase();
|
||||||
|
|
||||||
//Remove everything except capital letters
|
//Remove everything except capital letters
|
||||||
key = key.replaceAll("[^A-Z]", "");
|
keyword = keyword.replaceAll("[^A-Z]", "");
|
||||||
|
|
||||||
//Add all letters in the alphabet to the key
|
//Add all letters in the alphabet to the key
|
||||||
key += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
keyword += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
|
||||||
//Replace all replaced characters
|
//Replace all replaced characters
|
||||||
key = key.replaceAll(Character.toString(replaced), Character.toString(replacer));
|
keyword = keyword.replaceAll(Character.toString(replaced), Character.toString(replacer));
|
||||||
|
|
||||||
//Remove all duplicate characters
|
//Remove all duplicate characters
|
||||||
StringBuilder uniqueKey = new StringBuilder();
|
StringBuilder uniqueKey = new StringBuilder();
|
||||||
key.chars().distinct().forEach(c -> uniqueKey.append((char)c));
|
keyword.chars().distinct().forEach(c -> uniqueKey.append((char)c));
|
||||||
keyword = uniqueKey.toString();
|
this.keyword = uniqueKey.toString();
|
||||||
|
|
||||||
//Create the grid from the sanitized keyword
|
//Create the grid from the sanitized keyword
|
||||||
createGrid();
|
createGrid();
|
||||||
@@ -239,22 +257,22 @@ public class PolybiusSquare{
|
|||||||
reset();
|
reset();
|
||||||
setReplaced('J');
|
setReplaced('J');
|
||||||
setReplacer('I');
|
setReplacer('I');
|
||||||
leaveWhitespace = false;
|
preserveWhitespace = false;
|
||||||
leaveSymbols = false;
|
preserveSymbols = false;
|
||||||
}
|
}
|
||||||
public PolybiusSquare(boolean leaveWhitespace, boolean leaveSymbols) throws InvalidCharacterException{
|
public PolybiusSquare(boolean preserveWhitespace, boolean preserveSymbols) throws InvalidCharacterException{
|
||||||
reset();
|
reset();
|
||||||
setReplaced('J');
|
setReplaced('J');
|
||||||
setReplacer('I');
|
setReplacer('I');
|
||||||
this.leaveWhitespace = leaveWhitespace;
|
this.preserveWhitespace = preserveWhitespace;
|
||||||
this.leaveSymbols = leaveSymbols;
|
this.preserveSymbols = preserveSymbols;
|
||||||
}
|
}
|
||||||
public PolybiusSquare(boolean leaveWhitespace, boolean leaveSymbols, char replaced, char replacer) throws InvalidCharacterException{
|
public PolybiusSquare(boolean preserveWhitespace, boolean preserveSymbols, char replaced, char replacer) throws InvalidCharacterException{
|
||||||
reset();
|
reset();
|
||||||
setReplaced(replaced);
|
setReplaced(replaced);
|
||||||
setReplacer(replacer);
|
setReplacer(replacer);
|
||||||
this.leaveWhitespace = leaveWhitespace;
|
this.preserveWhitespace = preserveWhitespace;
|
||||||
this.leaveSymbols = leaveSymbols;
|
this.preserveSymbols = preserveSymbols;
|
||||||
}
|
}
|
||||||
//Sets the keyword and inputString and encodes the message
|
//Sets the keyword and inputString and encodes the message
|
||||||
public String encode(String inputString) throws InvalidCharacterException, InvalidInputException{
|
public String encode(String inputString) throws InvalidCharacterException, InvalidInputException{
|
||||||
@@ -267,10 +285,10 @@ public class PolybiusSquare{
|
|||||||
return encode();
|
return encode();
|
||||||
}
|
}
|
||||||
//Sets the keyword and inputString and decodes the message
|
//Sets the keyword and inputString and decodes the message
|
||||||
public String decode(String inputString) throws InvalidCharacterException{
|
public String decode(String inputString) throws InvalidCharacterException, InvalidInputException{
|
||||||
return decode("", inputString);
|
return decode("", inputString);
|
||||||
}
|
}
|
||||||
public String decode(String keyword, String inputString) throws InvalidCharacterException{
|
public String decode(String keyword, String inputString) throws InvalidCharacterException, InvalidInputException{
|
||||||
reset();
|
reset();
|
||||||
setKeyword(keyword);
|
setKeyword(keyword);
|
||||||
setInputStringDecoding(inputString);
|
setInputStringDecoding(inputString);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
|
||||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidKeywordException;
|
import com.mattrixwv.CipherStreamJava.exceptions.InvalidKeywordException;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -14,244 +15,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
public class TestAutokey{
|
public class TestAutokey{
|
||||||
@Test
|
@Test
|
||||||
public void testDecode() throws InvalidKeywordException{
|
public void testEncode() throws InvalidKeywordException, InvalidInputException{
|
||||||
Autokey cipher = new Autokey(true, true, true);
|
|
||||||
|
|
||||||
//Test lowercase decoding
|
|
||||||
String input = "qnxepv";
|
|
||||||
String keyword = "queenly";
|
|
||||||
String correctOutput = "attack";
|
|
||||||
String output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed lowercase decoding.", correctOutput, output);
|
|
||||||
//Test uppercase decoding
|
|
||||||
input = "QNXEPV";
|
|
||||||
keyword = "queenly";
|
|
||||||
correctOutput = "ATTACK";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed uppercase decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace decoding
|
|
||||||
input = "qnxepv yt wtwp";
|
|
||||||
keyword = "queenly";
|
|
||||||
correctOutput = "attack at dawn";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed whitespace decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
|
||||||
input = "qnxepv@yt-wtwp";
|
|
||||||
keyword = "queenly";
|
|
||||||
correctOutput = "attack@at-dawn";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed symbol decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, symbol decoding
|
|
||||||
input = "Qnxepv yt - wtwp";
|
|
||||||
keyword = "QUEENLY";
|
|
||||||
correctOutput = "Attack at - dawn";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
|
||||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
|
||||||
input = "Wmpm mx \"Xae Yhbryoca\"";
|
|
||||||
keyword = "k@i l-t";
|
|
||||||
correctOutput = "Meet at \"The Fountain\"";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testNoWhitespaceDecode() throws InvalidKeywordException{
|
|
||||||
Autokey cipher = new Autokey(true, false, true);
|
|
||||||
|
|
||||||
//Test lowercase decoding
|
|
||||||
String input = "qnxepv";
|
|
||||||
String keyword = "queenly";
|
|
||||||
String correctOutput = "attack";
|
|
||||||
String output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed no whitespace lowercase decoding.", correctOutput, output);
|
|
||||||
//Test uppercase decoding
|
|
||||||
input = "QNXEPV";
|
|
||||||
keyword = "queenly";
|
|
||||||
correctOutput = "ATTACK";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed no whitespace uppercase decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace decoding
|
|
||||||
input = "qnxepv yt wtwp";
|
|
||||||
keyword = "queenly";
|
|
||||||
correctOutput = "attackatdawn";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed no whitespace whitespace decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
|
||||||
input = "qnxepv@yt-wtwp";
|
|
||||||
keyword = "queenly";
|
|
||||||
correctOutput = "attack@at-dawn";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed no whitespace symbol decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, symbol decoding
|
|
||||||
input = "Qnxepv yt - wtwp";
|
|
||||||
keyword = "QUEENLY";
|
|
||||||
correctOutput = "Attackat-dawn";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed no whitespace mixed case, whitespace, symbol decoding.", correctOutput, output);
|
|
||||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
|
||||||
input = "Wmpm mx \"Xae Yhbryoca\"";
|
|
||||||
keyword = "k@i l-t";
|
|
||||||
correctOutput = "Meetat\"TheFountain\"";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed no whitespace mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testNoCapitalDecode() throws InvalidKeywordException{
|
|
||||||
Autokey cipher = new Autokey(false, true, true);
|
|
||||||
|
|
||||||
//Test lowercase decoding
|
|
||||||
String input = "qnxepv";
|
|
||||||
String keyword = "queenly";
|
|
||||||
String correctOutput = "attack";
|
|
||||||
String output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed no capital lowercase decoding.", correctOutput, output);
|
|
||||||
//Test uppercase decoding
|
|
||||||
input = "QNXEPV";
|
|
||||||
keyword = "queenly";
|
|
||||||
correctOutput = "attack";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed no capital uppercase decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace decoding
|
|
||||||
input = "qnxepv yt wtwp";
|
|
||||||
keyword = "queenly";
|
|
||||||
correctOutput = "attack at dawn";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed no capital whitespace decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
|
||||||
input = "qnxepv@yt-wtwp";
|
|
||||||
keyword = "queenly";
|
|
||||||
correctOutput = "attack@at-dawn";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed no capital symbol decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, symbol decoding
|
|
||||||
input = "Qnxepv yt - wtwp";
|
|
||||||
keyword = "QUEENLY";
|
|
||||||
correctOutput = "attack at - dawn";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed no capital mixed case, whitespace, symbol decoding.", correctOutput, output);
|
|
||||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
|
||||||
input = "Wmpm mx \"Xae Yhbryoca\"";
|
|
||||||
keyword = "k@i l-t";
|
|
||||||
correctOutput = "meet at \"the fountain\"";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed no capital mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testNoSymbolDecode() throws InvalidKeywordException{
|
|
||||||
Autokey cipher = new Autokey(true, true, false);
|
|
||||||
|
|
||||||
//Test lowercase decoding
|
|
||||||
String input = "qnxepv";
|
|
||||||
String keyword = "queenly";
|
|
||||||
String correctOutput = "attack";
|
|
||||||
String output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed no symbol lowercase decoding.", correctOutput, output);
|
|
||||||
//Test uppercase decoding
|
|
||||||
input = "QNXEPV";
|
|
||||||
keyword = "queenly";
|
|
||||||
correctOutput = "ATTACK";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed no symbol uppercase decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace decoding
|
|
||||||
input = "qnxepv yt wtwp";
|
|
||||||
keyword = "queenly";
|
|
||||||
correctOutput = "attack at dawn";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed no symbol whitespace decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
|
||||||
input = "qnxepv@yt-wtwp";
|
|
||||||
keyword = "queenly";
|
|
||||||
correctOutput = "attackatdawn";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed no symbol symbol decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, symbol decoding
|
|
||||||
input = "Qnxepv yt - wtwp";
|
|
||||||
keyword = "QUEENLY";
|
|
||||||
correctOutput = "Attack at dawn";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed no symbol mixed case, whitespace, symbol decoding.", correctOutput, output);
|
|
||||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
|
||||||
input = "Wmpm mx \"Xae Yhbryoca\"";
|
|
||||||
keyword = "k@i l-t";
|
|
||||||
correctOutput = "Meet at The Fountain";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed no symbol mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidKeywordException{
|
|
||||||
Autokey cipher = new Autokey(false, false, false);
|
|
||||||
|
|
||||||
//Test lowercase decoding
|
|
||||||
String input = "qnxepv";
|
|
||||||
String keyword = "queenly";
|
|
||||||
String correctOutput = "attack";
|
|
||||||
String output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed secure lowercase decoding.", correctOutput, output);
|
|
||||||
//Test uppercase decoding
|
|
||||||
input = "QNXEPV";
|
|
||||||
keyword = "queenly";
|
|
||||||
correctOutput = "attack";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed secure uppercase decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace decoding
|
|
||||||
input = "qnxepv yt wtwp";
|
|
||||||
keyword = "queenly";
|
|
||||||
correctOutput = "attackatdawn";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed secure whitespace decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
|
||||||
input = "qnxepv@yt-wtwp";
|
|
||||||
keyword = "queenly";
|
|
||||||
correctOutput = "attackatdawn";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed secure symbol decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, symbol decoding
|
|
||||||
input = "Qnxepv yt - wtwp";
|
|
||||||
keyword = "QUEENLY";
|
|
||||||
correctOutput = "attackatdawn";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed secure mixed case, whitespace, symbol decoding.", correctOutput, output);
|
|
||||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
|
||||||
input = "Wmpm mx \"Xae Yhbryoca\"";
|
|
||||||
keyword = "k@i l-t";
|
|
||||||
correctOutput = "meetatthefountain";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Autokey failed secure mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEncode() throws InvalidKeywordException{
|
|
||||||
Autokey cipher = new Autokey(true, true, true);
|
Autokey cipher = new Autokey(true, true, true);
|
||||||
|
|
||||||
//Test lowercase decoding
|
//Test lowercase decoding
|
||||||
@@ -298,54 +62,7 @@ public class TestAutokey{
|
|||||||
assertEquals("Autokey failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
assertEquals("Autokey failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testNoWhitespaceEncode() throws InvalidKeywordException{
|
public void testNoCapitalEncode() throws InvalidKeywordException, InvalidInputException{
|
||||||
Autokey cipher = new Autokey(true, false, true);
|
|
||||||
|
|
||||||
//Test lowercase decoding
|
|
||||||
String input = "attack";
|
|
||||||
String keyword = "queenly";
|
|
||||||
String correctOutput = "qnxepv";
|
|
||||||
String output = cipher.encode(keyword, input);
|
|
||||||
assertEquals("Autokey failed no whitespace lowercase decoding.", correctOutput, output);
|
|
||||||
//Test uppercase decoding
|
|
||||||
input = "ATTACK";
|
|
||||||
keyword = "queenly";
|
|
||||||
correctOutput = "QNXEPV";
|
|
||||||
output = cipher.encode(keyword, input);
|
|
||||||
assertEquals("Autokey failed no whitespace uppercase decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace decoding
|
|
||||||
input = "attack at dawn";
|
|
||||||
keyword = "queenly";
|
|
||||||
correctOutput = "qnxepvytwtwp";
|
|
||||||
output = cipher.encode(keyword, input);
|
|
||||||
assertEquals("Autokey failed no whitespace whitespace decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
|
||||||
input = "attack@at-dawn";
|
|
||||||
keyword = "queenly";
|
|
||||||
correctOutput = "qnxepv@yt-wtwp";
|
|
||||||
output = cipher.encode(keyword, input);
|
|
||||||
assertEquals("Autokey failed no whitespace symbol decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, symbol encoding
|
|
||||||
input = "Attack at - dawn";
|
|
||||||
keyword = "QUEENLY";
|
|
||||||
correctOutput = "Qnxepvyt-wtwp";
|
|
||||||
output = cipher.encode(keyword, input);
|
|
||||||
assertEquals("Autokey failed no whitespace mixed case, whitespace, symbol decoding.", correctOutput, output);
|
|
||||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
|
||||||
input = "Meet at \"The Fountain\"";
|
|
||||||
keyword = "k@i l-t";
|
|
||||||
correctOutput = "Wmpmmx\"XaeYhbryoca\"";
|
|
||||||
output = cipher.encode(keyword, input);
|
|
||||||
assertEquals("Autokey failed no whitespace mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testNoCapitalEncode() throws InvalidKeywordException{
|
|
||||||
Autokey cipher = new Autokey(false, true, true);
|
Autokey cipher = new Autokey(false, true, true);
|
||||||
|
|
||||||
//Test lowercase decoding
|
//Test lowercase decoding
|
||||||
@@ -392,7 +109,54 @@ public class TestAutokey{
|
|||||||
assertEquals("Autokey failed no capital mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
assertEquals("Autokey failed no capital mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testNoSymbolEncode() throws InvalidKeywordException{
|
public void testNoWhitespaceEncode() throws InvalidKeywordException, InvalidInputException{
|
||||||
|
Autokey cipher = new Autokey(true, false, true);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String input = "attack";
|
||||||
|
String keyword = "queenly";
|
||||||
|
String correctOutput = "qnxepv";
|
||||||
|
String output = cipher.encode(keyword, input);
|
||||||
|
assertEquals("Autokey failed no whitespace lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
input = "ATTACK";
|
||||||
|
keyword = "queenly";
|
||||||
|
correctOutput = "QNXEPV";
|
||||||
|
output = cipher.encode(keyword, input);
|
||||||
|
assertEquals("Autokey failed no whitespace uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test whitespace decoding
|
||||||
|
input = "attack at dawn";
|
||||||
|
keyword = "queenly";
|
||||||
|
correctOutput = "qnxepvytwtwp";
|
||||||
|
output = cipher.encode(keyword, input);
|
||||||
|
assertEquals("Autokey failed no whitespace whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
input = "attack@at-dawn";
|
||||||
|
keyword = "queenly";
|
||||||
|
correctOutput = "qnxepv@yt-wtwp";
|
||||||
|
output = cipher.encode(keyword, input);
|
||||||
|
assertEquals("Autokey failed no whitespace symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol encoding
|
||||||
|
input = "Attack at - dawn";
|
||||||
|
keyword = "QUEENLY";
|
||||||
|
correctOutput = "Qnxepvyt-wtwp";
|
||||||
|
output = cipher.encode(keyword, input);
|
||||||
|
assertEquals("Autokey failed no whitespace mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||||
|
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||||
|
input = "Meet at \"The Fountain\"";
|
||||||
|
keyword = "k@i l-t";
|
||||||
|
correctOutput = "Wmpmmx\"XaeYhbryoca\"";
|
||||||
|
output = cipher.encode(keyword, input);
|
||||||
|
assertEquals("Autokey failed no whitespace mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testNoSymbolEncode() throws InvalidKeywordException, InvalidInputException{
|
||||||
Autokey cipher = new Autokey(true, true, false);
|
Autokey cipher = new Autokey(true, true, false);
|
||||||
|
|
||||||
//Test lowercase decoding
|
//Test lowercase decoding
|
||||||
@@ -439,7 +203,7 @@ public class TestAutokey{
|
|||||||
assertEquals("Autokey failed no symbol mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
assertEquals("Autokey failed no symbol mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidKeywordException{
|
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidKeywordException, InvalidInputException{
|
||||||
Autokey cipher = new Autokey(false, false, false);
|
Autokey cipher = new Autokey(false, false, false);
|
||||||
|
|
||||||
//Test lowercase decoding
|
//Test lowercase decoding
|
||||||
@@ -487,6 +251,243 @@ public class TestAutokey{
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDecode() throws InvalidKeywordException, InvalidInputException{
|
||||||
|
Autokey cipher = new Autokey(true, true, true);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String input = "qnxepv";
|
||||||
|
String keyword = "queenly";
|
||||||
|
String correctOutput = "attack";
|
||||||
|
String output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
input = "QNXEPV";
|
||||||
|
keyword = "queenly";
|
||||||
|
correctOutput = "ATTACK";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test whitespace decoding
|
||||||
|
input = "qnxepv yt wtwp";
|
||||||
|
keyword = "queenly";
|
||||||
|
correctOutput = "attack at dawn";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
input = "qnxepv@yt-wtwp";
|
||||||
|
keyword = "queenly";
|
||||||
|
correctOutput = "attack@at-dawn";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol decoding
|
||||||
|
input = "Qnxepv yt - wtwp";
|
||||||
|
keyword = "QUEENLY";
|
||||||
|
correctOutput = "Attack at - dawn";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||||
|
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||||
|
input = "Wmpm mx \"Xae Yhbryoca\"";
|
||||||
|
keyword = "k@i l-t";
|
||||||
|
correctOutput = "Meet at \"The Fountain\"";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testNoCapitalDecode() throws InvalidKeywordException, InvalidInputException{
|
||||||
|
Autokey cipher = new Autokey(false, true, true);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String input = "qnxepv";
|
||||||
|
String keyword = "queenly";
|
||||||
|
String correctOutput = "attack";
|
||||||
|
String output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed no capital lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
input = "QNXEPV";
|
||||||
|
keyword = "queenly";
|
||||||
|
correctOutput = "attack";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed no capital uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test whitespace decoding
|
||||||
|
input = "qnxepv yt wtwp";
|
||||||
|
keyword = "queenly";
|
||||||
|
correctOutput = "attack at dawn";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed no capital whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
input = "qnxepv@yt-wtwp";
|
||||||
|
keyword = "queenly";
|
||||||
|
correctOutput = "attack@at-dawn";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed no capital symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol decoding
|
||||||
|
input = "Qnxepv yt - wtwp";
|
||||||
|
keyword = "QUEENLY";
|
||||||
|
correctOutput = "attack at - dawn";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed no capital mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||||
|
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||||
|
input = "Wmpm mx \"Xae Yhbryoca\"";
|
||||||
|
keyword = "k@i l-t";
|
||||||
|
correctOutput = "meet at \"the fountain\"";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed no capital mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testNoWhitespaceDecode() throws InvalidKeywordException, InvalidInputException{
|
||||||
|
Autokey cipher = new Autokey(true, false, true);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String input = "qnxepv";
|
||||||
|
String keyword = "queenly";
|
||||||
|
String correctOutput = "attack";
|
||||||
|
String output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed no whitespace lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
input = "QNXEPV";
|
||||||
|
keyword = "queenly";
|
||||||
|
correctOutput = "ATTACK";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed no whitespace uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test whitespace decoding
|
||||||
|
input = "qnxepv yt wtwp";
|
||||||
|
keyword = "queenly";
|
||||||
|
correctOutput = "attackatdawn";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed no whitespace whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
input = "qnxepv@yt-wtwp";
|
||||||
|
keyword = "queenly";
|
||||||
|
correctOutput = "attack@at-dawn";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed no whitespace symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol decoding
|
||||||
|
input = "Qnxepv yt - wtwp";
|
||||||
|
keyword = "QUEENLY";
|
||||||
|
correctOutput = "Attackat-dawn";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed no whitespace mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||||
|
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||||
|
input = "Wmpm mx \"Xae Yhbryoca\"";
|
||||||
|
keyword = "k@i l-t";
|
||||||
|
correctOutput = "Meetat\"TheFountain\"";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed no whitespace mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testNoSymbolDecode() throws InvalidKeywordException, InvalidInputException{
|
||||||
|
Autokey cipher = new Autokey(true, true, false);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String input = "qnxepv";
|
||||||
|
String keyword = "queenly";
|
||||||
|
String correctOutput = "attack";
|
||||||
|
String output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed no symbol lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
input = "QNXEPV";
|
||||||
|
keyword = "queenly";
|
||||||
|
correctOutput = "ATTACK";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed no symbol uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test whitespace decoding
|
||||||
|
input = "qnxepv yt wtwp";
|
||||||
|
keyword = "queenly";
|
||||||
|
correctOutput = "attack at dawn";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed no symbol whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
input = "qnxepv@yt-wtwp";
|
||||||
|
keyword = "queenly";
|
||||||
|
correctOutput = "attackatdawn";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed no symbol symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol decoding
|
||||||
|
input = "Qnxepv yt - wtwp";
|
||||||
|
keyword = "QUEENLY";
|
||||||
|
correctOutput = "Attack at dawn";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed no symbol mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||||
|
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||||
|
input = "Wmpm mx \"Xae Yhbryoca\"";
|
||||||
|
keyword = "k@i l-t";
|
||||||
|
correctOutput = "Meet at The Fountain";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed no symbol mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidKeywordException, InvalidInputException{
|
||||||
|
Autokey cipher = new Autokey(false, false, false);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String input = "qnxepv";
|
||||||
|
String keyword = "queenly";
|
||||||
|
String correctOutput = "attack";
|
||||||
|
String output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed secure lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
input = "QNXEPV";
|
||||||
|
keyword = "queenly";
|
||||||
|
correctOutput = "attack";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed secure uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test whitespace decoding
|
||||||
|
input = "qnxepv yt wtwp";
|
||||||
|
keyword = "queenly";
|
||||||
|
correctOutput = "attackatdawn";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed secure whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
input = "qnxepv@yt-wtwp";
|
||||||
|
keyword = "queenly";
|
||||||
|
correctOutput = "attackatdawn";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed secure symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol decoding
|
||||||
|
input = "Qnxepv yt - wtwp";
|
||||||
|
keyword = "QUEENLY";
|
||||||
|
correctOutput = "attackatdawn";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed secure mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||||
|
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||||
|
input = "Wmpm mx \"Xae Yhbryoca\"";
|
||||||
|
keyword = "k@i l-t";
|
||||||
|
correctOutput = "meetatthefountain";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Autokey failed secure mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testKeyword() throws InvalidKeywordException{
|
public void testKeyword() throws InvalidKeywordException{
|
||||||
Autokey cipher = new Autokey();
|
Autokey cipher = new Autokey();
|
||||||
|
|||||||
@@ -8,55 +8,14 @@ package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidCharacterException;
|
import com.mattrixwv.CipherStreamJava.exceptions.InvalidCharacterException;
|
||||||
|
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
public class TestBaconian{
|
public class TestBaconian{
|
||||||
@Test
|
@Test
|
||||||
public void testDecode() throws InvalidCharacterException{
|
public void testEncode() throws InvalidInputException{
|
||||||
Baconian cipher = new Baconian(true);
|
|
||||||
|
|
||||||
//Test lowercase decoding
|
|
||||||
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);
|
|
||||||
//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);
|
|
||||||
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testDecodeNoCapital() throws InvalidCharacterException{
|
|
||||||
Baconian cipher = new Baconian(false);
|
|
||||||
|
|
||||||
//Test lowercase decoding
|
|
||||||
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);
|
|
||||||
//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);
|
|
||||||
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testEncode(){
|
|
||||||
Baconian cipher = new Baconian(true);
|
Baconian cipher = new Baconian(true);
|
||||||
|
|
||||||
//Test lowercase encoding
|
//Test lowercase encoding
|
||||||
@@ -77,7 +36,7 @@ public class TestBaconian{
|
|||||||
assertEquals("Baconian failed mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
assertEquals("Baconian failed mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeNoCapital(){
|
public void testEncodeNoCapital() throws InvalidInputException{
|
||||||
Baconian cipher = new Baconian(false);
|
Baconian cipher = new Baconian(false);
|
||||||
|
|
||||||
//Test lowercase encoding
|
//Test lowercase encoding
|
||||||
@@ -97,4 +56,48 @@ public class TestBaconian{
|
|||||||
output = cipher.encode(inputString);
|
output = cipher.encode(inputString);
|
||||||
assertEquals("Baconian failed no capital mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
assertEquals("Baconian failed no capital mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDecode() throws InvalidCharacterException, InvalidInputException{
|
||||||
|
Baconian cipher = new Baconian(true);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
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);
|
||||||
|
//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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testDecodeNoCapital() throws InvalidCharacterException, InvalidInputException{
|
||||||
|
Baconian cipher = new Baconian(false);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
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);
|
||||||
|
//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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,145 +9,14 @@ import static org.junit.Assert.assertEquals;
|
|||||||
|
|
||||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidBaseException;
|
import com.mattrixwv.CipherStreamJava.exceptions.InvalidBaseException;
|
||||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidCharacterException;
|
import com.mattrixwv.CipherStreamJava.exceptions.InvalidCharacterException;
|
||||||
|
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
public class TestBaseX{
|
public class TestBaseX{
|
||||||
@Test
|
@Test
|
||||||
public void testBinaryDecode() throws InvalidCharacterException, InvalidBaseException{
|
public void testBinaryEncode() throws InvalidBaseException, InvalidInputException{
|
||||||
BaseX cipher = new BaseX();
|
|
||||||
|
|
||||||
//Test lowercase decoding
|
|
||||||
String inputString = "1100001";
|
|
||||||
String correctOutput = "a";
|
|
||||||
String output = cipher.decode(inputString);
|
|
||||||
assertEquals("Binary failed binary lowercase decoding.", correctOutput, output);
|
|
||||||
//Test uppercase decoding
|
|
||||||
inputString = "1000001";
|
|
||||||
correctOutput = "A";
|
|
||||||
output = cipher.decode(inputString);
|
|
||||||
assertEquals("Binary failed binary uppercase decoding.", 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);
|
|
||||||
|
|
||||||
//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);
|
|
||||||
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testOctalDecode() throws InvalidCharacterException, InvalidBaseException{
|
|
||||||
BaseX cipher = new BaseX(8);
|
|
||||||
|
|
||||||
//Test lowercase decoding
|
|
||||||
String inputString = "141";
|
|
||||||
String correctOutput = "a";
|
|
||||||
String output = cipher.decode(inputString);
|
|
||||||
assertEquals("Binary failed octal lowercase decoding.", correctOutput, output);
|
|
||||||
//Test uppercase decoding
|
|
||||||
inputString = "101";
|
|
||||||
correctOutput = "A";
|
|
||||||
output = cipher.decode(inputString);
|
|
||||||
assertEquals("Binary failed octal uppercase decoding.", 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);
|
|
||||||
|
|
||||||
//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);
|
|
||||||
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testDecimalDecode() throws InvalidCharacterException, InvalidBaseException{
|
|
||||||
BaseX cipher = new BaseX(10);
|
|
||||||
|
|
||||||
//Test lowercase decoding
|
|
||||||
String inputString = "97";
|
|
||||||
String correctOutput = "a";
|
|
||||||
String output = cipher.decode(inputString);
|
|
||||||
assertEquals("Binary failed decimal lowercase decoding.", correctOutput, output);
|
|
||||||
//Test uppercase decoding
|
|
||||||
inputString = "65";
|
|
||||||
correctOutput = "A";
|
|
||||||
output = cipher.decode(inputString);
|
|
||||||
assertEquals("Binary failed decimal uppercase decoding.", 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);
|
|
||||||
|
|
||||||
//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);
|
|
||||||
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testHexDecode() throws InvalidCharacterException, InvalidBaseException{
|
|
||||||
BaseX cipher = new BaseX(16);
|
|
||||||
|
|
||||||
//Test lowercase decoding
|
|
||||||
String inputString = "61";
|
|
||||||
String correctOutput = "a";
|
|
||||||
String output = cipher.decode(inputString);
|
|
||||||
assertEquals("Binary failed hex lowercase decoding.", correctOutput, output);
|
|
||||||
//Test uppercase decoding
|
|
||||||
inputString = "41";
|
|
||||||
correctOutput = "A";
|
|
||||||
output = cipher.decode(inputString);
|
|
||||||
assertEquals("Binary failed hex uppercase decoding.", 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);
|
|
||||||
|
|
||||||
//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);
|
|
||||||
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testBinaryEncode() throws InvalidBaseException{
|
|
||||||
BaseX cipher = new BaseX();
|
BaseX cipher = new BaseX();
|
||||||
|
|
||||||
//Test lowercase encoding
|
//Test lowercase encoding
|
||||||
@@ -180,7 +49,7 @@ public class TestBaseX{
|
|||||||
assertEquals("Binary failed binary mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
assertEquals("Binary failed binary mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testOctalEncode() throws InvalidBaseException{
|
public void testOctalEncode() throws InvalidBaseException, InvalidInputException{
|
||||||
BaseX cipher = new BaseX(8);
|
BaseX cipher = new BaseX(8);
|
||||||
|
|
||||||
//Test lowercase encoding
|
//Test lowercase encoding
|
||||||
@@ -213,7 +82,7 @@ public class TestBaseX{
|
|||||||
assertEquals("Binary failed octal mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
assertEquals("Binary failed octal mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testDecimalEncode() throws InvalidBaseException{
|
public void testDecimalEncode() throws InvalidBaseException, InvalidInputException{
|
||||||
BaseX cipher = new BaseX(10);
|
BaseX cipher = new BaseX(10);
|
||||||
|
|
||||||
//Test lowercase encoding
|
//Test lowercase encoding
|
||||||
@@ -246,7 +115,7 @@ public class TestBaseX{
|
|||||||
assertEquals("Binary failed decimal mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
assertEquals("Binary failed decimal mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testHexEncode() throws InvalidBaseException{
|
public void testHexEncode() throws InvalidBaseException, InvalidInputException{
|
||||||
BaseX cipher = new BaseX(16);
|
BaseX cipher = new BaseX(16);
|
||||||
|
|
||||||
//Test lowercase encoding
|
//Test lowercase encoding
|
||||||
@@ -278,4 +147,138 @@ public class TestBaseX{
|
|||||||
output = cipher.encode(inputString);
|
output = cipher.encode(inputString);
|
||||||
assertEquals("Binary failed hex mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
assertEquals("Binary failed hex mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBinaryDecode() throws InvalidCharacterException, InvalidBaseException, InvalidInputException{
|
||||||
|
BaseX cipher = new BaseX();
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String inputString = "1100001";
|
||||||
|
String correctOutput = "a";
|
||||||
|
String output = cipher.decode(inputString);
|
||||||
|
assertEquals("Binary failed binary lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
inputString = "1000001";
|
||||||
|
correctOutput = "A";
|
||||||
|
output = cipher.decode(inputString);
|
||||||
|
assertEquals("Binary failed binary uppercase decoding.", 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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testOctalDecode() throws InvalidCharacterException, InvalidBaseException, InvalidInputException{
|
||||||
|
BaseX cipher = new BaseX(8);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String inputString = "141";
|
||||||
|
String correctOutput = "a";
|
||||||
|
String output = cipher.decode(inputString);
|
||||||
|
assertEquals("Binary failed octal lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
inputString = "101";
|
||||||
|
correctOutput = "A";
|
||||||
|
output = cipher.decode(inputString);
|
||||||
|
assertEquals("Binary failed octal uppercase decoding.", 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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testDecimalDecode() throws InvalidCharacterException, InvalidBaseException, InvalidInputException{
|
||||||
|
BaseX cipher = new BaseX(10);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String inputString = "97";
|
||||||
|
String correctOutput = "a";
|
||||||
|
String output = cipher.decode(inputString);
|
||||||
|
assertEquals("Binary failed decimal lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
inputString = "65";
|
||||||
|
correctOutput = "A";
|
||||||
|
output = cipher.decode(inputString);
|
||||||
|
assertEquals("Binary failed decimal uppercase decoding.", 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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testHexDecode() throws InvalidCharacterException, InvalidBaseException, InvalidInputException{
|
||||||
|
BaseX cipher = new BaseX(16);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String inputString = "61";
|
||||||
|
String correctOutput = "a";
|
||||||
|
String output = cipher.decode(inputString);
|
||||||
|
assertEquals("Binary failed hex lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
inputString = "41";
|
||||||
|
correctOutput = "A";
|
||||||
|
output = cipher.decode(inputString);
|
||||||
|
assertEquals("Binary failed hex uppercase decoding.", 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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,319 +7,14 @@ package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
public class TestCaesar{
|
public class TestCaesar{
|
||||||
@Test
|
@Test
|
||||||
public void testDecode(){
|
public void testEncode() throws InvalidInputException{
|
||||||
Caesar cipher = new Caesar(true, true, true);
|
|
||||||
|
|
||||||
//Test lowercase decoding
|
|
||||||
String input = "def";
|
|
||||||
int shift = 3;
|
|
||||||
String correctOutput = "abc";
|
|
||||||
String output = cipher.decode(shift, input);
|
|
||||||
assertEquals("Caesar failed lowercase decoding.", correctOutput, output);
|
|
||||||
//Test uppercase decoding
|
|
||||||
input = "DEF";
|
|
||||||
shift = 3;
|
|
||||||
correctOutput = "ABC";
|
|
||||||
output = cipher.decode(shift, input);
|
|
||||||
assertEquals("Caesar failed uppercase decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test out of bounds shift decoding
|
|
||||||
input = "def";
|
|
||||||
shift = 29;
|
|
||||||
correctOutput = "abc";
|
|
||||||
output = cipher.decode(shift, input);
|
|
||||||
assertEquals("Caesar failed out of bounds shift decoding.", 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);
|
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace decoding
|
|
||||||
input = "def ghi";
|
|
||||||
shift = 3;
|
|
||||||
correctOutput = "abc def";
|
|
||||||
output = cipher.decode(shift, input);
|
|
||||||
assertEquals("Caesar failed whitespace decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
|
||||||
input = "def-ghi@";
|
|
||||||
shift = 3;
|
|
||||||
correctOutput = "abc-def@";
|
|
||||||
output = cipher.decode(shift, input);
|
|
||||||
assertEquals("Caesar failed symbol decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, and symbol decoding
|
|
||||||
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
|
||||||
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);
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testNoWhitespaceDecode(){
|
|
||||||
Caesar cipher = new Caesar(true, false, true);
|
|
||||||
|
|
||||||
//Test lowercase decoding
|
|
||||||
String input = "def";
|
|
||||||
int shift = 3;
|
|
||||||
String correctOutput = "abc";
|
|
||||||
String output = cipher.decode(shift, input);
|
|
||||||
assertEquals("Caesar failed no whitespace lowercase decoding.", 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);
|
|
||||||
|
|
||||||
|
|
||||||
//Test out of bounds shift decoding
|
|
||||||
input = "def";
|
|
||||||
shift = 29;
|
|
||||||
correctOutput = "abc";
|
|
||||||
output = cipher.decode(shift, input);
|
|
||||||
assertEquals("Caesar failed no whitespace out of bounds shift decoding.", 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);
|
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace decoding
|
|
||||||
input = "def ghi";
|
|
||||||
shift = 3;
|
|
||||||
correctOutput = "abcdef";
|
|
||||||
output = cipher.decode(shift, input);
|
|
||||||
assertEquals("Caesar failed no whitespace whitespace decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
|
||||||
input = "def-ghi@";
|
|
||||||
shift = 3;
|
|
||||||
correctOutput = "abc-def@";
|
|
||||||
output = cipher.decode(shift, input);
|
|
||||||
assertEquals("Caesar failed no whitespace symbol decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, and symbol decoding
|
|
||||||
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
|
||||||
shift = 23;
|
|
||||||
correctOutput = "Thequickbrownfoxjumpsover-thelazydog";
|
|
||||||
output = cipher.decode(shift, input);
|
|
||||||
assertEquals("Caesar failed no whitespace mixed case, whitespace, and symbol decoding.", 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);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testNoCapitalDecode(){
|
|
||||||
Caesar cipher = new Caesar(false, true, true);
|
|
||||||
|
|
||||||
//Test lowercase decoding
|
|
||||||
String input = "def";
|
|
||||||
int shift = 3;
|
|
||||||
String correctOutput = "abc";
|
|
||||||
String output = cipher.decode(shift, input);
|
|
||||||
assertEquals("Caesar failed no capital lowercase decoding.", 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);
|
|
||||||
|
|
||||||
|
|
||||||
//Test out of bounds shift decoding
|
|
||||||
input = "def";
|
|
||||||
shift = 29;
|
|
||||||
correctOutput = "abc";
|
|
||||||
output = cipher.decode(shift, input);
|
|
||||||
assertEquals("Caesar failed no capital out of bounds shift decoding.", 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);
|
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace decoding
|
|
||||||
input = "def ghi";
|
|
||||||
shift = 3;
|
|
||||||
correctOutput = "abc def";
|
|
||||||
output = cipher.decode(shift, input);
|
|
||||||
assertEquals("Caesare failed no capital whitespace decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
|
||||||
input = "def-ghi@";
|
|
||||||
shift = 3;
|
|
||||||
correctOutput = "abc-def@";
|
|
||||||
output = cipher.decode(shift, input);
|
|
||||||
assertEquals("Caesar failed no capital symbol decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, and symbol decoding
|
|
||||||
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
|
||||||
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);
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testNoSymbolDecode(){
|
|
||||||
Caesar cipher = new Caesar(true, true, false);
|
|
||||||
|
|
||||||
//Test lowercase decoding
|
|
||||||
String input = "def";
|
|
||||||
int shift = 3;
|
|
||||||
String correctOutput = "abc";
|
|
||||||
String output = cipher.decode(shift, input);
|
|
||||||
assertEquals("Caesar failed no symbol lowercase decoding.", 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);
|
|
||||||
|
|
||||||
|
|
||||||
//Test out of bounds shift decoding
|
|
||||||
input = "def";
|
|
||||||
shift = 29;
|
|
||||||
correctOutput = "abc";
|
|
||||||
output = cipher.decode(shift, input);
|
|
||||||
assertEquals("Caesar failed no symbol out of bounds shift decoding.", 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);
|
|
||||||
|
|
||||||
|
|
||||||
//Test whitepace decoding
|
|
||||||
input = "def ghi";
|
|
||||||
shift = 3;
|
|
||||||
correctOutput = "abc def";
|
|
||||||
output = cipher.decode(shift, input);
|
|
||||||
assertEquals("Caesar failed no symbol whitespace decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
|
||||||
input = "def-ghi!";
|
|
||||||
shift = 3;
|
|
||||||
correctOutput = "abcdef";
|
|
||||||
output = cipher.decode(shift, input);
|
|
||||||
assertEquals("Caesar failed no symbol symbol decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, and symbol decoding
|
|
||||||
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
|
||||||
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);
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testNoCapitalWhitespaceSymbolDecode(){
|
|
||||||
Caesar cipher = new Caesar(false, false, false);
|
|
||||||
|
|
||||||
//Test lowercase decoding
|
|
||||||
String input = "def";
|
|
||||||
int shift = 3;
|
|
||||||
String correctOutput = "abc";
|
|
||||||
String output = cipher.decode(shift, input);
|
|
||||||
assertEquals("Caesar failed secure lowercase decoding.", correctOutput, output);
|
|
||||||
//Test uppercase decoding
|
|
||||||
input = "DEF";
|
|
||||||
shift = 3;
|
|
||||||
correctOutput = "abc";
|
|
||||||
output = cipher.decode(shift, input);
|
|
||||||
assertEquals("Caesar failed secure uppercase decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test out of bounds shift decoding
|
|
||||||
input = "def";
|
|
||||||
shift = 29;
|
|
||||||
correctOutput = "abc";
|
|
||||||
output = cipher.decode(shift, input);
|
|
||||||
assertEquals("Caesar failed secure out of bounds shift decoding.", 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);
|
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace decoding
|
|
||||||
input = "def ghi";
|
|
||||||
shift = 3;
|
|
||||||
correctOutput = "abcdef";
|
|
||||||
output = cipher.decode(shift, input);
|
|
||||||
assertEquals("Caesar failed secure whitespace decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
|
||||||
input = "def-ghi@";
|
|
||||||
shift = 3;
|
|
||||||
correctOutput = "abcdef";
|
|
||||||
output = cipher.decode(shift, input);
|
|
||||||
assertEquals("Caesar failed secure symbol decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, and symbol decoding
|
|
||||||
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
|
||||||
shift = 23;
|
|
||||||
correctOutput = "thequickbrownfoxjumpsoverthelazydog";
|
|
||||||
output = cipher.decode(shift, input);
|
|
||||||
assertEquals("Caesar failed secure mixed case, whitespace, and symbol decoding.", 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEncode(){
|
|
||||||
Caesar cipher = new Caesar(true, true, true);
|
Caesar cipher = new Caesar(true, true, true);
|
||||||
|
|
||||||
//Test lowercase encode
|
//Test lowercase encode
|
||||||
@@ -380,68 +75,7 @@ public class TestCaesar{
|
|||||||
assertEquals("Caesar failed mixed case, whitespace, and symbol encoding with negative shift.", correctOutput, output);
|
assertEquals("Caesar failed mixed case, whitespace, and symbol encoding with negative shift.", correctOutput, output);
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testNoWhitespaceEncode(){
|
public void testNoCapitalEncode() throws InvalidInputException{
|
||||||
Caesar cipher = new Caesar(true, false, true);
|
|
||||||
|
|
||||||
//Test lowercase encoding
|
|
||||||
String input = "abc";
|
|
||||||
int shift = 3;
|
|
||||||
String correctOutput = "def";
|
|
||||||
String output = cipher.encode(shift, input);
|
|
||||||
assertEquals("Caesar failed no whitespace lowercase encoding.", 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);
|
|
||||||
|
|
||||||
|
|
||||||
//Test out of bounds shift encoding
|
|
||||||
input = "abc";
|
|
||||||
shift = 29;
|
|
||||||
correctOutput = "def";
|
|
||||||
output = cipher.encode(shift, input);
|
|
||||||
assertEquals("Caesar failed no whitespace out of bounds shift encoding.", 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);
|
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace encoding
|
|
||||||
input = "abc def";
|
|
||||||
shift = 3;
|
|
||||||
correctOutput = "defghi";
|
|
||||||
output = cipher.encode(shift, input);
|
|
||||||
assertEquals("Caesar failed no whitespace whitespace encoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test symbol encoding
|
|
||||||
input = "abc-def@";
|
|
||||||
shift = 3;
|
|
||||||
correctOutput = "def-ghi@";
|
|
||||||
output = cipher.encode(shift, input);
|
|
||||||
assertEquals("Caesar failed no whitespace symbol encoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Testing mixed case, whitespace, and symbol encoding
|
|
||||||
input = "The quick brown fox jumps over - the lazy dog";
|
|
||||||
shift = 23;
|
|
||||||
correctOutput = "Qebnrfzhyoltkclugrjmplsbo-qebixwvald";
|
|
||||||
output = cipher.encode(shift, input);
|
|
||||||
assertEquals("Caesar failed no whitespace mixed case, whitespace, and symbol encoding.", 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);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testNoCapitalEncode(){
|
|
||||||
Caesar cipher = new Caesar(false, true, true);
|
Caesar cipher = new Caesar(false, true, true);
|
||||||
|
|
||||||
//Test lowercase encode
|
//Test lowercase encode
|
||||||
@@ -502,7 +136,68 @@ public class TestCaesar{
|
|||||||
assertEquals("Caesar failed no capital mixed case, whitespace, and symbol encoding with negative shift.", correctOutput, output);
|
assertEquals("Caesar failed no capital mixed case, whitespace, and symbol encoding with negative shift.", correctOutput, output);
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testNoSymbolEncode(){
|
public void testNoWhitespaceEncode() throws InvalidInputException{
|
||||||
|
Caesar cipher = new Caesar(true, false, true);
|
||||||
|
|
||||||
|
//Test lowercase encoding
|
||||||
|
String input = "abc";
|
||||||
|
int shift = 3;
|
||||||
|
String correctOutput = "def";
|
||||||
|
String output = cipher.encode(shift, input);
|
||||||
|
assertEquals("Caesar failed no whitespace lowercase encoding.", 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);
|
||||||
|
|
||||||
|
|
||||||
|
//Test out of bounds shift encoding
|
||||||
|
input = "abc";
|
||||||
|
shift = 29;
|
||||||
|
correctOutput = "def";
|
||||||
|
output = cipher.encode(shift, input);
|
||||||
|
assertEquals("Caesar failed no whitespace out of bounds shift encoding.", 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);
|
||||||
|
|
||||||
|
|
||||||
|
//Test whitespace encoding
|
||||||
|
input = "abc def";
|
||||||
|
shift = 3;
|
||||||
|
correctOutput = "defghi";
|
||||||
|
output = cipher.encode(shift, input);
|
||||||
|
assertEquals("Caesar failed no whitespace whitespace encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test symbol encoding
|
||||||
|
input = "abc-def@";
|
||||||
|
shift = 3;
|
||||||
|
correctOutput = "def-ghi@";
|
||||||
|
output = cipher.encode(shift, input);
|
||||||
|
assertEquals("Caesar failed no whitespace symbol encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Testing mixed case, whitespace, and symbol encoding
|
||||||
|
input = "The quick brown fox jumps over - the lazy dog";
|
||||||
|
shift = 23;
|
||||||
|
correctOutput = "Qebnrfzhyoltkclugrjmplsbo-qebixwvald";
|
||||||
|
output = cipher.encode(shift, input);
|
||||||
|
assertEquals("Caesar failed no whitespace mixed case, whitespace, and symbol encoding.", 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);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testNoSymbolEncode() throws InvalidInputException{
|
||||||
Caesar cipher = new Caesar(true, true, false);
|
Caesar cipher = new Caesar(true, true, false);
|
||||||
|
|
||||||
//Test lowercase encode
|
//Test lowercase encode
|
||||||
@@ -563,7 +258,7 @@ public class TestCaesar{
|
|||||||
assertEquals("Caesar failed mixed case, whitespace, and symbol encoding with negative shift.", correctOutput, output);
|
assertEquals("Caesar failed mixed case, whitespace, and symbol encoding with negative shift.", correctOutput, output);
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testNoCapitalWhitespaceSymbolEncode(){
|
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidInputException{
|
||||||
Caesar cipher = new Caesar(false, false, false);
|
Caesar cipher = new Caesar(false, false, false);
|
||||||
|
|
||||||
//Test lowercase encode
|
//Test lowercase encode
|
||||||
@@ -623,4 +318,311 @@ public class TestCaesar{
|
|||||||
output = cipher.encode(shift, input);
|
output = cipher.encode(shift, input);
|
||||||
assertEquals("Caesar failed secure mixed case, whitespace, and symbol encoding with negative shift.", correctOutput, output);
|
assertEquals("Caesar failed secure mixed case, whitespace, and symbol encoding with negative shift.", correctOutput, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDecode() throws InvalidInputException{
|
||||||
|
Caesar cipher = new Caesar(true, true, true);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String input = "def";
|
||||||
|
int shift = 3;
|
||||||
|
String correctOutput = "abc";
|
||||||
|
String output = cipher.decode(shift, input);
|
||||||
|
assertEquals("Caesar failed lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
input = "DEF";
|
||||||
|
shift = 3;
|
||||||
|
correctOutput = "ABC";
|
||||||
|
output = cipher.decode(shift, input);
|
||||||
|
assertEquals("Caesar failed uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test out of bounds shift decoding
|
||||||
|
input = "def";
|
||||||
|
shift = 29;
|
||||||
|
correctOutput = "abc";
|
||||||
|
output = cipher.decode(shift, input);
|
||||||
|
assertEquals("Caesar failed out of bounds shift decoding.", 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);
|
||||||
|
|
||||||
|
|
||||||
|
//Test whitespace decoding
|
||||||
|
input = "def ghi";
|
||||||
|
shift = 3;
|
||||||
|
correctOutput = "abc def";
|
||||||
|
output = cipher.decode(shift, input);
|
||||||
|
assertEquals("Caesar failed whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
input = "def-ghi@";
|
||||||
|
shift = 3;
|
||||||
|
correctOutput = "abc-def@";
|
||||||
|
output = cipher.decode(shift, input);
|
||||||
|
assertEquals("Caesar failed symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, and symbol decoding
|
||||||
|
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||||
|
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);
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testNoCapitalDecode() throws InvalidInputException{
|
||||||
|
Caesar cipher = new Caesar(false, true, true);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String input = "def";
|
||||||
|
int shift = 3;
|
||||||
|
String correctOutput = "abc";
|
||||||
|
String output = cipher.decode(shift, input);
|
||||||
|
assertEquals("Caesar failed no capital lowercase decoding.", 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);
|
||||||
|
|
||||||
|
|
||||||
|
//Test out of bounds shift decoding
|
||||||
|
input = "def";
|
||||||
|
shift = 29;
|
||||||
|
correctOutput = "abc";
|
||||||
|
output = cipher.decode(shift, input);
|
||||||
|
assertEquals("Caesar failed no capital out of bounds shift decoding.", 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);
|
||||||
|
|
||||||
|
|
||||||
|
//Test whitespace decoding
|
||||||
|
input = "def ghi";
|
||||||
|
shift = 3;
|
||||||
|
correctOutput = "abc def";
|
||||||
|
output = cipher.decode(shift, input);
|
||||||
|
assertEquals("Caesare failed no capital whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
input = "def-ghi@";
|
||||||
|
shift = 3;
|
||||||
|
correctOutput = "abc-def@";
|
||||||
|
output = cipher.decode(shift, input);
|
||||||
|
assertEquals("Caesar failed no capital symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, and symbol decoding
|
||||||
|
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||||
|
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);
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testNoWhitespaceDecode() throws InvalidInputException{
|
||||||
|
Caesar cipher = new Caesar(true, false, true);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String input = "def";
|
||||||
|
int shift = 3;
|
||||||
|
String correctOutput = "abc";
|
||||||
|
String output = cipher.decode(shift, input);
|
||||||
|
assertEquals("Caesar failed no whitespace lowercase decoding.", 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);
|
||||||
|
|
||||||
|
|
||||||
|
//Test out of bounds shift decoding
|
||||||
|
input = "def";
|
||||||
|
shift = 29;
|
||||||
|
correctOutput = "abc";
|
||||||
|
output = cipher.decode(shift, input);
|
||||||
|
assertEquals("Caesar failed no whitespace out of bounds shift decoding.", 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);
|
||||||
|
|
||||||
|
|
||||||
|
//Test whitespace decoding
|
||||||
|
input = "def ghi";
|
||||||
|
shift = 3;
|
||||||
|
correctOutput = "abcdef";
|
||||||
|
output = cipher.decode(shift, input);
|
||||||
|
assertEquals("Caesar failed no whitespace whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
input = "def-ghi@";
|
||||||
|
shift = 3;
|
||||||
|
correctOutput = "abc-def@";
|
||||||
|
output = cipher.decode(shift, input);
|
||||||
|
assertEquals("Caesar failed no whitespace symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, and symbol decoding
|
||||||
|
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||||
|
shift = 23;
|
||||||
|
correctOutput = "Thequickbrownfoxjumpsover-thelazydog";
|
||||||
|
output = cipher.decode(shift, input);
|
||||||
|
assertEquals("Caesar failed no whitespace mixed case, whitespace, and symbol decoding.", 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);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testNoSymbolDecode() throws InvalidInputException{
|
||||||
|
Caesar cipher = new Caesar(true, true, false);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String input = "def";
|
||||||
|
int shift = 3;
|
||||||
|
String correctOutput = "abc";
|
||||||
|
String output = cipher.decode(shift, input);
|
||||||
|
assertEquals("Caesar failed no symbol lowercase decoding.", 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);
|
||||||
|
|
||||||
|
|
||||||
|
//Test out of bounds shift decoding
|
||||||
|
input = "def";
|
||||||
|
shift = 29;
|
||||||
|
correctOutput = "abc";
|
||||||
|
output = cipher.decode(shift, input);
|
||||||
|
assertEquals("Caesar failed no symbol out of bounds shift decoding.", 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);
|
||||||
|
|
||||||
|
|
||||||
|
//Test whitepace decoding
|
||||||
|
input = "def ghi";
|
||||||
|
shift = 3;
|
||||||
|
correctOutput = "abc def";
|
||||||
|
output = cipher.decode(shift, input);
|
||||||
|
assertEquals("Caesar failed no symbol whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
input = "def-ghi!";
|
||||||
|
shift = 3;
|
||||||
|
correctOutput = "abcdef";
|
||||||
|
output = cipher.decode(shift, input);
|
||||||
|
assertEquals("Caesar failed no symbol symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, and symbol decoding
|
||||||
|
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||||
|
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);
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidInputException{
|
||||||
|
Caesar cipher = new Caesar(false, false, false);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String input = "def";
|
||||||
|
int shift = 3;
|
||||||
|
String correctOutput = "abc";
|
||||||
|
String output = cipher.decode(shift, input);
|
||||||
|
assertEquals("Caesar failed secure lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
input = "DEF";
|
||||||
|
shift = 3;
|
||||||
|
correctOutput = "abc";
|
||||||
|
output = cipher.decode(shift, input);
|
||||||
|
assertEquals("Caesar failed secure uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test out of bounds shift decoding
|
||||||
|
input = "def";
|
||||||
|
shift = 29;
|
||||||
|
correctOutput = "abc";
|
||||||
|
output = cipher.decode(shift, input);
|
||||||
|
assertEquals("Caesar failed secure out of bounds shift decoding.", 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);
|
||||||
|
|
||||||
|
|
||||||
|
//Test whitespace decoding
|
||||||
|
input = "def ghi";
|
||||||
|
shift = 3;
|
||||||
|
correctOutput = "abcdef";
|
||||||
|
output = cipher.decode(shift, input);
|
||||||
|
assertEquals("Caesar failed secure whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
input = "def-ghi@";
|
||||||
|
shift = 3;
|
||||||
|
correctOutput = "abcdef";
|
||||||
|
output = cipher.decode(shift, input);
|
||||||
|
assertEquals("Caesar failed secure symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, and symbol decoding
|
||||||
|
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||||
|
shift = 23;
|
||||||
|
correctOutput = "thequickbrownfoxjumpsoverthelazydog";
|
||||||
|
output = cipher.decode(shift, input);
|
||||||
|
assertEquals("Caesar failed secure mixed case, whitespace, and symbol decoding.", 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
|
||||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidKeywordException;
|
import com.mattrixwv.CipherStreamJava.exceptions.InvalidKeywordException;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -14,244 +15,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
public class TestVigenere{
|
public class TestVigenere{
|
||||||
@Test
|
@Test
|
||||||
public void testDecode() throws InvalidKeywordException{
|
public void testEncode() throws InvalidKeywordException, InvalidInputException{
|
||||||
Vigenere cipher = new Vigenere(true, true, true);
|
|
||||||
|
|
||||||
//Test lowercase decoding
|
|
||||||
String input = "xzb";
|
|
||||||
String keyword = "xyz";
|
|
||||||
String correctOutput = "abc";
|
|
||||||
String output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed lowercase decoding.", correctOutput, output);
|
|
||||||
//Test uppercase decoding
|
|
||||||
input = "XZB";
|
|
||||||
keyword = "XYZ";
|
|
||||||
correctOutput = "ABC";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed uppercase decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace decoding
|
|
||||||
input = "x z b";
|
|
||||||
keyword = "xyz";
|
|
||||||
correctOutput = "a b c";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed whitespace decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
|
||||||
input = "x@z^b";
|
|
||||||
keyword = "xyz";
|
|
||||||
correctOutput = "a@b^c";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed symbol decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, symbol decoding
|
|
||||||
input = "Lxfopv ef - rnhr";
|
|
||||||
keyword = "lemon";
|
|
||||||
correctOutput = "Attack at - dawn";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
|
||||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
|
||||||
input = "'Csastp' kv siqut gqu 'Csastpiuaqjb'";
|
|
||||||
keyword = " a@b C=d";
|
|
||||||
correctOutput = "'Crypto' is short for 'Cryptography'";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testNoWhitespaceDecode() throws InvalidKeywordException{
|
|
||||||
Vigenere cipher = new Vigenere(true, false, true);
|
|
||||||
|
|
||||||
//Test lowercase decoding
|
|
||||||
String input = "xzb";
|
|
||||||
String keyword = "xyz";
|
|
||||||
String correctOutput = "abc";
|
|
||||||
String output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed lowercase decoding.", correctOutput, output);
|
|
||||||
//Test uppercase decoding
|
|
||||||
input = "XZB";
|
|
||||||
keyword = "XYZ";
|
|
||||||
correctOutput = "ABC";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed uppercase decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace decoding
|
|
||||||
input = "x z b";
|
|
||||||
keyword = "xyz";
|
|
||||||
correctOutput = "abc";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed whitespace decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
|
||||||
input = "x@z^b";
|
|
||||||
keyword = "xyz";
|
|
||||||
correctOutput = "a@b^c";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed symbol decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, symbol decoding
|
|
||||||
input = "Lxfopv ef - rnhr";
|
|
||||||
keyword = "lemon";
|
|
||||||
correctOutput = "Attackat-dawn";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
|
||||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
|
||||||
input = "'Csastp' kv siqut gqu 'Csastpiuaqjb'";
|
|
||||||
keyword = " a@b C=d";
|
|
||||||
correctOutput = "'Crypto'isshortfor'Cryptography'";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testNoCapitalDecode() throws InvalidKeywordException{
|
|
||||||
Vigenere cipher = new Vigenere(false, true, true);
|
|
||||||
|
|
||||||
//Test lowercase decoding
|
|
||||||
String input = "xzb";
|
|
||||||
String keyword = "xyz";
|
|
||||||
String correctOutput = "abc";
|
|
||||||
String output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed lowercase decoding.", correctOutput, output);
|
|
||||||
//Test uppercase decoding
|
|
||||||
input = "XZB";
|
|
||||||
keyword = "XYZ";
|
|
||||||
correctOutput = "abc";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed uppercase decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace decoding
|
|
||||||
input = "x z b";
|
|
||||||
keyword = "xyz";
|
|
||||||
correctOutput = "a b c";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed whitespace decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
|
||||||
input = "x@z^b";
|
|
||||||
keyword = "xyz";
|
|
||||||
correctOutput = "a@b^c";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed symbol decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, symbol decoding
|
|
||||||
input = "Lxfopv ef - rnhr";
|
|
||||||
keyword = "lemon";
|
|
||||||
correctOutput = "attack at - dawn";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
|
||||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
|
||||||
input = "'Csastp' kv siqut gqu 'Csastpiuaqjb'";
|
|
||||||
keyword = " a@b C=d";
|
|
||||||
correctOutput = "'crypto' is short for 'cryptography'";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testNoSymbolDecode() throws InvalidKeywordException{
|
|
||||||
Vigenere cipher = new Vigenere(true, true, false);
|
|
||||||
|
|
||||||
//Test lowercase decoding
|
|
||||||
String input = "xzb";
|
|
||||||
String keyword = "xyz";
|
|
||||||
String correctOutput = "abc";
|
|
||||||
String output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed lowercase decoding.", correctOutput, output);
|
|
||||||
//Test uppercase decoding
|
|
||||||
input = "XZB";
|
|
||||||
keyword = "XYZ";
|
|
||||||
correctOutput = "ABC";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed uppercase decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace decoding
|
|
||||||
input = "x z b";
|
|
||||||
keyword = "xyz";
|
|
||||||
correctOutput = "a b c";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed whitespace decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
|
||||||
input = "x@z^b";
|
|
||||||
keyword = "xyz";
|
|
||||||
correctOutput = "abc";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed symbol decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, symbol decoding
|
|
||||||
input = "Lxfopv ef - rnhr";
|
|
||||||
keyword = "lemon";
|
|
||||||
correctOutput = "Attack at dawn";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
|
||||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
|
||||||
input = "'Csastp' kv siqut gqu 'Csastpiuaqjb'";
|
|
||||||
keyword = " a@b C=d";
|
|
||||||
correctOutput = "Crypto is short for Cryptography";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidKeywordException{
|
|
||||||
Vigenere cipher = new Vigenere(false, false, false);
|
|
||||||
|
|
||||||
//Test lowercase decoding
|
|
||||||
String input = "xzb";
|
|
||||||
String keyword = "xyz";
|
|
||||||
String correctOutput = "abc";
|
|
||||||
String output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed lowercase decoding.", correctOutput, output);
|
|
||||||
//Test uppercase decoding
|
|
||||||
input = "XZB";
|
|
||||||
keyword = "XYZ";
|
|
||||||
correctOutput = "abc";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed uppercase decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace decoding
|
|
||||||
input = "x z b";
|
|
||||||
keyword = "xyz";
|
|
||||||
correctOutput = "abc";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed whitespace decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
|
||||||
input = "x@z^b";
|
|
||||||
keyword = "xyz";
|
|
||||||
correctOutput = "abc";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed symbol decoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, symbol decoding
|
|
||||||
input = "Lxfopv ef rnhr";
|
|
||||||
keyword = "lemon";
|
|
||||||
correctOutput = "attackatdawn";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
|
||||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
|
||||||
input = "'Csastp' kv siqut gqu 'Csastpiuaqjb'";
|
|
||||||
keyword = " a@b C=d";
|
|
||||||
correctOutput = "cryptoisshortforcryptography";
|
|
||||||
output = cipher.decode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEncode() throws InvalidKeywordException{
|
|
||||||
Vigenere cipher = new Vigenere(true, true, true);
|
Vigenere cipher = new Vigenere(true, true, true);
|
||||||
|
|
||||||
//Test lowercase encoding
|
//Test lowercase encoding
|
||||||
@@ -298,54 +62,7 @@ public class TestVigenere{
|
|||||||
assertEquals("Vigenere failed mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
assertEquals("Vigenere failed mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testNoWhitespaceEncode() throws InvalidKeywordException{
|
public void testNoCapitalEncode() throws InvalidKeywordException, InvalidInputException{
|
||||||
Vigenere cipher = new Vigenere(true, false, true);
|
|
||||||
|
|
||||||
//Test lowercase encoding
|
|
||||||
String input = "abc";
|
|
||||||
String keyword = "xyz";
|
|
||||||
String correctOutput = "xzb";
|
|
||||||
String output = cipher.encode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed lowercase encoding.", correctOutput, output);
|
|
||||||
//Test upercase encoding
|
|
||||||
input = "ABC";
|
|
||||||
keyword = "xyz";
|
|
||||||
correctOutput = "XZB";
|
|
||||||
output = cipher.encode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed uppercase encoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace encoding
|
|
||||||
input = "a b c";
|
|
||||||
keyword = "xyz";
|
|
||||||
correctOutput = "xzb";
|
|
||||||
output = cipher.encode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed whitespace encoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
|
||||||
input = "a@b^c";
|
|
||||||
keyword = "xyz";
|
|
||||||
correctOutput = "x@z^b";
|
|
||||||
output = cipher.encode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed symbol encoding.", correctOutput, output);
|
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, symbol decoding
|
|
||||||
input = "Attack at dawn";
|
|
||||||
keyword = "lemon";
|
|
||||||
correctOutput = "Lxfopvefrnhr";
|
|
||||||
output = cipher.encode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
|
||||||
//Test mixed case, whitespace, symbol decoding test 2
|
|
||||||
input = "'Crypto' is short for 'Cryptography'";
|
|
||||||
keyword = " a@b C=d";
|
|
||||||
correctOutput = "'Csastp'kvsiqutgqu'Csastpiuaqjb'";
|
|
||||||
output = cipher.encode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testNoCapitalEncode() throws InvalidKeywordException{
|
|
||||||
Vigenere cipher = new Vigenere(false, true, true);
|
Vigenere cipher = new Vigenere(false, true, true);
|
||||||
|
|
||||||
//Test lowercase encoding
|
//Test lowercase encoding
|
||||||
@@ -392,7 +109,54 @@ public class TestVigenere{
|
|||||||
assertEquals("Vigenere failed mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
assertEquals("Vigenere failed mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testNoSymbolEncode() throws InvalidKeywordException{
|
public void testNoWhitespaceEncode() throws InvalidKeywordException, InvalidInputException{
|
||||||
|
Vigenere cipher = new Vigenere(true, false, true);
|
||||||
|
|
||||||
|
//Test lowercase encoding
|
||||||
|
String input = "abc";
|
||||||
|
String keyword = "xyz";
|
||||||
|
String correctOutput = "xzb";
|
||||||
|
String output = cipher.encode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed lowercase encoding.", correctOutput, output);
|
||||||
|
//Test upercase encoding
|
||||||
|
input = "ABC";
|
||||||
|
keyword = "xyz";
|
||||||
|
correctOutput = "XZB";
|
||||||
|
output = cipher.encode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed uppercase encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test whitespace encoding
|
||||||
|
input = "a b c";
|
||||||
|
keyword = "xyz";
|
||||||
|
correctOutput = "xzb";
|
||||||
|
output = cipher.encode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed whitespace encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
input = "a@b^c";
|
||||||
|
keyword = "xyz";
|
||||||
|
correctOutput = "x@z^b";
|
||||||
|
output = cipher.encode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed symbol encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol decoding
|
||||||
|
input = "Attack at dawn";
|
||||||
|
keyword = "lemon";
|
||||||
|
correctOutput = "Lxfopvefrnhr";
|
||||||
|
output = cipher.encode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||||
|
//Test mixed case, whitespace, symbol decoding test 2
|
||||||
|
input = "'Crypto' is short for 'Cryptography'";
|
||||||
|
keyword = " a@b C=d";
|
||||||
|
correctOutput = "'Csastp'kvsiqutgqu'Csastpiuaqjb'";
|
||||||
|
output = cipher.encode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testNoSymbolEncode() throws InvalidKeywordException, InvalidInputException{
|
||||||
Vigenere cipher = new Vigenere(true, true, false);
|
Vigenere cipher = new Vigenere(true, true, false);
|
||||||
|
|
||||||
//Test lowercase encoding
|
//Test lowercase encoding
|
||||||
@@ -439,7 +203,7 @@ public class TestVigenere{
|
|||||||
assertEquals("Vigenere failed mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
assertEquals("Vigenere failed mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidKeywordException{
|
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidKeywordException, InvalidInputException{
|
||||||
Vigenere cipher = new Vigenere(false, false, false);
|
Vigenere cipher = new Vigenere(false, false, false);
|
||||||
|
|
||||||
//Test lowercase encoding
|
//Test lowercase encoding
|
||||||
@@ -487,6 +251,243 @@ public class TestVigenere{
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDecode() throws InvalidKeywordException, InvalidInputException{
|
||||||
|
Vigenere cipher = new Vigenere(true, true, true);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String input = "xzb";
|
||||||
|
String keyword = "xyz";
|
||||||
|
String correctOutput = "abc";
|
||||||
|
String output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
input = "XZB";
|
||||||
|
keyword = "XYZ";
|
||||||
|
correctOutput = "ABC";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test whitespace decoding
|
||||||
|
input = "x z b";
|
||||||
|
keyword = "xyz";
|
||||||
|
correctOutput = "a b c";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
input = "x@z^b";
|
||||||
|
keyword = "xyz";
|
||||||
|
correctOutput = "a@b^c";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol decoding
|
||||||
|
input = "Lxfopv ef - rnhr";
|
||||||
|
keyword = "lemon";
|
||||||
|
correctOutput = "Attack at - dawn";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||||
|
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||||
|
input = "'Csastp' kv siqut gqu 'Csastpiuaqjb'";
|
||||||
|
keyword = " a@b C=d";
|
||||||
|
correctOutput = "'Crypto' is short for 'Cryptography'";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testNoCapitalDecode() throws InvalidKeywordException, InvalidInputException{
|
||||||
|
Vigenere cipher = new Vigenere(false, true, true);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String input = "xzb";
|
||||||
|
String keyword = "xyz";
|
||||||
|
String correctOutput = "abc";
|
||||||
|
String output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
input = "XZB";
|
||||||
|
keyword = "XYZ";
|
||||||
|
correctOutput = "abc";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test whitespace decoding
|
||||||
|
input = "x z b";
|
||||||
|
keyword = "xyz";
|
||||||
|
correctOutput = "a b c";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
input = "x@z^b";
|
||||||
|
keyword = "xyz";
|
||||||
|
correctOutput = "a@b^c";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol decoding
|
||||||
|
input = "Lxfopv ef - rnhr";
|
||||||
|
keyword = "lemon";
|
||||||
|
correctOutput = "attack at - dawn";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||||
|
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||||
|
input = "'Csastp' kv siqut gqu 'Csastpiuaqjb'";
|
||||||
|
keyword = " a@b C=d";
|
||||||
|
correctOutput = "'crypto' is short for 'cryptography'";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testNoWhitespaceDecode() throws InvalidKeywordException, InvalidInputException{
|
||||||
|
Vigenere cipher = new Vigenere(true, false, true);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String input = "xzb";
|
||||||
|
String keyword = "xyz";
|
||||||
|
String correctOutput = "abc";
|
||||||
|
String output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
input = "XZB";
|
||||||
|
keyword = "XYZ";
|
||||||
|
correctOutput = "ABC";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test whitespace decoding
|
||||||
|
input = "x z b";
|
||||||
|
keyword = "xyz";
|
||||||
|
correctOutput = "abc";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
input = "x@z^b";
|
||||||
|
keyword = "xyz";
|
||||||
|
correctOutput = "a@b^c";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol decoding
|
||||||
|
input = "Lxfopv ef - rnhr";
|
||||||
|
keyword = "lemon";
|
||||||
|
correctOutput = "Attackat-dawn";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||||
|
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||||
|
input = "'Csastp' kv siqut gqu 'Csastpiuaqjb'";
|
||||||
|
keyword = " a@b C=d";
|
||||||
|
correctOutput = "'Crypto'isshortfor'Cryptography'";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testNoSymbolDecode() throws InvalidKeywordException, InvalidInputException{
|
||||||
|
Vigenere cipher = new Vigenere(true, true, false);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String input = "xzb";
|
||||||
|
String keyword = "xyz";
|
||||||
|
String correctOutput = "abc";
|
||||||
|
String output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
input = "XZB";
|
||||||
|
keyword = "XYZ";
|
||||||
|
correctOutput = "ABC";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test whitespace decoding
|
||||||
|
input = "x z b";
|
||||||
|
keyword = "xyz";
|
||||||
|
correctOutput = "a b c";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
input = "x@z^b";
|
||||||
|
keyword = "xyz";
|
||||||
|
correctOutput = "abc";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol decoding
|
||||||
|
input = "Lxfopv ef - rnhr";
|
||||||
|
keyword = "lemon";
|
||||||
|
correctOutput = "Attack at dawn";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||||
|
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||||
|
input = "'Csastp' kv siqut gqu 'Csastpiuaqjb'";
|
||||||
|
keyword = " a@b C=d";
|
||||||
|
correctOutput = "Crypto is short for Cryptography";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidKeywordException, InvalidInputException{
|
||||||
|
Vigenere cipher = new Vigenere(false, false, false);
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String input = "xzb";
|
||||||
|
String keyword = "xyz";
|
||||||
|
String correctOutput = "abc";
|
||||||
|
String output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
input = "XZB";
|
||||||
|
keyword = "XYZ";
|
||||||
|
correctOutput = "abc";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test whitespace decoding
|
||||||
|
input = "x z b";
|
||||||
|
keyword = "xyz";
|
||||||
|
correctOutput = "abc";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
input = "x@z^b";
|
||||||
|
keyword = "xyz";
|
||||||
|
correctOutput = "abc";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol decoding
|
||||||
|
input = "Lxfopv ef rnhr";
|
||||||
|
keyword = "lemon";
|
||||||
|
correctOutput = "attackatdawn";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||||
|
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||||
|
input = "'Csastp' kv siqut gqu 'Csastpiuaqjb'";
|
||||||
|
keyword = " a@b C=d";
|
||||||
|
correctOutput = "cryptoisshortforcryptography";
|
||||||
|
output = cipher.decode(keyword, input);
|
||||||
|
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testKeyword() throws InvalidKeywordException{
|
public void testKeyword() throws InvalidKeywordException{
|
||||||
Vigenere cipher = new Vigenere();
|
Vigenere cipher = new Vigenere();
|
||||||
|
|||||||
@@ -11,28 +11,6 @@ import org.junit.Test;
|
|||||||
|
|
||||||
|
|
||||||
public class TestMorse{
|
public class TestMorse{
|
||||||
@Test
|
|
||||||
public void testDecode(){
|
|
||||||
Morse cipher = new Morse();
|
|
||||||
|
|
||||||
//Test 1
|
|
||||||
String input = "... --- ...";
|
|
||||||
String correctOutput = "SOS";
|
|
||||||
String output = cipher.decode(input);
|
|
||||||
assertEquals("Morse Decoding failed the first test", correctOutput, output);
|
|
||||||
|
|
||||||
//Test 2
|
|
||||||
input = "-- --- .-. ... . -.-. --- -.. .";
|
|
||||||
correctOutput = "MORSECODE";
|
|
||||||
output = cipher.decode(input);
|
|
||||||
assertEquals("Morse Decoding failed the second test", correctOutput, output);
|
|
||||||
|
|
||||||
//Test 3
|
|
||||||
input = ".---- ..--- ...-- ----. ---.. --...";
|
|
||||||
correctOutput = "123987";
|
|
||||||
output = cipher.decode(input);
|
|
||||||
assertEquals("Morse Decoding failed the third test", correctOutput, output);
|
|
||||||
}
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncode(){
|
public void testEncode(){
|
||||||
Morse cipher = new Morse();
|
Morse cipher = new Morse();
|
||||||
@@ -55,4 +33,26 @@ public class TestMorse{
|
|||||||
output = cipher.encode(input);
|
output = cipher.encode(input);
|
||||||
assertEquals("Morse Encoding failed the third test", correctOutput, output);
|
assertEquals("Morse Encoding failed the third test", correctOutput, output);
|
||||||
}
|
}
|
||||||
|
@Test
|
||||||
|
public void testDecode(){
|
||||||
|
Morse cipher = new Morse();
|
||||||
|
|
||||||
|
//Test 1
|
||||||
|
String input = "... --- ...";
|
||||||
|
String correctOutput = "SOS";
|
||||||
|
String output = cipher.decode(input);
|
||||||
|
assertEquals("Morse Decoding failed the first test", correctOutput, output);
|
||||||
|
|
||||||
|
//Test 2
|
||||||
|
input = "-- --- .-. ... . -.-. --- -.. .";
|
||||||
|
correctOutput = "MORSECODE";
|
||||||
|
output = cipher.decode(input);
|
||||||
|
assertEquals("Morse Decoding failed the second test", correctOutput, output);
|
||||||
|
|
||||||
|
//Test 3
|
||||||
|
input = ".---- ..--- ...-- ----. ---.. --...";
|
||||||
|
correctOutput = "123987";
|
||||||
|
output = cipher.decode(input);
|
||||||
|
assertEquals("Morse Decoding failed the third test", correctOutput, output);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,256 @@ import org.junit.Test;
|
|||||||
|
|
||||||
|
|
||||||
public class TestPlayfair{
|
public class TestPlayfair{
|
||||||
|
@Test
|
||||||
|
public void testEncode() throws InvalidCharacterException, InvalidInputException{
|
||||||
|
Playfair cipher = new Playfair(true, true, true);
|
||||||
|
|
||||||
|
//Test lowercase encoding
|
||||||
|
String inputString = "hidethegoldinthetreestump";
|
||||||
|
String keyword = "Playfair Example";
|
||||||
|
String correctOutput = "bmodzbxdnabekudmuixMmouvif";
|
||||||
|
String output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Playfair failed lowercase encoding.", correctOutput, output);
|
||||||
|
//Test uppercase encoding
|
||||||
|
inputString = "HIDETHEGOLDINTHETREESTUMP";
|
||||||
|
keyword = "Playfair Example";
|
||||||
|
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Playfair failed uppercase encoding.", 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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testNoWhitespaceEncode() throws InvalidCharacterException, InvalidInputException{
|
||||||
|
Playfair cipher = new Playfair(true, false, true);
|
||||||
|
|
||||||
|
//Test lowercase encoding
|
||||||
|
String inputString = "hidethegoldinthetreestump";
|
||||||
|
String keyword = "Playfair Example";
|
||||||
|
String correctOutput = "bmodzbxdnabekudmuixMmouvif";
|
||||||
|
String output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Playfair failed no whitespace lowercase encoding.", 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);
|
||||||
|
//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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testNoCapitalEncode() throws InvalidCharacterException, InvalidInputException{
|
||||||
|
Playfair cipher = new Playfair(false, true, true);
|
||||||
|
|
||||||
|
//Test lowercase encoding
|
||||||
|
String inputString = "hidethegoldinthetreestump";
|
||||||
|
String keyword = "Playfair Example";
|
||||||
|
String correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||||
|
String output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Playfair failed no capital lowercase encoding.", 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);
|
||||||
|
//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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testNoSymbolEncode() throws InvalidCharacterException, InvalidInputException{
|
||||||
|
Playfair cipher = new Playfair(true, true, false);
|
||||||
|
|
||||||
|
//Test lowercase encoding
|
||||||
|
String inputString = "hidethegoldinthetreestump";
|
||||||
|
String keyword = "Playfair Example";
|
||||||
|
String correctOutput = "bmodzbxdnabekudmuixMmouvif";
|
||||||
|
String output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Playfair failed no symbol lowercase encoding.", 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);
|
||||||
|
//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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidCharacterException, InvalidInputException{
|
||||||
|
Playfair cipher = new Playfair(false, false, false);
|
||||||
|
|
||||||
|
//Test lowercase encoding
|
||||||
|
String inputString = "hidethegoldinthetreestump";
|
||||||
|
String keyword = "Playfair Example";
|
||||||
|
String correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||||
|
String output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Playfair failed secure lowercase encoding.", 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);
|
||||||
|
//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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
//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);
|
||||||
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testDecode() throws InvalidCharacterException, InvalidInputException{
|
public void testDecode() throws InvalidCharacterException, InvalidInputException{
|
||||||
Playfair cipher = new Playfair(true, true, true);
|
Playfair cipher = new Playfair(true, true, true);
|
||||||
@@ -264,254 +514,4 @@ public class TestPlayfair{
|
|||||||
output = cipher.decode(keyword, inputString);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Playfair failed secure mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
assertEquals("Playfair failed secure mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||||
}
|
}
|
||||||
@Test
|
|
||||||
public void testEncode() throws InvalidCharacterException, InvalidInputException{
|
|
||||||
Playfair cipher = new Playfair(true, true, true);
|
|
||||||
|
|
||||||
//Test lowercase encoding
|
|
||||||
String inputString = "hidethegoldinthetrexestump";
|
|
||||||
String keyword = "Playfair Example";
|
|
||||||
String correctOutput = "bmodzbxdnabekudmuixmmouvif";
|
|
||||||
String output = cipher.encode(keyword, inputString);
|
|
||||||
assertEquals("Playfair failed lowercase encoding.", correctOutput, output);
|
|
||||||
//Test uppercase encoding
|
|
||||||
inputString = "HIDETHEGOLDINTHETREXESTUMP";
|
|
||||||
keyword = "Playfair Example";
|
|
||||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
|
||||||
output = cipher.encode(keyword, inputString);
|
|
||||||
assertEquals("Playfair failed uppercase encoding.", 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);
|
|
||||||
|
|
||||||
//Test whitespace encoding
|
|
||||||
inputString = "hide the gold in the trexe stump";
|
|
||||||
keyword = "Playfair Example";
|
|
||||||
correctOutput = "bmod zbx dnab ek udm uixmm ouvif";
|
|
||||||
output = cipher.encode(keyword, inputString);
|
|
||||||
assertEquals("Playfair failed whitespace encoding.", correctOutput, output);
|
|
||||||
|
|
||||||
//Test symbol encoding
|
|
||||||
inputString = "hidethegoldin-the@trexe+stump";
|
|
||||||
keyword = "Playfair Example";
|
|
||||||
correctOutput = "bmodzbxdnabek-udm@uixmm+ouvif";
|
|
||||||
output = cipher.encode(keyword, inputString);
|
|
||||||
assertEquals("Playfair failed symbol encoding.", 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);
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testNoWhitespaceEncode() throws InvalidCharacterException, InvalidInputException{
|
|
||||||
Playfair cipher = new Playfair(true, false, true);
|
|
||||||
|
|
||||||
//Test lowercase encoding
|
|
||||||
String inputString = "hidethegoldinthetrexestump";
|
|
||||||
String keyword = "Playfair Example";
|
|
||||||
String correctOutput = "bmodzbxdnabekudmuixmmouvif";
|
|
||||||
String output = cipher.encode(keyword, inputString);
|
|
||||||
assertEquals("Playfair failed no whitespace lowercase encoding.", correctOutput, output);
|
|
||||||
//Test uppercase encoding
|
|
||||||
inputString = "HIDETHEGOLDINTHETREXESTUMP";
|
|
||||||
keyword = "Playfair Example";
|
|
||||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
|
||||||
output = cipher.encode(keyword, inputString);
|
|
||||||
assertEquals("Playfair failed no whitespace uppercase encoding.", correctOutput, output);
|
|
||||||
//Test odd letter count encoding
|
|
||||||
inputString = "hidethegoldinthetrexestum";
|
|
||||||
keyword = "Playfair Example";
|
|
||||||
correctOutput = "bmodzbxdnabekudmuixmmouviM";
|
|
||||||
output = cipher.encode(keyword, inputString);
|
|
||||||
assertEquals("Playfair failed no whitespace odd letter count encoding.", correctOutput, output);
|
|
||||||
|
|
||||||
//Test whitespace encoding
|
|
||||||
inputString = "hide the gold in the trexe stump";
|
|
||||||
keyword = "Playfair Example";
|
|
||||||
correctOutput = "bmodzbxdnabekudmuixmmouvif";
|
|
||||||
output = cipher.encode(keyword, inputString);
|
|
||||||
assertEquals("Playfair failed no whitespace whitespace encoding.", correctOutput, output);
|
|
||||||
|
|
||||||
//Test symbol encoding
|
|
||||||
inputString = "hidethegoldin-the@trexe+stump";
|
|
||||||
keyword = "Playfair Example";
|
|
||||||
correctOutput = "bmodzbxdnabek-udm@uixmm+ouvif";
|
|
||||||
output = cipher.encode(keyword, inputString);
|
|
||||||
assertEquals("Playfair failed no whitespace symbol encoding.", 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);
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testNoCapitalEncode() throws InvalidCharacterException, InvalidInputException{
|
|
||||||
Playfair cipher = new Playfair(false, true, true);
|
|
||||||
|
|
||||||
//Test lowercase encoding
|
|
||||||
String inputString = "hidethegoldinthetrexestump";
|
|
||||||
String keyword = "Playfair Example";
|
|
||||||
String correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
|
||||||
String output = cipher.encode(keyword, inputString);
|
|
||||||
assertEquals("Playfair failed no capital lowercase encoding.", correctOutput, output);
|
|
||||||
//Test uppercase encoding
|
|
||||||
inputString = "HIDETHEGOLDINTHETREXESTUMP";
|
|
||||||
keyword = "Playfair Example";
|
|
||||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
|
||||||
output = cipher.encode(keyword, inputString);
|
|
||||||
assertEquals("Playfair failed no capital uppercase encoding.", correctOutput, output);
|
|
||||||
//Test odd letter count encoding
|
|
||||||
inputString = "hidethegoldinthetrexestum";
|
|
||||||
keyword = "Playfair Example";
|
|
||||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIM";
|
|
||||||
output = cipher.encode(keyword, inputString);
|
|
||||||
assertEquals("Playfair failed no capital odd letter count encoding.", correctOutput, output);
|
|
||||||
|
|
||||||
//Test whitespace encoding
|
|
||||||
inputString = "hide the gold in the trexe 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);
|
|
||||||
|
|
||||||
//Test symbol encoding
|
|
||||||
inputString = "hidethegoldin-the@trexe+stump";
|
|
||||||
keyword = "Playfair Example";
|
|
||||||
correctOutput = "BMODZBXDNABEK-UDM@UIXMM+OUVIF";
|
|
||||||
output = cipher.encode(keyword, inputString);
|
|
||||||
assertEquals("Playfair failed no capital symbol encoding.", 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);
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testNoSymbolEncode() throws InvalidCharacterException, InvalidInputException{
|
|
||||||
Playfair cipher = new Playfair(true, true, false);
|
|
||||||
|
|
||||||
//Test lowercase encoding
|
|
||||||
String inputString = "hidethegoldinthetrexestump";
|
|
||||||
String keyword = "Playfair Example";
|
|
||||||
String correctOutput = "bmodzbxdnabekudmuixmmouvif";
|
|
||||||
String output = cipher.encode(keyword, inputString);
|
|
||||||
assertEquals("Playfair failed no symbol lowercase encoding.", correctOutput, output);
|
|
||||||
//Test uppercase encoding
|
|
||||||
inputString = "HIDETHEGOLDINTHETREXESTUMP";
|
|
||||||
keyword = "Playfair Example";
|
|
||||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
|
||||||
output = cipher.encode(keyword, inputString);
|
|
||||||
assertEquals("Playfair failed no symbol uppercase encoding.", correctOutput, output);
|
|
||||||
//Test odd letter count encoding
|
|
||||||
inputString = "hidethegoldinthetrexestum";
|
|
||||||
keyword = "Playfair Example";
|
|
||||||
correctOutput = "bmodzbxdnabekudmuixmmouviM";
|
|
||||||
output = cipher.encode(keyword, inputString);
|
|
||||||
assertEquals("Playfair failed no symbol odd letter count encoding.", correctOutput, output);
|
|
||||||
|
|
||||||
//Test whitespace encoding
|
|
||||||
inputString = "hide the gold in the trexe 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);
|
|
||||||
|
|
||||||
//Test symbol encoding
|
|
||||||
inputString = "hidethegoldin-the@trexe+stump";
|
|
||||||
keyword = "Playfair Example";
|
|
||||||
correctOutput = "bmodzbxdnabekudmuixmmouvif";
|
|
||||||
output = cipher.encode(keyword, inputString);
|
|
||||||
assertEquals("Playfair failed no symbol symbol encoding.", 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);
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidCharacterException, InvalidInputException{
|
|
||||||
Playfair cipher = new Playfair(false, false, false);
|
|
||||||
|
|
||||||
//Test lowercase encoding
|
|
||||||
String inputString = "hidethegoldinthetrexestump";
|
|
||||||
String keyword = "Playfair Example";
|
|
||||||
String correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
|
||||||
String output = cipher.encode(keyword, inputString);
|
|
||||||
assertEquals("Playfair failed secure lowercase encoding.", correctOutput, output);
|
|
||||||
//Test uppercase encoding
|
|
||||||
inputString = "HIDETHEGOLDINTHETREXESTUMP";
|
|
||||||
keyword = "Playfair Example";
|
|
||||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
|
||||||
output = cipher.encode(keyword, inputString);
|
|
||||||
assertEquals("Playfair failed secure uppercase encoding.", correctOutput, output);
|
|
||||||
//Test odd letter count encoding
|
|
||||||
inputString = "hidethegoldinthetrexestum";
|
|
||||||
keyword = "Playfair Example";
|
|
||||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIM";
|
|
||||||
output = cipher.encode(keyword, inputString);
|
|
||||||
assertEquals("Playfair failed secure odd letter count encoding.", correctOutput, output);
|
|
||||||
|
|
||||||
//Test whitespace encoding
|
|
||||||
inputString = "hide the gold in the trexe stump";
|
|
||||||
keyword = "Playfair Example";
|
|
||||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
|
||||||
output = cipher.encode(keyword, inputString);
|
|
||||||
assertEquals("Playfair failed secure whitespace encoding.", correctOutput, output);
|
|
||||||
|
|
||||||
//Test symbol encoding
|
|
||||||
inputString = "hidethegoldin-the@trexe+stump";
|
|
||||||
keyword = "Playfair Example";
|
|
||||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
|
||||||
output = cipher.encode(keyword, inputString);
|
|
||||||
assertEquals("Playfair failed secure symbol encoding.", 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);
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,158 +14,6 @@ import org.junit.Test;
|
|||||||
|
|
||||||
|
|
||||||
public class TestPolybiusSquare{
|
public class TestPolybiusSquare{
|
||||||
@Test
|
|
||||||
public void testDecode() throws InvalidCharacterException{
|
|
||||||
PolybiusSquare cipher = new PolybiusSquare(true, true);
|
|
||||||
|
|
||||||
//Test simple decoding
|
|
||||||
String inputString = "121144";
|
|
||||||
String keyword = "";
|
|
||||||
String correctOutput = "BAT";
|
|
||||||
String output = cipher.decode(keyword, inputString);
|
|
||||||
assertEquals("PolybiusSquare failed simple decoding.", 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);
|
|
||||||
|
|
||||||
//Test symbol decoding
|
|
||||||
inputString = "12@11+44-";
|
|
||||||
keyword = "";
|
|
||||||
correctOutput = "B@A+T-";
|
|
||||||
output = cipher.decode(keyword, inputString);
|
|
||||||
assertEquals("PolybiusSquare failed symbol decoding.", 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);
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testNoWhitespaceDecode() throws InvalidCharacterException{
|
|
||||||
PolybiusSquare cipher = new PolybiusSquare(false, true);
|
|
||||||
|
|
||||||
//Test simple decoding
|
|
||||||
String inputString = "121144";
|
|
||||||
String keyword = "";
|
|
||||||
String correctOutput = "BAT";
|
|
||||||
String output = cipher.decode(keyword, inputString);
|
|
||||||
assertEquals("PolybiusSquare failed no whitespace simple decoding.", 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);
|
|
||||||
|
|
||||||
//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);
|
|
||||||
|
|
||||||
//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);
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testNoSymbolDeocde() throws InvalidCharacterException{
|
|
||||||
PolybiusSquare cipher = new PolybiusSquare(true, false);
|
|
||||||
|
|
||||||
//Test simple decoding
|
|
||||||
String inputString = "121144";
|
|
||||||
String keyword = "";
|
|
||||||
String correctOutput = "BAT";
|
|
||||||
String output = cipher.decode(keyword, inputString);
|
|
||||||
assertEquals("PolybiusSquare failed no symbol simple decoding.", 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);
|
|
||||||
|
|
||||||
//Test symbol decoding
|
|
||||||
inputString = "12@11+44-";
|
|
||||||
keyword = "";
|
|
||||||
correctOutput = "BAT";
|
|
||||||
output = cipher.decode(keyword, inputString);
|
|
||||||
assertEquals("PolybiusSquare failed no symbol symbol decoding.", 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);
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void testNoWhitespaceSymbolDecode() throws InvalidCharacterException{
|
|
||||||
PolybiusSquare cipher = new PolybiusSquare(false, false);
|
|
||||||
|
|
||||||
//Test simple decoding
|
|
||||||
String inputString = "121144";
|
|
||||||
String keyword = "";
|
|
||||||
String correctOutput = "BAT";
|
|
||||||
String output = cipher.decode(keyword, inputString);
|
|
||||||
assertEquals("PolybiusSquare failed secure simple decoding.", 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);
|
|
||||||
|
|
||||||
//Test symbol decoding
|
|
||||||
inputString = "12@11+44-";
|
|
||||||
keyword = "";
|
|
||||||
correctOutput = "BAT";
|
|
||||||
output = cipher.decode(keyword, inputString);
|
|
||||||
assertEquals("PolybiusSquare failed secure symbol decoding.", 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);
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncode() throws InvalidCharacterException, InvalidInputException{
|
public void testEncode() throws InvalidCharacterException, InvalidInputException{
|
||||||
PolybiusSquare cipher = new PolybiusSquare(true, true);
|
PolybiusSquare cipher = new PolybiusSquare(true, true);
|
||||||
@@ -318,4 +166,156 @@ public class TestPolybiusSquare{
|
|||||||
output = cipher.encode(keyword, inputString);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("PolybiusSquare failed secure whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
assertEquals("PolybiusSquare failed secure whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||||
}
|
}
|
||||||
|
@Test
|
||||||
|
public void testDecode() throws InvalidCharacterException, InvalidInputException{
|
||||||
|
PolybiusSquare cipher = new PolybiusSquare(true, true);
|
||||||
|
|
||||||
|
//Test simple decoding
|
||||||
|
String inputString = "121144";
|
||||||
|
String keyword = "";
|
||||||
|
String correctOutput = "BAT";
|
||||||
|
String output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("PolybiusSquare failed simple decoding.", 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);
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
inputString = "12@11+44-";
|
||||||
|
keyword = "";
|
||||||
|
correctOutput = "B@A+T-";
|
||||||
|
output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("PolybiusSquare failed symbol decoding.", 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);
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testNoWhitespaceDecode() throws InvalidCharacterException, InvalidInputException{
|
||||||
|
PolybiusSquare cipher = new PolybiusSquare(false, true);
|
||||||
|
|
||||||
|
//Test simple decoding
|
||||||
|
String inputString = "121144";
|
||||||
|
String keyword = "";
|
||||||
|
String correctOutput = "BAT";
|
||||||
|
String output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("PolybiusSquare failed no whitespace simple decoding.", 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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
|
||||||
|
//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);
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testNoSymbolDeocde() throws InvalidCharacterException, InvalidInputException{
|
||||||
|
PolybiusSquare cipher = new PolybiusSquare(true, false);
|
||||||
|
|
||||||
|
//Test simple decoding
|
||||||
|
String inputString = "121144";
|
||||||
|
String keyword = "";
|
||||||
|
String correctOutput = "BAT";
|
||||||
|
String output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("PolybiusSquare failed no symbol simple decoding.", 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);
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
inputString = "12@11+44-";
|
||||||
|
keyword = "";
|
||||||
|
correctOutput = "BAT";
|
||||||
|
output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("PolybiusSquare failed no symbol symbol decoding.", 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);
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testNoWhitespaceSymbolDecode() throws InvalidCharacterException, InvalidInputException{
|
||||||
|
PolybiusSquare cipher = new PolybiusSquare(false, false);
|
||||||
|
|
||||||
|
//Test simple decoding
|
||||||
|
String inputString = "121144";
|
||||||
|
String keyword = "";
|
||||||
|
String correctOutput = "BAT";
|
||||||
|
String output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("PolybiusSquare failed secure simple decoding.", 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);
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
inputString = "12@11+44-";
|
||||||
|
keyword = "";
|
||||||
|
correctOutput = "BAT";
|
||||||
|
output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("PolybiusSquare failed secure symbol decoding.", 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);
|
||||||
|
//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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user