From 05bcb03536a45e7312f9d0549cdeade178ac8fad Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Thu, 30 Dec 2021 16:20:12 -0500 Subject: [PATCH] Added encryption options --- .../mattrixwv/CipherStreamJava/Caesar.java | 40 +- .../CipherStreamJava/TestCaesar.java | 609 +++++++++++++++++- 2 files changed, 619 insertions(+), 30 deletions(-) diff --git a/src/main/java/mattrixwv/CipherStreamJava/Caesar.java b/src/main/java/mattrixwv/CipherStreamJava/Caesar.java index 45e991a..17c72c6 100644 --- a/src/main/java/mattrixwv/CipherStreamJava/Caesar.java +++ b/src/main/java/mattrixwv/CipherStreamJava/Caesar.java @@ -1,16 +1,18 @@ //CipherStreamJava/src/main/java/mattrixwv/CipherStreamJava/Caesar.java //Matthew Ellison // Created: 07-25-21 -//Modified: 07-25-21 +//Modified: 12-25-21 //This is the declaration of the Caesar class package mattrixwv.CipherStreamJava; 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 outputString; //The encoded/decoded string 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 private void setShift(int shiftAmount){ //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 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; } //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(Character.isUpperCase(currentChar)){ currentChar -= shift; + //Wrap around if the letter is now out of bounds if(currentChar < 'A'){ currentChar += 26; } @@ -73,6 +85,7 @@ public class Caesar{ //If it is a lower case letter shift it and wrap if necessary else if(Character.isLowerCase(currentChar)){ currentChar -= shift; + //Wrap around if the letter is now out of bounds if(currentChar < 'a'){ currentChar += 26; } @@ -92,6 +105,15 @@ public class Caesar{ //Constructor public Caesar(){ 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 public String getInputString(){ @@ -105,6 +127,20 @@ public class Caesar{ public String getOutputString(){ 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 public String encode(int shiftAmount, String inputString){ reset(); diff --git a/src/test/java/mattrixwv/CipherStreamJava/TestCaesar.java b/src/test/java/mattrixwv/CipherStreamJava/TestCaesar.java index f9bebb1..a03a164 100644 --- a/src/test/java/mattrixwv/CipherStreamJava/TestCaesar.java +++ b/src/test/java/mattrixwv/CipherStreamJava/TestCaesar.java @@ -1,7 +1,7 @@ -//CipherStreamJava/src/main/java/mattrixwv/CipherStreamJava/TestCaesar.java +//CipherStreamJava/src/test/java/mattrixwv/CipherStreamJava/TestCaesar.java //Matthew Ellison // Created: 07-25-21 -//Modified: 07-25-21 +//Modified: 12-25-21 //These are the tests for the Caesar class package mattrixwv.CipherStreamJava; @@ -14,61 +14,614 @@ import org.junit.Test; public class TestCaesar{ @Test public void testDecode(){ - Caesar cipher = new Caesar(); + Caesar cipher = new Caesar(true, true, true); - //Test 1 + //Test lowercase decoding String input = "def"; int shift = 3; String correctOutput = "abc"; String output = cipher.decode(shift, input); - assertEquals("Caesar Decoding failed the first test", correctOutput, output); - //Test 2 + 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 Decoding failed the second test", correctOutput, output); - - //Test 3 - input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald"; - shift = -3; - correctOutput = "The quick brown fox jumps over - the lazy dog"; + 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 Decoding failed the third test", correctOutput, output); - //Test 4 + 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 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 public void testEncode(){ - //Test 1 - Caesar cipher = new Caesar(); + Caesar cipher = new Caesar(true, true, true); + + //Test lowercase encode String input = "abc"; int shift = 3; String correctOutput = "def"; String output = cipher.encode(shift, input); - assertEquals("Caesar Encoding failed the first test", correctOutput, output); - //Test 2 + assertEquals("Caesar failed lowercase encoding.", correctOutput, output); + //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"; shift = 29; correctOutput = "def"; output = cipher.encode(shift, input); - assertEquals("Caesar Encoding failed the second test - Expected: " + correctOutput + "; actual" + output, correctOutput, output); - - //Test 3 - input = "The quick brown fox jumps over - the lazy dog"; - shift = -3; - correctOutput = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald"; + assertEquals("Caesar failed 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 Encoding failed the third test", correctOutput, output); - //Test 4 + assertEquals("Causar failed 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 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"; shift = 23; correctOutput = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald"; 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); } }