Added encryption options

This commit is contained in:
2021-12-30 16:20:12 -05:00
parent cf183c1bda
commit 05bcb03536
2 changed files with 619 additions and 30 deletions

View File

@@ -1,16 +1,18 @@
//CipherStreamJava/src/main/java/mattrixwv/CipherStreamJava/Caesar.java //CipherStreamJava/src/main/java/mattrixwv/CipherStreamJava/Caesar.java
//Matthew Ellison //Matthew Ellison
// Created: 07-25-21 // Created: 07-25-21
//Modified: 07-25-21 //Modified: 12-25-21
//This is the declaration of the Caesar class //This is the declaration of the Caesar class
package mattrixwv.CipherStreamJava; package mattrixwv.CipherStreamJava;
public class Caesar{ public class Caesar{
public static final String version = "1.0"; //The current version number for the library
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
private int shift; //The amount that you need to shift each letter private int shift; //The amount that you need to shift each letter
private boolean leaveCapitals; //Whether to respect capitals in the output string
private boolean leaveWhitespace; //Whether to respect whitespace in the output string
private boolean leaveSymbols; //Whether to respect whitespace in the output string
//Sets shift and makes sure it is within the propper bounds //Sets shift and makes sure it is within the propper bounds
private void setShift(int shiftAmount){ private void setShift(int shiftAmount){
//If you shift more than 26 you will just be wrapping back around again //If you shift more than 26 you will just be wrapping back around again
@@ -18,6 +20,15 @@ public class Caesar{
} }
//Sets the input string //Sets the input string
private void setInputString(String inputString){ private void setInputString(String inputString){
if(!leaveCapitals){
inputString = inputString.toLowerCase();
}
if(!leaveWhitespace){
inputString = inputString.replaceAll("\\s+", "");
}
if(!leaveSymbols){
inputString = inputString.replaceAll("[^a-zA-Z0-9\\s+]", "");
}
this.inputString = inputString; this.inputString = inputString;
} }
//Encodes the inputString and stores the result in outputString //Encodes the inputString and stores the result in outputString
@@ -63,6 +74,7 @@ public class Caesar{
//If it is an upper case letter shift it and wrap if necessary //If it is an upper case letter shift it and wrap if necessary
if(Character.isUpperCase(currentChar)){ if(Character.isUpperCase(currentChar)){
currentChar -= shift; currentChar -= shift;
//Wrap around if the letter is now out of bounds
if(currentChar < 'A'){ if(currentChar < 'A'){
currentChar += 26; currentChar += 26;
} }
@@ -73,6 +85,7 @@ public class Caesar{
//If it is a lower case letter shift it and wrap if necessary //If it is a lower case letter shift it and wrap if necessary
else if(Character.isLowerCase(currentChar)){ else if(Character.isLowerCase(currentChar)){
currentChar -= shift; currentChar -= shift;
//Wrap around if the letter is now out of bounds
if(currentChar < 'a'){ if(currentChar < 'a'){
currentChar += 26; currentChar += 26;
} }
@@ -92,6 +105,15 @@ public class Caesar{
//Constructor //Constructor
public Caesar(){ public Caesar(){
reset(); reset();
leaveCapitals = false;
leaveWhitespace = false;
leaveSymbols = false;
}
public Caesar(boolean leaveCapitals, boolean leaveWhitespace, boolean leaveSymbols){
reset();
this.leaveCapitals = leaveCapitals;
this.leaveWhitespace = leaveWhitespace;
this.leaveSymbols = leaveSymbols;
} }
//Returns the inputString //Returns the inputString
public String getInputString(){ public String getInputString(){
@@ -105,6 +127,20 @@ public class Caesar{
public String getOutputString(){ public String getOutputString(){
return outputString; return outputString;
} }
//Returns if capitals should be respected in the output
public boolean getLeaveCapitals(){
return leaveCapitals;
}
public void setLeaveCapitals(boolean leaveCapitals){
this.leaveCapitals = leaveCapitals;
}
//Returns if whitespace should be respected in the output
public boolean getLeaveWhitespace(){
return leaveWhitespace;
}
public void setLeaveWhitespace(boolean leaveWhitespace){
this.leaveWhitespace = leaveWhitespace;
}
//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){
reset(); reset();

View File

@@ -1,7 +1,7 @@
//CipherStreamJava/src/main/java/mattrixwv/CipherStreamJava/TestCaesar.java //CipherStreamJava/src/test/java/mattrixwv/CipherStreamJava/TestCaesar.java
//Matthew Ellison //Matthew Ellison
// Created: 07-25-21 // Created: 07-25-21
//Modified: 07-25-21 //Modified: 12-25-21
//These are the tests for the Caesar class //These are the tests for the Caesar class
package mattrixwv.CipherStreamJava; package mattrixwv.CipherStreamJava;
@@ -14,61 +14,614 @@ import org.junit.Test;
public class TestCaesar{ public class TestCaesar{
@Test @Test
public void testDecode(){ public void testDecode(){
Caesar cipher = new Caesar(); Caesar cipher = new Caesar(true, true, true);
//Test 1 //Test lowercase decoding
String input = "def"; String input = "def";
int shift = 3; int shift = 3;
String correctOutput = "abc"; String correctOutput = "abc";
String output = cipher.decode(shift, input); String output = cipher.decode(shift, input);
assertEquals("Caesar Decoding failed the first test", correctOutput, output); assertEquals("Caesar failed lowercase decoding.", correctOutput, output);
//Test 2 //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"; input = "def";
shift = 29; shift = 29;
correctOutput = "abc"; correctOutput = "abc";
output = cipher.decode(shift, input); output = cipher.decode(shift, input);
assertEquals("Caesar Decoding failed the second test", correctOutput, output); assertEquals("Caesar failed out of bounds shift decoding.", correctOutput, output);
//Test out of bounds shift negative decoding
//Test 3 input = "def";
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald"; shift = -23;
shift = -3; correctOutput = "abc";
correctOutput = "The quick brown fox jumps over - the lazy dog";
output = cipher.decode(shift, input); output = cipher.decode(shift, input);
assertEquals("Caesar Decoding failed the third test", correctOutput, output); assertEquals("Caesar failed out of bounds shift negative decoding.", correctOutput, output);
//Test 4
//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"; input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
shift = 23; shift = 23;
correctOutput = "The quick brown fox jumps over - the lazy dog"; correctOutput = "The quick brown fox jumps over - the lazy dog";
output = cipher.decode(shift, input); output = cipher.decode(shift, input);
assertEquals("Caesar Decoding failed the fourth test", correctOutput, output); 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 @Test
public void testEncode(){ public void testEncode(){
//Test 1 Caesar cipher = new Caesar(true, true, true);
Caesar cipher = new Caesar();
//Test lowercase encode
String input = "abc"; String input = "abc";
int shift = 3; int shift = 3;
String correctOutput = "def"; String correctOutput = "def";
String output = cipher.encode(shift, input); String output = cipher.encode(shift, input);
assertEquals("Caesar Encoding failed the first test", correctOutput, output); assertEquals("Caesar failed lowercase encoding.", correctOutput, output);
//Test 2 //Test uppercase encoding
input = "ABC";
shift = 3;
correctOutput = "DEF";
output = cipher.encode(shift, input);
assertEquals("Ceasar failed uppercase encoding.", correctOutput, output);
//Test out of bounds shift encoding
input = "abc"; input = "abc";
shift = 29; shift = 29;
correctOutput = "def"; correctOutput = "def";
output = cipher.encode(shift, input); output = cipher.encode(shift, input);
assertEquals("Caesar Encoding failed the second test - Expected: " + correctOutput + "; actual" + output, correctOutput, output); assertEquals("Caesar failed out of bounds shift encoding.", correctOutput, output);
//Test out of bounds shift encoding negative
//Test 3 input = "abc";
input = "The quick brown fox jumps over - the lazy dog"; shift = -23;
shift = -3; correctOutput = "def";
correctOutput = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
output = cipher.encode(shift, input); output = cipher.encode(shift, input);
assertEquals("Caesar Encoding failed the third test", correctOutput, output); assertEquals("Causar failed out of bounds shift negative encoding.", correctOutput, output);
//Test 4
//Test whitespace encoding
input = "abc def";
shift = 3;
correctOutput = "def ghi";
output = cipher.encode(shift, input);
assertEquals("Caesar failed whitespace encoding.", correctOutput, output);
//Test symbol encoding
input = "abc-def@";
shift = 3;
correctOutput = "def-ghi@";
output = cipher.encode(shift, input);
assertEquals("Caesar failed symbol encoding.", correctOutput, output);
//Test mixed case, whitespace, and symbol encoding
input = "The quick brown fox jumps over - the lazy dog"; input = "The quick brown fox jumps over - the lazy dog";
shift = 23; shift = 23;
correctOutput = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald"; correctOutput = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
output = cipher.encode(shift, input); output = cipher.encode(shift, input);
assertEquals("Caesar Encoding failed the third test", correctOutput, output); assertEquals("Caesar failed mixed case, whitespace, and symbol encoding.", correctOutput, output);
//Test mixed case, whitespace, and symbol encoding with negative shift
input = "The quick brown fox jumps over - the lazy dog";
shift = -3;
correctOutput = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
output = cipher.encode(shift, input);
assertEquals("Caesar failed mixed case, whitespace, and symbol encoding with negative shift.", correctOutput, output);
}
@Test
public void testNoWhitespaceEncode(){
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);
//Test lowercase encode
String input = "abc";
int shift = 3;
String correctOutput = "def";
String output = cipher.encode(shift, input);
assertEquals("Caesar failed no capital lowercase encoding.", correctOutput, output);
//Test uppercase encoding
input = "ABC";
shift = 3;
correctOutput = "def";
output = cipher.encode(shift, input);
assertEquals("Ceasar failed no capital uppercase encoding.", correctOutput, output);
//Test out of bounds shift encoding
input = "abc";
shift = 29;
correctOutput = "def";
output = cipher.encode(shift, input);
assertEquals("Caesar failed no capital 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 capital out of bounds shift negative encoding.", correctOutput, output);
//Test whitespace encoding
input = "abc def";
shift = 3;
correctOutput = "def ghi";
output = cipher.encode(shift, input);
assertEquals("Caesar failed no capital whitespace encoding.", correctOutput, output);
//Test symbol decoding
input = "abc-def@";
shift = 3;
correctOutput = "def-ghi@";
output = cipher.encode(shift, input);
assertEquals("Caesar failed no capital symbol encoding.", correctOutput, output);
//Test mixed case, whitespace, and symbol encoding
input = "The quick brown fox jumps over - the lazy dog";
shift = 23;
correctOutput = "qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
output = cipher.encode(shift, input);
assertEquals("Caesar failed no capital mixed case, whitespace, and symbol ecoding.", correctOutput, output);
//Test mixed case, whitespace, and symbol encoding with negative shift
input = "The quick brown fox jumps over - the lazy dog";
shift = -3;
correctOutput = "qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
output = cipher.encode(shift, input);
assertEquals("Caesar failed no capital mixed case, whitespace, and symbol encoding with negative shift.", correctOutput, output);
}
@Test
public void testNoSymbolEncode(){
Caesar cipher = new Caesar(true, true, false);
//Test lowercase encode
String input = "abc";
int shift = 3;
String correctOutput = "def";
String output = cipher.encode(shift, input);
assertEquals("Caesar failed no symbol lowercase encoding.", correctOutput, output);
//Test uppercase encoding
input = "ABC";
shift = 3;
correctOutput = "DEF";
output = cipher.encode(shift, input);
assertEquals("Ceasar failed no symbol uppercase encoding.", correctOutput, output);
//Test out of bounds shift encoding
input = "abc";
shift = 29;
correctOutput = "def";
output = cipher.encode(shift, input);
assertEquals("Caesar failed no symbol 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 symbol out of bounds shift negative encoding.", correctOutput, output);
//Test whitespace encoding
input = "abc def";
shift = 3;
correctOutput = "def ghi";
output = cipher.encode(shift, input);
assertEquals("Caesar failed no symbol whitespace encoding.", correctOutput, output);
//Test symbol decoding
input = "abc-def@";
shift = 3;
correctOutput = "defghi";
output = cipher.encode(shift, input);
assertEquals("Caesar failed symbol encoding.", correctOutput, output);
//Test mixed case, whitespace, and symbol encoding
input = "The quick brown fox jumps over - the lazy dog";
shift = 23;
correctOutput = "Qeb nrfzh yoltk clu grjmp lsbo qeb ixwv ald";
output = cipher.encode(shift, input);
assertEquals("Caesar failed mixed case, whitespace, and symbol encoding.", correctOutput, output);
//test mixed case, whitespace, and symbol encoding with negative shift
input = "The quick brown fox jumps over - the lazy dog";
shift = -3;
correctOutput = "Qeb nrfzh yoltk clu grjmp lsbo qeb ixwv ald";
output = cipher.encode(shift, input);
assertEquals("Caesar failed mixed case, whitespace, and symbol encoding with negative shift.", correctOutput, output);
}
@Test
public void testNoCapitalWhitespaceSymbolEncode(){
Caesar cipher = new Caesar(false, false, false);
//Test lowercase encode
String input = "abc";
int shift = 3;
String correctOutput = "def";
String output = cipher.encode(shift, input);
assertEquals("Caesar failed secure lowercase encoding.", correctOutput, output);
//Test uppercase encoding
input = "ABC";
shift = 3;
correctOutput = "def";
output = cipher.encode(shift, input);
assertEquals("Ceasar failed secure uppercase encoding.", correctOutput, output);
//Test out of bounds shift encoding
input = "abc";
shift = 29;
correctOutput = "def";
output = cipher.encode(shift, input);
assertEquals("Caesar failed secure out of bounds shift encoding.", correctOutput, output);
//Test out of bounds shift encoding negative
input = "abc";
shift = 29;
correctOutput = "def";
output = cipher.encode(shift, input);
assertEquals("Caesar failed secure out of bounds shift negative encoding.", correctOutput, output);
//Test whitespace encoding
input = "abc def";
shift = 3;
correctOutput = "defghi";
output = cipher.encode(shift, input);
assertEquals("Caesar failed secure whitespace encoding.", correctOutput, output);
//Test symbol encoding
input = "abc-def@";
shift = 3;
correctOutput = "defghi";
output = cipher.encode(shift, input);
assertEquals("Caesar failed secure symbol encoding.", correctOutput, output);
//Test mixed case, whitespace, and symbol encoding
input = "The quick brown fox jumps over - the lazy dog";
shift = 23;
correctOutput = "qebnrfzhyoltkclugrjmplsboqebixwvald";
output = cipher.encode(shift, input);
assertEquals("Caesar failed secure mixed case, whitespace, and symbol encoding.", correctOutput, output);
//Test mixed case, whitespace, and symbol encoding with negative shift
input = "The quick brown fox jumps over - the lazy dog";
shift = -3;
correctOutput = "qebnrfzhyoltkclugrjmplsboqebixwvald";
output = cipher.encode(shift, input);
assertEquals("Caesar failed secure mixed case, whitespace, and symbol encoding with negative shift.", correctOutput, output);
} }
} }