Replaced generic exceptions with custom exceptions
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/Exceptions/InvalidBaseException.java
|
||||
//Mattrixwv
|
||||
// Created: 01-09-22
|
||||
//Modified: 01-09-22
|
||||
package com.mattrixwv.CipherStreamJava.exceptions;
|
||||
|
||||
|
||||
public class InvalidBaseException extends Exception{
|
||||
public InvalidBaseException(){
|
||||
super();
|
||||
}
|
||||
public InvalidBaseException(String message){
|
||||
super(message);
|
||||
}
|
||||
public InvalidBaseException(Throwable error){
|
||||
super(error);
|
||||
}
|
||||
public InvalidBaseException(String message, Throwable error){
|
||||
super(message, error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/Exceptions/InvalidInputException.java
|
||||
//Mattrixwv
|
||||
// Created: 01-09-22
|
||||
//Modified: 01-09-22
|
||||
package com.mattrixwv.CipherStreamJava.exceptions;
|
||||
|
||||
|
||||
public class InvalidInputException extends Exception{
|
||||
public InvalidInputException(){
|
||||
super();
|
||||
}
|
||||
public InvalidInputException(String message){
|
||||
super(message);
|
||||
}
|
||||
public InvalidInputException(Throwable error){
|
||||
super(error);
|
||||
}
|
||||
public InvalidInputException(String message, Throwable error){
|
||||
super(message, error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/Exceptions/InvalidKeywordException.java
|
||||
//Mattrixwv
|
||||
// Created: 01-09-22
|
||||
//Modified: 01-09-22
|
||||
package com.mattrixwv.CipherStreamJava.exceptions;
|
||||
|
||||
|
||||
public class InvalidKeywordException extends Exception{
|
||||
public InvalidKeywordException(){
|
||||
super();
|
||||
}
|
||||
public InvalidKeywordException(String message){
|
||||
super(message);
|
||||
}
|
||||
public InvalidKeywordException(Throwable error){
|
||||
super(error);
|
||||
}
|
||||
public InvalidKeywordException(String message, Throwable error){
|
||||
super(message, error);
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,7 @@ public class Atbash{
|
||||
if(Character.isUpperCase(currentChar)){
|
||||
letterBase = 'A';
|
||||
}
|
||||
//TODO: Test and see if there is a more efficient way to do this
|
||||
output.append((char)(currentChar + 25 - (2 * (currentChar - letterBase))));
|
||||
}
|
||||
//Keep any punctuatio/whitespace the way it is
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
//Modified: 01-04-22
|
||||
package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
||||
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidKeywordException;
|
||||
|
||||
public class Autokey extends Vigenere{
|
||||
//Special rules for setting the strings for encoding
|
||||
private void encodeSet(String key, String input) throws Exception{
|
||||
private void encodeSet(String key, String input) throws InvalidKeywordException{
|
||||
//Set the input
|
||||
setInputString(input);
|
||||
|
||||
@@ -28,7 +30,7 @@ public class Autokey extends Vigenere{
|
||||
setOffset();
|
||||
}
|
||||
//Setting the strings for decoding
|
||||
private void decodeSet(String key, String input) throws Exception{
|
||||
private void decodeSet(String key, String input) throws InvalidKeywordException{
|
||||
//Remove all unneccessary elements from the key
|
||||
setKeyword(key);
|
||||
//Remove all unneccessary elements from the input
|
||||
@@ -36,7 +38,7 @@ public class Autokey extends Vigenere{
|
||||
setInputString(input);
|
||||
}
|
||||
//Decodes the inputString
|
||||
protected String decode() throws Exception{
|
||||
protected String decode() throws InvalidKeywordException{
|
||||
//Decode what the key will allow, add that to the key and continue
|
||||
StringBuilder currentOutput = new StringBuilder();
|
||||
StringBuilder fullOutput = new StringBuilder();
|
||||
@@ -89,13 +91,13 @@ public class Autokey extends Vigenere{
|
||||
super(leaveCapitals, leaveWhitespace, leaveSymbols);
|
||||
}
|
||||
//Encodes inputString using the Autokey cipher
|
||||
public String encode(String key, String input) throws Exception{
|
||||
public String encode(String key, String input) throws InvalidKeywordException{
|
||||
reset();
|
||||
encodeSet(key, input);
|
||||
return encode();
|
||||
}
|
||||
//Decodes inputString using the Autokey cipher
|
||||
public String decode(String key, String input) throws Exception{
|
||||
public String decode(String key, String input) throws InvalidKeywordException{
|
||||
reset();
|
||||
setInputString(input);
|
||||
decodeSet(key, input);
|
||||
|
||||
@@ -7,6 +7,7 @@ package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
||||
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidBaseException;
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidCharacterException;
|
||||
|
||||
|
||||
@@ -30,10 +31,9 @@ public class BaseX{
|
||||
}
|
||||
}
|
||||
//Sets the numeric base
|
||||
private void setBase(int base) throws Exception{
|
||||
private void setBase(int base) throws InvalidBaseException{
|
||||
if(base <= 0){
|
||||
//TODO: Change this to a custom exception. InvalidParameter?
|
||||
throw new Exception("Base cannot be a negative number");
|
||||
throw new InvalidBaseException("Base cannot be a negative number");
|
||||
}
|
||||
|
||||
this.base = base;
|
||||
@@ -79,11 +79,11 @@ public class BaseX{
|
||||
}
|
||||
|
||||
//Constructor
|
||||
public BaseX() throws Exception{
|
||||
public BaseX() throws InvalidBaseException{
|
||||
reset();
|
||||
setBase(2);
|
||||
}
|
||||
public BaseX(int base) throws Exception{
|
||||
public BaseX(int base) throws InvalidBaseException{
|
||||
reset();
|
||||
setBase(base);
|
||||
}
|
||||
@@ -105,7 +105,7 @@ public class BaseX{
|
||||
setInputStringEncode(inputString);
|
||||
return encode();
|
||||
}
|
||||
public String encode(int base, String inputString) throws Exception{
|
||||
public String encode(int base, String inputString) throws InvalidBaseException{
|
||||
reset();
|
||||
setBase(base);
|
||||
setInputStringEncode(inputString);
|
||||
@@ -117,7 +117,7 @@ public class BaseX{
|
||||
setInputStringDecode(inputString);
|
||||
return decode();
|
||||
}
|
||||
public String decode(int base, String inputString) throws Exception{
|
||||
public String decode(int base, String inputString) throws InvalidBaseException, InvalidCharacterException{
|
||||
reset();
|
||||
setBase(base);
|
||||
setInputStringDecode(inputString);
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/Vigenere.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-25-21
|
||||
//Modified: 01-04-22
|
||||
//Modified: 01-09-22
|
||||
package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
public class Vigenere{
|
||||
protected String inputString; //This is the string that needs encoded/decoded
|
||||
@@ -42,7 +44,7 @@ public class Vigenere{
|
||||
this.inputString = inputString;
|
||||
}
|
||||
//Sets keyword
|
||||
protected void setKeyword(String key) throws Exception{
|
||||
protected void setKeyword(String key) throws InvalidKeywordException{
|
||||
//Convert all letters to uppercase
|
||||
key = key.toUpperCase();
|
||||
//Remove all characters except capital letters
|
||||
@@ -55,7 +57,7 @@ public class Vigenere{
|
||||
setOffset();
|
||||
//If after all the eliminating of unusable characters the keyword is empty throw an exception
|
||||
if(keyword == ""){
|
||||
throw new Exception("The keyword cannot be empty");
|
||||
throw new InvalidKeywordException("The keyword cannot be empty");
|
||||
}
|
||||
}
|
||||
//Encodes inputString and stores the result in outputString
|
||||
@@ -93,7 +95,7 @@ public class Vigenere{
|
||||
return outputString;
|
||||
}
|
||||
//Decodes inputString and stores the result in outputString
|
||||
protected String decode() throws Exception{
|
||||
protected String decode() throws InvalidKeywordException{
|
||||
StringBuilder output = new StringBuilder();
|
||||
|
||||
//Step through every character in the inputString and advance it the correct amount, according to offset
|
||||
@@ -158,14 +160,14 @@ public class Vigenere{
|
||||
return offset;
|
||||
}
|
||||
//Encodes input using key and returns the result
|
||||
public String encode(String key, String input) throws Exception{
|
||||
public String encode(String key, String input) throws InvalidKeywordException{
|
||||
reset();
|
||||
setKeyword(key);
|
||||
setInputString(input);
|
||||
return encode();
|
||||
}
|
||||
//Decodes input using key and returns the result
|
||||
public String decode(String key, String input) throws Exception{
|
||||
public String decode(String key, String input) throws InvalidKeywordException{
|
||||
reset();
|
||||
setKeyword(key);
|
||||
setInputString(input);
|
||||
@@ -173,7 +175,9 @@ public class Vigenere{
|
||||
}
|
||||
//Makes sure all of the variables are empty
|
||||
public void reset(){
|
||||
inputString = outputString = keyword = "";
|
||||
inputString = "";
|
||||
outputString = "";
|
||||
keyword = "";
|
||||
offset.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/Playfair.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-30-21
|
||||
//Modified: 01-04-22
|
||||
//Modified: 01-09-22
|
||||
package com.mattrixwv.CipherStreamJava.polySubstitution;
|
||||
|
||||
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
|
||||
|
||||
|
||||
public class Playfair{
|
||||
@@ -175,7 +176,7 @@ public class Playfair{
|
||||
createGrid();
|
||||
}
|
||||
//Returns the location of the given character in the grid
|
||||
private CharLocation findChar(char letter) throws Exception{
|
||||
private CharLocation findChar(char letter) throws InvalidInputException{
|
||||
for(int row = 0;row < grid.length;++row){
|
||||
for(int col = 0;col < grid[row].length;++col){
|
||||
if(grid[row][col] == letter){
|
||||
@@ -184,7 +185,7 @@ public class Playfair{
|
||||
}
|
||||
}
|
||||
//If it was not found something went wrong
|
||||
throw new Exception("That character was not found in the grid. ERROR");
|
||||
throw new InvalidInputException("The character '" + letter + "' was not found in the grid");
|
||||
}
|
||||
//Returns the location in the grid of x and y, adjusting for out of bounds
|
||||
private char getGridChar(int x, int y){
|
||||
@@ -214,7 +215,7 @@ public class Playfair{
|
||||
outputString = fullOutput.toString();
|
||||
}
|
||||
//Encodes inputString using the Playfair cipher and stores the result in outputString
|
||||
private String encode() throws Exception{
|
||||
private String encode() throws InvalidInputException{
|
||||
StringBuilder output = new StringBuilder();
|
||||
int inputCnt = 0;
|
||||
String cleanString = getPreparedInputString();
|
||||
@@ -253,7 +254,7 @@ public class Playfair{
|
||||
return outputString;
|
||||
}
|
||||
//Decodes inputString using the Playfair cipher and stores the result in outputString
|
||||
private String decode() throws Exception{
|
||||
private String decode() throws InvalidInputException{
|
||||
StringBuilder output = new StringBuilder();
|
||||
int inputCnt = 0;
|
||||
String cleanString = getPreparedInputString();
|
||||
@@ -320,14 +321,14 @@ public class Playfair{
|
||||
setDoubled(doubled);
|
||||
}
|
||||
//Sets the keyword and inputString and encodes the message
|
||||
public String encode(String keyword, String input) throws InvalidCharacterException, Exception{
|
||||
public String encode(String keyword, String input) throws InvalidCharacterException, InvalidInputException{
|
||||
reset();
|
||||
setKeyword(keyword);
|
||||
setInputString(input, true);
|
||||
return encode();
|
||||
}
|
||||
//Sets the keyword and inputString and decodes the message
|
||||
public String decode(String keyword, String input) throws InvalidCharacterException, Exception{
|
||||
public String decode(String keyword, String input) throws InvalidCharacterException, InvalidInputException{
|
||||
reset();
|
||||
setKeyword(keyword);
|
||||
setInputString(input, false);
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/PolybiusSquare.java
|
||||
//Mattrixwv
|
||||
// Created: 01-04-22
|
||||
//Modified: 01-04-22
|
||||
//Modified: 01-09-22
|
||||
package com.mattrixwv.CipherStreamJava.polySubstitution;
|
||||
|
||||
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
|
||||
|
||||
|
||||
public class PolybiusSquare{
|
||||
@@ -145,7 +146,7 @@ public class PolybiusSquare{
|
||||
createGrid();
|
||||
}
|
||||
//Returns the location of the given charcter in the grid
|
||||
public CharLocation findChar(char letter) throws Exception{
|
||||
public CharLocation findChar(char letter) throws InvalidInputException{
|
||||
for(int row = 0;row < grid.length;++row){
|
||||
for(int col = 0;col < grid[row].length;++col){
|
||||
if(grid[row][col] == letter){
|
||||
@@ -154,7 +155,7 @@ public class PolybiusSquare{
|
||||
}
|
||||
}
|
||||
//If it was not found something went wrong
|
||||
throw new Exception("That character was not found in the grid. ERROR");
|
||||
throw new InvalidInputException("The character '" + letter + "' was not found in the grid");
|
||||
}
|
||||
//Adds characters that aren't letters to the output
|
||||
public void addCharactersToCleanStringEncode(String cleanString){
|
||||
@@ -190,7 +191,7 @@ public class PolybiusSquare{
|
||||
outputString = fullOutput.toString();
|
||||
}
|
||||
//Encodes inputString using the Playfair cipher and stores the result in outputString
|
||||
private String encode() throws Exception{
|
||||
private String encode() throws InvalidInputException{
|
||||
StringBuilder output = new StringBuilder();
|
||||
String cleanString = getPreparedInputStringEncoding();
|
||||
for(int cnt = 0;cnt < cleanString.length();++cnt){
|
||||
@@ -256,10 +257,10 @@ public class PolybiusSquare{
|
||||
this.leaveSymbols = leaveSymbols;
|
||||
}
|
||||
//Sets the keyword and inputString and encodes the message
|
||||
public String encode(String inputString) throws InvalidCharacterException, Exception{
|
||||
public String encode(String inputString) throws InvalidCharacterException, InvalidInputException{
|
||||
return encode("", inputString);
|
||||
}
|
||||
public String encode(String keyword, String inputString) throws InvalidCharacterException, Exception{
|
||||
public String encode(String keyword, String inputString) throws InvalidCharacterException, InvalidInputException{
|
||||
reset();
|
||||
setKeyword(keyword);
|
||||
setInputStringEncoding(inputString);
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/TestAutokey.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-26-21
|
||||
//Modified: 01-04-22
|
||||
//Modified: 01-09-22
|
||||
package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidKeywordException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class TestAutokey{
|
||||
@Test
|
||||
public void testDecode() throws Exception{
|
||||
public void testDecode() throws InvalidKeywordException{
|
||||
Autokey cipher = new Autokey(true, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -59,7 +61,7 @@ public class TestAutokey{
|
||||
assertEquals("Autokey failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceDecode() throws Exception{
|
||||
public void testNoWhitespaceDecode() throws InvalidKeywordException{
|
||||
Autokey cipher = new Autokey(true, false, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -106,7 +108,7 @@ public class TestAutokey{
|
||||
assertEquals("Autokey failed no whitespace mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalDecode() throws Exception{
|
||||
public void testNoCapitalDecode() throws InvalidKeywordException{
|
||||
Autokey cipher = new Autokey(false, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -153,7 +155,7 @@ public class TestAutokey{
|
||||
assertEquals("Autokey failed no capital mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolDecode() throws Exception{
|
||||
public void testNoSymbolDecode() throws InvalidKeywordException{
|
||||
Autokey cipher = new Autokey(true, true, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -200,7 +202,7 @@ public class TestAutokey{
|
||||
assertEquals("Autokey failed no symbol mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolDecode() throws Exception{
|
||||
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidKeywordException{
|
||||
Autokey cipher = new Autokey(false, false, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -249,7 +251,7 @@ public class TestAutokey{
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncode() throws Exception{
|
||||
public void testEncode() throws InvalidKeywordException{
|
||||
Autokey cipher = new Autokey(true, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -296,7 +298,7 @@ public class TestAutokey{
|
||||
assertEquals("Autokey failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceEncode() throws Exception{
|
||||
public void testNoWhitespaceEncode() throws InvalidKeywordException{
|
||||
Autokey cipher = new Autokey(true, false, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -343,7 +345,7 @@ public class TestAutokey{
|
||||
assertEquals("Autokey failed no whitespace mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalEncode() throws Exception{
|
||||
public void testNoCapitalEncode() throws InvalidKeywordException{
|
||||
Autokey cipher = new Autokey(false, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -390,7 +392,7 @@ public class TestAutokey{
|
||||
assertEquals("Autokey failed no capital mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolEncode() throws Exception{
|
||||
public void testNoSymbolEncode() throws InvalidKeywordException{
|
||||
Autokey cipher = new Autokey(true, true, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -437,7 +439,7 @@ public class TestAutokey{
|
||||
assertEquals("Autokey failed no symbol mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolEncode() throws Exception{
|
||||
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidKeywordException{
|
||||
Autokey cipher = new Autokey(false, false, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -486,7 +488,7 @@ public class TestAutokey{
|
||||
|
||||
|
||||
@Test
|
||||
public void testKeyword() throws Exception{
|
||||
public void testKeyword() throws InvalidKeywordException{
|
||||
Autokey cipher = new Autokey();
|
||||
|
||||
//Test keyword with whitespace
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/monoSubstitution/TestBaseX.java
|
||||
//Mattrixwv
|
||||
// Created: 01-08-22
|
||||
//Modified: 01-08-22
|
||||
//Modified: 01-09-22
|
||||
package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidBaseException;
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidCharacterException;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -14,7 +15,7 @@ import org.junit.Test;
|
||||
|
||||
public class TestBaseX{
|
||||
@Test
|
||||
public void testBinaryDecode() throws InvalidCharacterException, Exception{
|
||||
public void testBinaryDecode() throws InvalidCharacterException, InvalidBaseException{
|
||||
BaseX cipher = new BaseX();
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -47,7 +48,7 @@ public class TestBaseX{
|
||||
assertEquals("Binary failed binary mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testOctalDecode() throws InvalidCharacterException, Exception{
|
||||
public void testOctalDecode() throws InvalidCharacterException, InvalidBaseException{
|
||||
BaseX cipher = new BaseX(8);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -80,7 +81,7 @@ public class TestBaseX{
|
||||
assertEquals("Binary failed octal mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testDecimalDecode() throws InvalidCharacterException, Exception{
|
||||
public void testDecimalDecode() throws InvalidCharacterException, InvalidBaseException{
|
||||
BaseX cipher = new BaseX(10);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -113,7 +114,7 @@ public class TestBaseX{
|
||||
assertEquals("Binary failed decimal mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testHexDecode() throws InvalidCharacterException, Exception{
|
||||
public void testHexDecode() throws InvalidCharacterException, InvalidBaseException{
|
||||
BaseX cipher = new BaseX(16);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -146,7 +147,7 @@ public class TestBaseX{
|
||||
assertEquals("Binary failed hex mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testBinaryEncode() throws Exception{
|
||||
public void testBinaryEncode() throws InvalidBaseException{
|
||||
BaseX cipher = new BaseX();
|
||||
|
||||
//Test lowercase encoding
|
||||
@@ -179,7 +180,7 @@ public class TestBaseX{
|
||||
assertEquals("Binary failed binary mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testOctalEncode() throws Exception{
|
||||
public void testOctalEncode() throws InvalidBaseException{
|
||||
BaseX cipher = new BaseX(8);
|
||||
|
||||
//Test lowercase encoding
|
||||
@@ -212,7 +213,7 @@ public class TestBaseX{
|
||||
assertEquals("Binary failed octal mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testDecimalEncode() throws Exception{
|
||||
public void testDecimalEncode() throws InvalidBaseException{
|
||||
BaseX cipher = new BaseX(10);
|
||||
|
||||
//Test lowercase encoding
|
||||
@@ -245,7 +246,7 @@ public class TestBaseX{
|
||||
assertEquals("Binary failed decimal mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testHexEncode() throws Exception{
|
||||
public void testHexEncode() throws InvalidBaseException{
|
||||
BaseX cipher = new BaseX(16);
|
||||
|
||||
//Test lowercase encoding
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/TestVigenere.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-25-21
|
||||
//Modified: 01-04-22
|
||||
//Modified: 01-09-22
|
||||
package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidKeywordException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class TestVigenere{
|
||||
@Test
|
||||
public void testDecode() throws Exception{
|
||||
public void testDecode() throws InvalidKeywordException{
|
||||
Vigenere cipher = new Vigenere(true, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -59,7 +61,7 @@ public class TestVigenere{
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceDecode() throws Exception{
|
||||
public void testNoWhitespaceDecode() throws InvalidKeywordException{
|
||||
Vigenere cipher = new Vigenere(true, false, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -106,7 +108,7 @@ public class TestVigenere{
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalDecode() throws Exception{
|
||||
public void testNoCapitalDecode() throws InvalidKeywordException{
|
||||
Vigenere cipher = new Vigenere(false, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -153,7 +155,7 @@ public class TestVigenere{
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolDecode() throws Exception{
|
||||
public void testNoSymbolDecode() throws InvalidKeywordException{
|
||||
Vigenere cipher = new Vigenere(true, true, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -200,7 +202,7 @@ public class TestVigenere{
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolDecode() throws Exception{
|
||||
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidKeywordException{
|
||||
Vigenere cipher = new Vigenere(false, false, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -249,7 +251,7 @@ public class TestVigenere{
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncode() throws Exception{
|
||||
public void testEncode() throws InvalidKeywordException{
|
||||
Vigenere cipher = new Vigenere(true, true, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
@@ -296,7 +298,7 @@ public class TestVigenere{
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceEncode() throws Exception{
|
||||
public void testNoWhitespaceEncode() throws InvalidKeywordException{
|
||||
Vigenere cipher = new Vigenere(true, false, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
@@ -343,7 +345,7 @@ public class TestVigenere{
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalEncode() throws Exception{
|
||||
public void testNoCapitalEncode() throws InvalidKeywordException{
|
||||
Vigenere cipher = new Vigenere(false, true, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
@@ -390,7 +392,7 @@ public class TestVigenere{
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolEncode() throws Exception{
|
||||
public void testNoSymbolEncode() throws InvalidKeywordException{
|
||||
Vigenere cipher = new Vigenere(true, true, false);
|
||||
|
||||
//Test lowercase encoding
|
||||
@@ -437,7 +439,7 @@ public class TestVigenere{
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolEncode() throws Exception{
|
||||
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidKeywordException{
|
||||
Vigenere cipher = new Vigenere(false, false, false);
|
||||
|
||||
//Test lowercase encoding
|
||||
@@ -486,7 +488,7 @@ public class TestVigenere{
|
||||
|
||||
|
||||
@Test
|
||||
public void testKeyword() throws Exception{
|
||||
public void testKeyword() throws InvalidKeywordException{
|
||||
Vigenere cipher = new Vigenere();
|
||||
|
||||
//Test keyword with whitespace
|
||||
|
||||
@@ -8,13 +8,14 @@ package com.mattrixwv.CipherStreamJava.polySubstitution;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class TestPlayfair{
|
||||
@Test
|
||||
public void testDecode() throws InvalidCharacterException, Exception{
|
||||
public void testDecode() throws InvalidCharacterException, InvalidInputException{
|
||||
Playfair cipher = new Playfair(true, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -64,7 +65,7 @@ public class TestPlayfair{
|
||||
assertEquals("Playfair failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceDecode() throws InvalidCharacterException, Exception{
|
||||
public void testNoWhitespaceDecode() throws InvalidCharacterException, InvalidInputException{
|
||||
Playfair cipher = new Playfair(true, false, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -114,7 +115,7 @@ public class TestPlayfair{
|
||||
assertEquals("Playfair failed no whitespace mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalDecode() throws InvalidCharacterException, Exception{
|
||||
public void testNoCapitalDecode() throws InvalidCharacterException, InvalidInputException{
|
||||
Playfair cipher = new Playfair(false, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -164,7 +165,7 @@ public class TestPlayfair{
|
||||
assertEquals("Playfair failed no capital mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolDecode() throws InvalidCharacterException, Exception{
|
||||
public void testNoSymbolDecode() throws InvalidCharacterException, InvalidInputException{
|
||||
Playfair cipher = new Playfair(true, true, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -214,7 +215,7 @@ public class TestPlayfair{
|
||||
assertEquals("Playfair failed no symbol mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidCharacterException, Exception{
|
||||
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidCharacterException, InvalidInputException{
|
||||
Playfair cipher = new Playfair(false, false, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -264,7 +265,7 @@ public class TestPlayfair{
|
||||
assertEquals("Playfair failed secure mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testEncode() throws InvalidCharacterException, Exception{
|
||||
public void testEncode() throws InvalidCharacterException, InvalidInputException{
|
||||
Playfair cipher = new Playfair(true, true, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
@@ -314,7 +315,7 @@ public class TestPlayfair{
|
||||
assertEquals("Playfair failed mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceEncode() throws InvalidCharacterException, Exception{
|
||||
public void testNoWhitespaceEncode() throws InvalidCharacterException, InvalidInputException{
|
||||
Playfair cipher = new Playfair(true, false, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
@@ -364,7 +365,7 @@ public class TestPlayfair{
|
||||
assertEquals("Playfair failed no whitespace mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalEncode() throws InvalidCharacterException, Exception{
|
||||
public void testNoCapitalEncode() throws InvalidCharacterException, InvalidInputException{
|
||||
Playfair cipher = new Playfair(false, true, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
@@ -414,7 +415,7 @@ public class TestPlayfair{
|
||||
assertEquals("Playfair failed no capital mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolEncode() throws InvalidCharacterException, Exception{
|
||||
public void testNoSymbolEncode() throws InvalidCharacterException, InvalidInputException{
|
||||
Playfair cipher = new Playfair(true, true, false);
|
||||
|
||||
//Test lowercase encoding
|
||||
@@ -464,7 +465,7 @@ public class TestPlayfair{
|
||||
assertEquals("Playfair failed no symbol mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidCharacterException, Exception{
|
||||
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidCharacterException, InvalidInputException{
|
||||
Playfair cipher = new Playfair(false, false, false);
|
||||
|
||||
//Test lowercase encoding
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/TestPolybiusSquare.java
|
||||
//Mattrixwv
|
||||
// Created: 01-04-22
|
||||
//Modified: 01-04-22
|
||||
//Modified: 01-09-22
|
||||
package com.mattrixwv.CipherStreamJava.polySubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -166,7 +167,7 @@ public class TestPolybiusSquare{
|
||||
assertEquals("PolybiusSquare failed secure whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testEncode() throws InvalidCharacterException, Exception{
|
||||
public void testEncode() throws InvalidCharacterException, InvalidInputException{
|
||||
PolybiusSquare cipher = new PolybiusSquare(true, true);
|
||||
|
||||
//Test simple encoding
|
||||
@@ -204,7 +205,7 @@ public class TestPolybiusSquare{
|
||||
assertEquals("PolybiusSquare failed whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceEncode() throws InvalidCharacterException, Exception{
|
||||
public void testNoWhitespaceEncode() throws InvalidCharacterException, InvalidInputException{
|
||||
PolybiusSquare cipher = new PolybiusSquare(false, true);
|
||||
|
||||
//Test simple encoding
|
||||
@@ -242,7 +243,7 @@ public class TestPolybiusSquare{
|
||||
assertEquals("PolybiusSquare failed no whitespace whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolEncode() throws InvalidCharacterException, Exception{
|
||||
public void testNoSymbolEncode() throws InvalidCharacterException, InvalidInputException{
|
||||
PolybiusSquare cipher = new PolybiusSquare(true, false);
|
||||
|
||||
//Test simple encoding
|
||||
@@ -280,7 +281,7 @@ public class TestPolybiusSquare{
|
||||
assertEquals("PolybiusSquare failed no symbol whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceSymbolEncode() throws InvalidCharacterException, Exception{
|
||||
public void testNoWhitespaceSymbolEncode() throws InvalidCharacterException, InvalidInputException{
|
||||
PolybiusSquare cipher = new PolybiusSquare(false, false);
|
||||
|
||||
//Test simple encoding
|
||||
|
||||
Reference in New Issue
Block a user