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,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);
}
}