Moved classes to website appropriate directory
This commit is contained in:
376
src/test/java/com/mattrixwv/CipherStreamJava/TestAtbash.java
Normal file
376
src/test/java/com/mattrixwv/CipherStreamJava/TestAtbash.java
Normal file
@@ -0,0 +1,376 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/TestAtbash.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-25-21
|
||||
//Modified: 01-04-22
|
||||
package com.mattrixwv.CipherStreamJava;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class TestAtbash{
|
||||
@Test
|
||||
public void testDecode(){
|
||||
Atbash cipher = new Atbash(true, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String input = "zyx";
|
||||
String correctOutput = "abc";
|
||||
String output = cipher.decode(input);
|
||||
assertEquals("Atbash failed lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "ZYX";
|
||||
correctOutput = "ABC";
|
||||
output = cipher.decode(input);
|
||||
assertEquals("Atbash failed uppercase decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
input = "zyx wvu";
|
||||
correctOutput = "abc def";
|
||||
output = cipher.decode(input);
|
||||
assertEquals("Atbash failed whitespace decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "zyx-wvu@";
|
||||
correctOutput = "abc-def@";
|
||||
output = cipher.decode(input);
|
||||
assertEquals("Atbash failed symbol decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
input = "Gsv jfrxp yildm ulc qfnkh levi - gsv ozab wlt";
|
||||
correctOutput = "The quick brown fox jumps over - the lazy dog";
|
||||
output = cipher.decode(input);
|
||||
assertEquals("Atbash failed mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceDecode(){
|
||||
Atbash cipher = new Atbash(true, false, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String input = "zyx";
|
||||
String correctOutput = "abc";
|
||||
String output = cipher.decode(input);
|
||||
assertEquals("Atbash failed no whitespace lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "ZYX";
|
||||
correctOutput = "ABC";
|
||||
output = cipher.decode(input);
|
||||
assertEquals("Atbash failed no whitespace uppercase decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
input = "zyx wvu";
|
||||
correctOutput = "abcdef";
|
||||
output = cipher.decode(input);
|
||||
assertEquals("Atbash failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "zyx-wvu@";
|
||||
correctOutput = "abc-def@";
|
||||
output = cipher.decode(input);
|
||||
assertEquals("Atbash failed no whitespace symbol decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
input = "Gsv jfrxp yildm ulc qfnkh levi - gsv ozab wlt";
|
||||
correctOutput = "Thequickbrownfoxjumpsover-thelazydog";
|
||||
output = cipher.decode(input);
|
||||
assertEquals("Atbash failed no whitespace mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalDecode(){
|
||||
Atbash cipher = new Atbash(false, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String input = "zyx";
|
||||
String correctOutput = "abc";
|
||||
String output = cipher.decode(input);
|
||||
assertEquals("Atbash failed no capital lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "ZYX";
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(input);
|
||||
assertEquals("Atbash failed no capital uppercase decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
input = "zyx wvu";
|
||||
correctOutput = "abc def";
|
||||
output = cipher.decode(input);
|
||||
assertEquals("Atbash failed no capital whitespace decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "zyx-wvu@";
|
||||
correctOutput = "abc-def@";
|
||||
output = cipher.decode(input);
|
||||
assertEquals("Atbash failed no capital symbol decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
input = "Gsv jfrxp yildm ulc qfnkh levi - gsv ozab wlt";
|
||||
correctOutput = "the quick brown fox jumps over - the lazy dog";
|
||||
output = cipher.decode(input);
|
||||
assertEquals("Atbash failed no capital mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolDecode(){
|
||||
Atbash cipher = new Atbash(true, true, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
String input = "zyx";
|
||||
String correctOutput = "abc";
|
||||
String output = cipher.decode(input);
|
||||
assertEquals("Atbash failed no symbol lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "ZYX";
|
||||
correctOutput = "ABC";
|
||||
output = cipher.decode(input);
|
||||
assertEquals("Atbash failed no symbol uppercase decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
input = "zyx wvu";
|
||||
correctOutput = "abc def";
|
||||
output = cipher.decode(input);
|
||||
assertEquals("Atbash failed no symbol whitespace decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "zyx-wvu@";
|
||||
correctOutput = "abcdef";
|
||||
output = cipher.decode(input);
|
||||
assertEquals("Atbash failed no symbol symbol decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
input = "Gsv jfrxp yildm ulc qfnkh levi - gsv ozab wlt";
|
||||
correctOutput = "The quick brown fox jumps over the lazy dog";
|
||||
output = cipher.decode(input);
|
||||
assertEquals("Atbash failed no symbol mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalwhitesapceSymbolDecode(){
|
||||
Atbash cipher = new Atbash(false, false, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
String input = "zyx";
|
||||
String correctOutput = "abc";
|
||||
String output = cipher.decode(input);
|
||||
assertEquals("Atbash failed secure lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "ZYX";
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(input);
|
||||
assertEquals("Atbash failed secure uppercase decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
input = "zyx wvu";
|
||||
correctOutput = "abcdef";
|
||||
output = cipher.decode(input);
|
||||
assertEquals("Atbash failed secure whitespace decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "zyx-wvu@";
|
||||
correctOutput = "abcdef";
|
||||
output = cipher.decode(input);
|
||||
assertEquals("Atbash failed secure symbol decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
input = "Gsv jfrxp yildm ulc qfnkh levi - gsv ozab wlt";
|
||||
correctOutput = "thequickbrownfoxjumpsoverthelazydog";
|
||||
output = cipher.decode(input);
|
||||
assertEquals("Atbash failed secure mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncode(){
|
||||
Atbash cipher = new Atbash(true, true, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
String input = "abc";
|
||||
String correctOutput = "zyx";
|
||||
String output = cipher.encode(input);
|
||||
assertEquals("Atbash failed lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
input = "ABC";
|
||||
correctOutput = "ZYX";
|
||||
output = cipher.encode(input);
|
||||
assertEquals("Atbash failed uppercase encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace encoding
|
||||
input = "abc def";
|
||||
correctOutput = "zyx wvu";
|
||||
output = cipher.encode(input);
|
||||
assertEquals("Atbash failed whitespace encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "abc-def@";
|
||||
correctOutput = "zyx-wvu@";
|
||||
output = cipher.encode(input);
|
||||
assertEquals("Atbash failed symbol encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
input = "The quick brown fox jumps over - the lazy dog";
|
||||
correctOutput = "Gsv jfrxp yildm ulc qfnkh levi - gsv ozab wlt";
|
||||
output = cipher.encode(input);
|
||||
assertEquals("Atbash failed mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceEncode(){
|
||||
Atbash cipher = new Atbash(true, false, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
String input = "abc";
|
||||
String correctOutput = "zyx";
|
||||
String output = cipher.encode(input);
|
||||
assertEquals("Atbash failed no whitespace lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
input = "ABC";
|
||||
correctOutput = "ZYX";
|
||||
output = cipher.encode(input);
|
||||
assertEquals("Atbash failed no whitespace uppercase encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace encoding
|
||||
input = "abc def";
|
||||
correctOutput = "zyxwvu";
|
||||
output = cipher.encode(input);
|
||||
assertEquals("Atbash failed no whitespace whitespace encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "abc-def@";
|
||||
correctOutput = "zyx-wvu@";
|
||||
output = cipher.encode(input);
|
||||
assertEquals("Atbash failed no whitespace symbol encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
input = "The quick brown fox jumps over - the lazy dog";
|
||||
correctOutput = "Gsvjfrxpyildmulcqfnkhlevi-gsvozabwlt";
|
||||
output = cipher.encode(input);
|
||||
assertEquals("Atbash failed no whitespace mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalEncode(){
|
||||
Atbash cipher = new Atbash(false, true, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
String input = "abc";
|
||||
String correctOutput = "zyx";
|
||||
String output = cipher.encode(input);
|
||||
assertEquals("Atbash failed no capital lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
input = "ABC";
|
||||
correctOutput = "zyx";
|
||||
output = cipher.encode(input);
|
||||
assertEquals("Atbash failed no capital uppercase encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace encoding
|
||||
input = "abc def";
|
||||
correctOutput = "zyx wvu";
|
||||
output = cipher.encode(input);
|
||||
assertEquals("Atbash failed no capital whitespace encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "abc-def@";
|
||||
correctOutput = "zyx-wvu@";
|
||||
output = cipher.encode(input);
|
||||
assertEquals("Atbash failed no capital symbol encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
input = "The quick brown fox jumps over - the lazy dog";
|
||||
correctOutput = "gsv jfrxp yildm ulc qfnkh levi - gsv ozab wlt";
|
||||
output = cipher.encode(input);
|
||||
assertEquals("Atbash failed no capital mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolEncode(){
|
||||
Atbash cipher = new Atbash(true, true, false);
|
||||
|
||||
//Test lowercase encoding
|
||||
String input = "abc";
|
||||
String correctOutput = "zyx";
|
||||
String output = cipher.encode(input);
|
||||
assertEquals("Atbash failed no symbol lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
input = "ABC";
|
||||
correctOutput = "ZYX";
|
||||
output = cipher.encode(input);
|
||||
assertEquals("Atbash failed no symbol uppercase encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace encoding
|
||||
input = "abc def";
|
||||
correctOutput = "zyx wvu";
|
||||
output = cipher.encode(input);
|
||||
assertEquals("Atbash failed no symbol whitespace encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "abc-def@";
|
||||
correctOutput = "zyxwvu";
|
||||
output = cipher.encode(input);
|
||||
assertEquals("Atbash failed no symbol symbol encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
input = "The quick brown fox jumps over - the lazy dog";
|
||||
correctOutput = "Gsv jfrxp yildm ulc qfnkh levi gsv ozab wlt";
|
||||
output = cipher.encode(input);
|
||||
assertEquals("Atbash failed no symbol mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolEncode(){
|
||||
Atbash cipher = new Atbash(false, false, false);
|
||||
|
||||
//Test lowercase encoding
|
||||
String input = "abc";
|
||||
String correctOutput = "zyx";
|
||||
String output = cipher.encode(input);
|
||||
assertEquals("Atbash failed secure lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
input = "ABC";
|
||||
correctOutput = "zyx";
|
||||
output = cipher.encode(input);
|
||||
assertEquals("Atbash failed secure uppercase encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace encoding
|
||||
input = "abc def";
|
||||
correctOutput = "zyxwvu";
|
||||
output = cipher.encode(input);
|
||||
assertEquals("Atbash failed secure whitespace encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "abc-def@";
|
||||
correctOutput = "zyxwvu";
|
||||
output = cipher.encode(input);
|
||||
assertEquals("Atbash failed secure symbol encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
input = "The quick brown fox jumps over - the lazy dog";
|
||||
correctOutput = "gsvjfrxpyildmulcqfnkhlevigsvozabwlt";
|
||||
output = cipher.encode(input);
|
||||
assertEquals("Atbash failed secure mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
}
|
||||
}
|
||||
522
src/test/java/com/mattrixwv/CipherStreamJava/TestAutokey.java
Normal file
522
src/test/java/com/mattrixwv/CipherStreamJava/TestAutokey.java
Normal file
@@ -0,0 +1,522 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/TestAutokey.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-26-21
|
||||
//Modified: 01-04-22
|
||||
package com.mattrixwv.CipherStreamJava;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class TestAutokey{
|
||||
@Test
|
||||
public void testDecode() throws Exception{
|
||||
Autokey cipher = new Autokey(true, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String input = "qnxepv";
|
||||
String keyword = "queenly";
|
||||
String correctOutput = "attack";
|
||||
String output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "QNXEPV";
|
||||
keyword = "queenly";
|
||||
correctOutput = "ATTACK";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed uppercase decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
input = "qnxepv yt wtwp";
|
||||
keyword = "queenly";
|
||||
correctOutput = "attack at dawn";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed whitespace decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "qnxepv@yt-wtwp";
|
||||
keyword = "queenly";
|
||||
correctOutput = "attack@at-dawn";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed symbol decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
input = "Qnxepv yt - wtwp";
|
||||
keyword = "QUEENLY";
|
||||
correctOutput = "Attack at - dawn";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||
input = "Wmpm mx \"Xae Yhbryoca\"";
|
||||
keyword = "k@i l-t";
|
||||
correctOutput = "Meet at \"The Fountain\"";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceDecode() throws Exception{
|
||||
Autokey cipher = new Autokey(true, false, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String input = "qnxepv";
|
||||
String keyword = "queenly";
|
||||
String correctOutput = "attack";
|
||||
String output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed no whitespace lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "QNXEPV";
|
||||
keyword = "queenly";
|
||||
correctOutput = "ATTACK";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed no whitespace uppercase decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
input = "qnxepv yt wtwp";
|
||||
keyword = "queenly";
|
||||
correctOutput = "attackatdawn";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "qnxepv@yt-wtwp";
|
||||
keyword = "queenly";
|
||||
correctOutput = "attack@at-dawn";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed no whitespace symbol decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
input = "Qnxepv yt - wtwp";
|
||||
keyword = "QUEENLY";
|
||||
correctOutput = "Attackat-dawn";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed no whitespace mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||
input = "Wmpm mx \"Xae Yhbryoca\"";
|
||||
keyword = "k@i l-t";
|
||||
correctOutput = "Meetat\"TheFountain\"";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed no whitespace mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalDecode() throws Exception{
|
||||
Autokey cipher = new Autokey(false, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String input = "qnxepv";
|
||||
String keyword = "queenly";
|
||||
String correctOutput = "attack";
|
||||
String output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed no capital lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "QNXEPV";
|
||||
keyword = "queenly";
|
||||
correctOutput = "attack";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed no capital uppercase decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
input = "qnxepv yt wtwp";
|
||||
keyword = "queenly";
|
||||
correctOutput = "attack at dawn";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed no capital whitespace decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "qnxepv@yt-wtwp";
|
||||
keyword = "queenly";
|
||||
correctOutput = "attack@at-dawn";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed no capital symbol decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
input = "Qnxepv yt - wtwp";
|
||||
keyword = "QUEENLY";
|
||||
correctOutput = "attack at - dawn";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed no capital mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||
input = "Wmpm mx \"Xae Yhbryoca\"";
|
||||
keyword = "k@i l-t";
|
||||
correctOutput = "meet at \"the fountain\"";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed no capital mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolDecode() throws Exception{
|
||||
Autokey cipher = new Autokey(true, true, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
String input = "qnxepv";
|
||||
String keyword = "queenly";
|
||||
String correctOutput = "attack";
|
||||
String output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed no symbol lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "QNXEPV";
|
||||
keyword = "queenly";
|
||||
correctOutput = "ATTACK";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed no symbol uppercase decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
input = "qnxepv yt wtwp";
|
||||
keyword = "queenly";
|
||||
correctOutput = "attack at dawn";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed no symbol whitespace decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "qnxepv@yt-wtwp";
|
||||
keyword = "queenly";
|
||||
correctOutput = "attackatdawn";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed no symbol symbol decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
input = "Qnxepv yt - wtwp";
|
||||
keyword = "QUEENLY";
|
||||
correctOutput = "Attack at dawn";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed no symbol mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||
input = "Wmpm mx \"Xae Yhbryoca\"";
|
||||
keyword = "k@i l-t";
|
||||
correctOutput = "Meet at The Fountain";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed no symbol mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolDecode() throws Exception{
|
||||
Autokey cipher = new Autokey(false, false, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
String input = "qnxepv";
|
||||
String keyword = "queenly";
|
||||
String correctOutput = "attack";
|
||||
String output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed secure lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "QNXEPV";
|
||||
keyword = "queenly";
|
||||
correctOutput = "attack";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed secure uppercase decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
input = "qnxepv yt wtwp";
|
||||
keyword = "queenly";
|
||||
correctOutput = "attackatdawn";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed secure whitespace decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "qnxepv@yt-wtwp";
|
||||
keyword = "queenly";
|
||||
correctOutput = "attackatdawn";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed secure symbol decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
input = "Qnxepv yt - wtwp";
|
||||
keyword = "QUEENLY";
|
||||
correctOutput = "attackatdawn";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed secure mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||
input = "Wmpm mx \"Xae Yhbryoca\"";
|
||||
keyword = "k@i l-t";
|
||||
correctOutput = "meetatthefountain";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Autokey failed secure mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncode() throws Exception{
|
||||
Autokey cipher = new Autokey(true, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String input = "attack";
|
||||
String keyword = "queenly";
|
||||
String correctOutput = "qnxepv";
|
||||
String output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "ATTACK";
|
||||
keyword = "queenly";
|
||||
correctOutput = "QNXEPV";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed uppercase decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
input = "attack at dawn";
|
||||
keyword = "queenly";
|
||||
correctOutput = "qnxepv yt wtwp";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed whitespace decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "attack@at-dawn";
|
||||
keyword = "queenly";
|
||||
correctOutput = "qnxepv@yt-wtwp";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed symbol decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
input = "Attack at - dawn";
|
||||
keyword = "QUEENLY";
|
||||
correctOutput = "Qnxepv yt - wtwp";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||
input = "Meet at \"The Fountain\"";
|
||||
keyword = "k@i l-t";
|
||||
correctOutput = "Wmpm mx \"Xae Yhbryoca\"";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceEncode() throws Exception{
|
||||
Autokey cipher = new Autokey(true, false, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String input = "attack";
|
||||
String keyword = "queenly";
|
||||
String correctOutput = "qnxepv";
|
||||
String output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed no whitespace lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "ATTACK";
|
||||
keyword = "queenly";
|
||||
correctOutput = "QNXEPV";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed no whitespace uppercase decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
input = "attack at dawn";
|
||||
keyword = "queenly";
|
||||
correctOutput = "qnxepvytwtwp";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "attack@at-dawn";
|
||||
keyword = "queenly";
|
||||
correctOutput = "qnxepv@yt-wtwp";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed no whitespace symbol decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
input = "Attack at - dawn";
|
||||
keyword = "QUEENLY";
|
||||
correctOutput = "Qnxepvyt-wtwp";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed no whitespace mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||
input = "Meet at \"The Fountain\"";
|
||||
keyword = "k@i l-t";
|
||||
correctOutput = "Wmpmmx\"XaeYhbryoca\"";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed no whitespace mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalEncode() throws Exception{
|
||||
Autokey cipher = new Autokey(false, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String input = "attack";
|
||||
String keyword = "queenly";
|
||||
String correctOutput = "qnxepv";
|
||||
String output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed no capital lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "ATTACK";
|
||||
keyword = "queenly";
|
||||
correctOutput = "qnxepv";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed no capital uppercase decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
input = "attack at dawn";
|
||||
keyword = "queenly";
|
||||
correctOutput = "qnxepv yt wtwp";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed no capital whitespace decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "attack@at-dawn";
|
||||
keyword = "queenly";
|
||||
correctOutput = "qnxepv@yt-wtwp";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed no capital symbol decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
input = "Attack at - dawn";
|
||||
keyword = "QUEENLY";
|
||||
correctOutput = "qnxepv yt - wtwp";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed no capital mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||
input = "Meet at \"The Fountain\"";
|
||||
keyword = "k@i l-t";
|
||||
correctOutput = "wmpm mx \"xae yhbryoca\"";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed no capital mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolEncode() throws Exception{
|
||||
Autokey cipher = new Autokey(true, true, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
String input = "attack";
|
||||
String keyword = "queenly";
|
||||
String correctOutput = "qnxepv";
|
||||
String output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed no symbol lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "ATTACK";
|
||||
keyword = "queenly";
|
||||
correctOutput = "QNXEPV";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed no symbol uppercase decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
input = "attack at dawn";
|
||||
keyword = "queenly";
|
||||
correctOutput = "qnxepv yt wtwp";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed no symbol whitespace decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "attack@at-dawn";
|
||||
keyword = "queenly";
|
||||
correctOutput = "qnxepvytwtwp";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed no symbol symbol decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
input = "Attack at - dawn";
|
||||
keyword = "QUEENLY";
|
||||
correctOutput = "Qnxepv yt wtwp";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed no symbol mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||
input = "Meet at \"The Fountain\"";
|
||||
keyword = "k@i l-t";
|
||||
correctOutput = "Wmpm mx Xae Yhbryoca";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed no symbol mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolEncode() throws Exception{
|
||||
Autokey cipher = new Autokey(false, false, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
String input = "attack";
|
||||
String keyword = "queenly";
|
||||
String correctOutput = "qnxepv";
|
||||
String output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed secure lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "ATTACK";
|
||||
keyword = "queenly";
|
||||
correctOutput = "qnxepv";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed secure uppercase decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
input = "attack at dawn";
|
||||
keyword = "queenly";
|
||||
correctOutput = "qnxepvytwtwp";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed secure whitespace decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "attack@at-dawn";
|
||||
keyword = "queenly";
|
||||
correctOutput = "qnxepvytwtwp";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed secure symbol decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
input = "Attack at - dawn";
|
||||
keyword = "QUEENLY";
|
||||
correctOutput = "qnxepvytwtwp";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed secure mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||
input = "Meet at \"The Fountain\"";
|
||||
keyword = "k@i l-t";
|
||||
correctOutput = "wmpmmxxaeyhbryoca";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Autokey failed secure mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testKeyword() throws Exception{
|
||||
Autokey cipher = new Autokey();
|
||||
|
||||
//Test keyword with whitespace
|
||||
String keyword = "x y z ";
|
||||
String correctOutput = "XYZ";
|
||||
cipher.setKeyword(keyword);
|
||||
String output = cipher.getKeyword();
|
||||
assertEquals("Vigenere failed keyword with whitespace", correctOutput, output);
|
||||
|
||||
|
||||
//Test keyword with symbol
|
||||
keyword = "x-y@z0";
|
||||
correctOutput = "XYZ";
|
||||
cipher.setKeyword(keyword);
|
||||
output = cipher.getKeyword();
|
||||
assertEquals("Vigenere failed keyword with symbol", correctOutput, output);
|
||||
|
||||
|
||||
//Test keyword with mixed case
|
||||
keyword = "xYz";
|
||||
correctOutput = "XYZ";
|
||||
cipher.setKeyword(keyword);
|
||||
output = cipher.getKeyword();
|
||||
assertEquals("Vigenere failed keyword with mixed case", correctOutput, output);
|
||||
|
||||
//Test keyword with whitespace, symbol and keyword
|
||||
keyword = "x Y%z ";
|
||||
correctOutput = "XYZ";
|
||||
cipher.setKeyword(keyword);
|
||||
output = cipher.getKeyword();
|
||||
assertEquals("Vigenere failed keyword with space, symbol, and mixed case", correctOutput, output);
|
||||
}
|
||||
}
|
||||
626
src/test/java/com/mattrixwv/CipherStreamJava/TestCaesar.java
Normal file
626
src/test/java/com/mattrixwv/CipherStreamJava/TestCaesar.java
Normal file
@@ -0,0 +1,626 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/TestCaesar.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-25-21
|
||||
//Modified: 01-04-22
|
||||
package com.mattrixwv.CipherStreamJava;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class TestCaesar{
|
||||
@Test
|
||||
public void testDecode(){
|
||||
Caesar cipher = new Caesar(true, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String input = "def";
|
||||
int shift = 3;
|
||||
String correctOutput = "abc";
|
||||
String output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "DEF";
|
||||
shift = 3;
|
||||
correctOutput = "ABC";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed uppercase decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test out of bounds shift decoding
|
||||
input = "def";
|
||||
shift = 29;
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed out of bounds shift decoding.", correctOutput, output);
|
||||
//Test out of bounds shift negative decoding
|
||||
input = "def";
|
||||
shift = -23;
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed out of bounds shift negative decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
input = "def ghi";
|
||||
shift = 3;
|
||||
correctOutput = "abc def";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed whitespace decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "def-ghi@";
|
||||
shift = 3;
|
||||
correctOutput = "abc-def@";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed symbol decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
shift = 23;
|
||||
correctOutput = "The quick brown fox jumps over - the lazy dog";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, and symbol decoding with negative shift
|
||||
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
shift = -3;
|
||||
correctOutput = "The quick brown fox jumps over - the lazy dog";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed mixed case, whitespace, and symbol decoding with negative shift.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceDecode(){
|
||||
Caesar cipher = new Caesar(true, false, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String input = "def";
|
||||
int shift = 3;
|
||||
String correctOutput = "abc";
|
||||
String output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no whitespace lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "DEF";
|
||||
shift = 3;
|
||||
correctOutput = "ABC";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no whitespace uppercase decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test out of bounds shift decoding
|
||||
input = "def";
|
||||
shift = 29;
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no whitespace out of bounds shift decoding.", correctOutput, output);
|
||||
//Test out of bounds shift negative decoding
|
||||
input = "def";
|
||||
shift = -23;
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no whitespace out of bounds shift negative decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
input = "def ghi";
|
||||
shift = 3;
|
||||
correctOutput = "abcdef";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "def-ghi@";
|
||||
shift = 3;
|
||||
correctOutput = "abc-def@";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no whitespace symbol decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
shift = 23;
|
||||
correctOutput = "Thequickbrownfoxjumpsover-thelazydog";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no whitespace mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, and symbol decoding with negative shift
|
||||
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
shift = -3;
|
||||
correctOutput = "Thequickbrownfoxjumpsover-thelazydog";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no whitespace mixed case, whitespace, and symbol decoding with negative shift.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalDecode(){
|
||||
Caesar cipher = new Caesar(false, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String input = "def";
|
||||
int shift = 3;
|
||||
String correctOutput = "abc";
|
||||
String output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no capital lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "DEF";
|
||||
shift = 3;
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no capital uppercase decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test out of bounds shift decoding
|
||||
input = "def";
|
||||
shift = 29;
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no capital out of bounds shift decoding.", correctOutput, output);
|
||||
//Test out of bounds shift negative decoding
|
||||
input = "def";
|
||||
shift = -23;
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no capital out of bounds shift negative decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
input = "def ghi";
|
||||
shift = 3;
|
||||
correctOutput = "abc def";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesare failed no capital whitespace decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "def-ghi@";
|
||||
shift = 3;
|
||||
correctOutput = "abc-def@";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no capital symbol decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
shift = 23;
|
||||
correctOutput = "the quick brown fox jumps over - the lazy dog";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no capital mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, and symbol with negative shift
|
||||
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
shift = -3;
|
||||
correctOutput = "the quick brown fox jumps over - the lazy dog";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no capital mixed case, whitespace, and symbol decoding with negative shift.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolDecode(){
|
||||
Caesar cipher = new Caesar(true, true, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
String input = "def";
|
||||
int shift = 3;
|
||||
String correctOutput = "abc";
|
||||
String output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no symbol lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "DEF";
|
||||
shift = 3;
|
||||
correctOutput = "ABC";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no symbol uppercase decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test out of bounds shift decoding
|
||||
input = "def";
|
||||
shift = 29;
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no symbol out of bounds shift decoding.", correctOutput, output);
|
||||
//Test out of bounds shift negative decoding
|
||||
input = "def";
|
||||
shift = -23;
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no symbol out of bounds shift negative decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitepace decoding
|
||||
input = "def ghi";
|
||||
shift = 3;
|
||||
correctOutput = "abc def";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no symbol whitespace decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "def-ghi!";
|
||||
shift = 3;
|
||||
correctOutput = "abcdef";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no symbol symbol decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
shift = 23;
|
||||
correctOutput = "The quick brown fox jumps over the lazy dog";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no symbol mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, and symbol decoding with negative shift
|
||||
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
shift = -3;
|
||||
correctOutput = "The quick brown fox jumps over the lazy dog";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed no symbol mixed case, whitespace, and symbol decoding with negative shift.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolDecode(){
|
||||
Caesar cipher = new Caesar(false, false, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
String input = "def";
|
||||
int shift = 3;
|
||||
String correctOutput = "abc";
|
||||
String output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed secure lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "DEF";
|
||||
shift = 3;
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed secure uppercase decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test out of bounds shift decoding
|
||||
input = "def";
|
||||
shift = 29;
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed secure out of bounds shift decoding.", correctOutput, output);
|
||||
//Test out of bounds shift negative decoding
|
||||
input = "def";
|
||||
shift = -23;
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed secure out of bounds shift negative decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
input = "def ghi";
|
||||
shift = 3;
|
||||
correctOutput = "abcdef";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed secure whitespace decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "def-ghi@";
|
||||
shift = 3;
|
||||
correctOutput = "abcdef";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed secure symbol decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
shift = 23;
|
||||
correctOutput = "thequickbrownfoxjumpsoverthelazydog";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed secure mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, and symbol decoding with negative shift
|
||||
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
shift = -3;
|
||||
correctOutput = "thequickbrownfoxjumpsoverthelazydog";
|
||||
output = cipher.decode(shift, input);
|
||||
assertEquals("Caesar failed secure mixed case, whitespace, and symbol decoding with negative shift.", correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncode(){
|
||||
Caesar cipher = new Caesar(true, true, true);
|
||||
|
||||
//Test lowercase encode
|
||||
String input = "abc";
|
||||
int shift = 3;
|
||||
String correctOutput = "def";
|
||||
String output = cipher.encode(shift, input);
|
||||
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 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("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 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);
|
||||
}
|
||||
}
|
||||
58
src/test/java/com/mattrixwv/CipherStreamJava/TestMorse.java
Normal file
58
src/test/java/com/mattrixwv/CipherStreamJava/TestMorse.java
Normal file
@@ -0,0 +1,58 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/TestMorse.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-28-21
|
||||
//Modified: 01-04-22
|
||||
package com.mattrixwv.CipherStreamJava;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class TestMorse{
|
||||
@Test
|
||||
public void testDecode(){
|
||||
Morse cipher = new Morse();
|
||||
|
||||
//Test 1
|
||||
String input = "... --- ...";
|
||||
String correctOutput = "SOS";
|
||||
String output = cipher.decode(input);
|
||||
assertEquals("Morse Decoding failed the first test", correctOutput, output);
|
||||
|
||||
//Test 2
|
||||
input = "-- --- .-. ... . -.-. --- -.. .";
|
||||
correctOutput = "MORSECODE";
|
||||
output = cipher.decode(input);
|
||||
assertEquals("Morse Decoding failed the second test", correctOutput, output);
|
||||
|
||||
//Test 3
|
||||
input = ".---- ..--- ...-- ----. ---.. --...";
|
||||
correctOutput = "123987";
|
||||
output = cipher.decode(input);
|
||||
assertEquals("Morse Decoding failed the third test", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testEncode(){
|
||||
Morse cipher = new Morse();
|
||||
|
||||
//Test 1
|
||||
String input = "sos";
|
||||
String correctOutput = "... --- ...";
|
||||
String output = cipher.encode(input);
|
||||
assertEquals("Morse Encoding failed the first test", correctOutput, output);
|
||||
|
||||
//Test 2
|
||||
input = "MORSE, CODE";
|
||||
correctOutput = "-- --- .-. ... . -.-. --- -.. .";
|
||||
output = cipher.encode(input);
|
||||
assertEquals("Morse Encoding failed the second test", correctOutput, output);
|
||||
|
||||
//Test 3
|
||||
input = "1.23 987";
|
||||
correctOutput = ".---- ..--- ...-- ----. ---.. --...";
|
||||
output = cipher.encode(input);
|
||||
assertEquals("Morse Encoding failed the third test", correctOutput, output);
|
||||
}
|
||||
}
|
||||
516
src/test/java/com/mattrixwv/CipherStreamJava/TestPlayfair.java
Normal file
516
src/test/java/com/mattrixwv/CipherStreamJava/TestPlayfair.java
Normal file
@@ -0,0 +1,516 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/TestPlayfair.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-30-21
|
||||
//Modified: 01-04-22
|
||||
package com.mattrixwv.CipherStreamJava;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.mattrixwv.CipherStreamJava.Exceptions.InvalidCharacterException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class TestPlayfair{
|
||||
@Test
|
||||
public void testDecode() throws InvalidCharacterException, Exception{
|
||||
Playfair cipher = new Playfair(true, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "bmodzbxdnabekudmuixmmouvif";
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "hidethegoldinthetrexestump";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed uppercase decoding.", correctOutput, output);
|
||||
//Test odd letter count decoding
|
||||
inputString = "bmodzbxdnabekudmuixmmouvim";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hidethegoldinthetrexestumx";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed odd letter count decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "bmod zbx dnab ek udm uixmm ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hide the gold in the trexe stump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "bmodzbxdnabek-udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hidethegoldin-the@trexe+stump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "Hide the gold in - the@trexe+stump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whtiespace, symbol decoding with mangled keyword
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "Hide the gold in - the@trexe+stump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceDecode() throws InvalidCharacterException, Exception{
|
||||
Playfair cipher = new Playfair(true, false, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "bmodzbxdnabekudmuixmmouvif";
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "hidethegoldinthetrexestump";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace uppercase decoding.", correctOutput, output);
|
||||
//Test odd letter count decoding
|
||||
inputString = "bmodzbxdnabekudmuixmmouvim";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hidethegoldinthetrexestumx";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace odd letter count decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "bmodzbxdnabekudmuixmmouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hidethegoldinthetrexestump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "bmodzbxdnabek-udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hidethegoldin-the@trexe+stump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whtiespace, symbol decoding
|
||||
inputString = "Bmodzbxdnabek-udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "Hidethegoldin-the@trexe+stump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whtiespace, symbol decoding with mangled keyword
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "Hidethegoldin-the@trexe+stump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalDecode() throws InvalidCharacterException, Exception{
|
||||
Playfair cipher = new Playfair(false, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "bmodzbxdnabekudmuixmmouvif";
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital uppercase decoding.", correctOutput, output);
|
||||
//Test odd letter count decoding
|
||||
inputString = "bmodzbxdnabekudmuixmmouvim";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMX";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital odd letter count decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "bmod zbx dnab ek udm uixmm ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDE THE GOLD IN THE TREXE STUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "bmodzbxdnabek-udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDIN-THE@TREXE+STUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whtiespace, symbol decoding
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDE THE GOLD IN - THE@TREXE+STUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whtiespace, symbol decoding with mangled keyword
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "HIDE THE GOLD IN - THE@TREXE+STUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolDecode() throws InvalidCharacterException, Exception{
|
||||
Playfair cipher = new Playfair(true, true, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "bmodzbxdnabekudmuixmmouvif";
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "hidethegoldinthetrexestump";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol uppercase decoding.", correctOutput, output);
|
||||
//Test odd letter count decoding
|
||||
inputString = "bmodzbxdnabekudmuixmmouvim";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hidethegoldinthetrexestumx";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol odd letter count decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "bmod zbx dnab ek udm uixmm ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hide the gold in the trexe stump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "bmodzbxdnabek-udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hidethegoldinthetrexestump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whtiespace, symbol decoding
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "Hide the gold in thetrexestump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whtiespace, symbol decoding with mangled keyword
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "Hide the gold in thetrexestump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidCharacterException, Exception{
|
||||
Playfair cipher = new Playfair(false, false, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "bmodzbxdnabekudmuixmmouvif";
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure uppercase decoding.", correctOutput, output);
|
||||
//Test odd letter count decoding
|
||||
inputString = "bmodzbxdnabekudmuixmmouvim";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMX";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure odd letter count decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "bmod zbx dnab ek udm uixmm ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "bmodzbxdnabek-udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whtiespace, symbol decoding
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whtiespace, symbol decoding with mangled keyword
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testEncode() throws InvalidCharacterException, Exception{
|
||||
Playfair cipher = new Playfair(true, true, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "hidethegoldinthetrexestump";
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "bmodzbxdnabekudmuixmmouvif";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed uppercase encoding.", correctOutput, output);
|
||||
//Test odd letter count encoding
|
||||
inputString = "hidethegoldinthetrexestum";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmodzbxdnabekudmuixmmouviM";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed odd letter count encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "hide the gold in the trexe stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmod zbx dnab ek udm uixmm ouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed whitespace encoding.", correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "hidethegoldin-the@trexe+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmodzbxdnabek-udm@uixmm+ouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed symbol encoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "Bmod zbx dnab ek - udm@uixMm+ouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol encoding with mangled keyword
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "Bmod zbx dnab ek - udm@uixMm+ouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceEncode() throws InvalidCharacterException, Exception{
|
||||
Playfair cipher = new Playfair(true, false, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "hidethegoldinthetrexestump";
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "bmodzbxdnabekudmuixmmouvif";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace uppercase encoding.", correctOutput, output);
|
||||
//Test odd letter count encoding
|
||||
inputString = "hidethegoldinthetrexestum";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmodzbxdnabekudmuixmmouviM";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace odd letter count encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "hide the gold in the trexe stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmodzbxdnabekudmuixmmouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace whitespace encoding.", correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "hidethegoldin-the@trexe+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmodzbxdnabek-udm@uixmm+ouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace symbol encoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "Bmodzbxdnabek-udm@uixMm+ouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol encoding with mangled keyword
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "Bmodzbxdnabek-udm@uixMm+ouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalEncode() throws InvalidCharacterException, Exception{
|
||||
Playfair cipher = new Playfair(false, true, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "hidethegoldinthetrexestump";
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital uppercase encoding.", correctOutput, output);
|
||||
//Test odd letter count encoding
|
||||
inputString = "hidethegoldinthetrexestum";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIM";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital odd letter count encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "hide the gold in the trexe stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMOD ZBX DNAB EK UDM UIXMM OUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital whitespace encoding.", correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "hidethegoldin-the@trexe+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEK-UDM@UIXMM+OUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital symbol encoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMOD ZBX DNAB EK - UDM@UIXMM+OUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol encoding with mangled keyword
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "BMOD ZBX DNAB EK - UDM@UIXMM+OUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolEncode() throws InvalidCharacterException, Exception{
|
||||
Playfair cipher = new Playfair(true, true, false);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "hidethegoldinthetrexestump";
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "bmodzbxdnabekudmuixmmouvif";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol uppercase encoding.", correctOutput, output);
|
||||
//Test odd letter count encoding
|
||||
inputString = "hidethegoldinthetrexestum";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmodzbxdnabekudmuixmmouviM";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol odd letter count encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "hide the gold in the trexe stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmod zbx dnab ek udm uixmm ouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol whitespace encoding.", correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "hidethegoldin-the@trexe+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmodzbxdnabekudmuixmmouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol symbol encoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "Bmod zbx dnab ek udmuixMmouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol encoding with mangled keyword
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "Bmod zbx dnab ek udmuixMmouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidCharacterException, Exception{
|
||||
Playfair cipher = new Playfair(false, false, false);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "hidethegoldinthetrexestump";
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure uppercase encoding.", correctOutput, output);
|
||||
//Test odd letter count encoding
|
||||
inputString = "hidethegoldinthetrexestum";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIM";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure odd letter count encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "hide the gold in the trexe stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure whitespace encoding.", correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "hidethegoldin-the@trexe+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure symbol encoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol encoding with mangled keyword
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,320 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/TestPolybiusSquare.java
|
||||
//Mattrixwv
|
||||
// Created: 01-04-22
|
||||
//Modified: 01-04-22
|
||||
package com.mattrixwv.CipherStreamJava;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.mattrixwv.CipherStreamJava.Exceptions.InvalidCharacterException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class TestPolybiusSquare{
|
||||
@Test
|
||||
public void testDecode() throws InvalidCharacterException{
|
||||
PolybiusSquare cipher = new PolybiusSquare(true, true);
|
||||
|
||||
//Test simple decoding
|
||||
String inputString = "121144";
|
||||
String keyword = "";
|
||||
String correctOutput = "BAT";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed simple decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "12 11 44";
|
||||
keyword = "";
|
||||
correctOutput = "B A T";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "12@11+44-";
|
||||
keyword = "";
|
||||
correctOutput = "B@A+T-";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace, symbol decoding
|
||||
inputString = "12 11-44";
|
||||
keyword = "";
|
||||
correctOutput = "B A-T";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test whitespace, symbol decoding with mangled keyword
|
||||
inputString = "15 14-52";
|
||||
keyword = "Z Y+ X-";
|
||||
correctOutput = "B A-T";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceDecode() throws InvalidCharacterException{
|
||||
PolybiusSquare cipher = new PolybiusSquare(false, true);
|
||||
|
||||
//Test simple decoding
|
||||
String inputString = "121144";
|
||||
String keyword = "";
|
||||
String correctOutput = "BAT";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no whitespace simple decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "12 11 44";
|
||||
keyword = "";
|
||||
correctOutput = "BAT";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "12@11+44-";
|
||||
keyword = "";
|
||||
correctOutput = "B@A+T-";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no whitespace symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace, symbol decoding
|
||||
inputString = "12 11-44";
|
||||
keyword = "";
|
||||
correctOutput = "BA-T";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no whitespace whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test whitespace, symbol decoding with mangled keyword
|
||||
inputString = "15 14-52";
|
||||
keyword = "Z Y+ X-";
|
||||
correctOutput = "BA-T";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no whitespace whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolDeocde() throws InvalidCharacterException{
|
||||
PolybiusSquare cipher = new PolybiusSquare(true, false);
|
||||
|
||||
//Test simple decoding
|
||||
String inputString = "121144";
|
||||
String keyword = "";
|
||||
String correctOutput = "BAT";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no symbol simple decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "12 11 44";
|
||||
keyword = "";
|
||||
correctOutput = "B A T";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no symbol whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "12@11+44-";
|
||||
keyword = "";
|
||||
correctOutput = "BAT";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no symbol symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace, symbol decoding
|
||||
inputString = "12 11-44";
|
||||
keyword = "";
|
||||
correctOutput = "B AT";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no symbol whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test whitespace, symbol decoding with mangled keyword
|
||||
inputString = "15 14-52";
|
||||
keyword = "Z Y+ X-";
|
||||
correctOutput = "B AT";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no symbol whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceSymbolDecode() throws InvalidCharacterException{
|
||||
PolybiusSquare cipher = new PolybiusSquare(false, false);
|
||||
|
||||
//Test simple decoding
|
||||
String inputString = "121144";
|
||||
String keyword = "";
|
||||
String correctOutput = "BAT";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed secure simple decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "12 11 44";
|
||||
keyword = "";
|
||||
correctOutput = "BAT";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed secure whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "12@11+44-";
|
||||
keyword = "";
|
||||
correctOutput = "BAT";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed secure symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace, symbol decoding
|
||||
inputString = "12 11-44";
|
||||
keyword = "";
|
||||
correctOutput = "BAT";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed secure whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test whitespace, symbol decoding with mangled keyword
|
||||
inputString = "15 14-52";
|
||||
keyword = "Z Y+ X-";
|
||||
correctOutput = "BAT";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed secure whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testEncode() throws InvalidCharacterException, Exception{
|
||||
PolybiusSquare cipher = new PolybiusSquare(true, true);
|
||||
|
||||
//Test simple encoding
|
||||
String inputString = "BAT";
|
||||
String keyword = "";
|
||||
String correctOutput = "121144";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed simple encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "B A T";
|
||||
keyword = "";
|
||||
correctOutput = "12 11 44";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed whitespace encoding.", correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "B@A+T-";
|
||||
keyword = "";
|
||||
correctOutput = "12@11+44-";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed symbol encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace, symbol decoding
|
||||
inputString = "B A-T";
|
||||
keyword = "";
|
||||
correctOutput = "12 11-44";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed whitespace, symbol encoding.", correctOutput, output);
|
||||
//Test whitespace, symbol decoding with mangled keyword
|
||||
inputString = "B A-T";
|
||||
keyword = "Z Y+ X-";
|
||||
correctOutput = "15 14-52";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceEncode() throws InvalidCharacterException, Exception{
|
||||
PolybiusSquare cipher = new PolybiusSquare(false, true);
|
||||
|
||||
//Test simple encoding
|
||||
String inputString = "BAT";
|
||||
String keyword = "";
|
||||
String correctOutput = "121144";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no whitespace simple encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "B A T";
|
||||
keyword = "";
|
||||
correctOutput = "121144";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no whitespace whitespace encoding.", correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "B@A+T-";
|
||||
keyword = "";
|
||||
correctOutput = "12@11+44-";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no whitespace symbol encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace, symbol decoding
|
||||
inputString = "B A-T";
|
||||
keyword = "";
|
||||
correctOutput = "1211-44";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no whitespace whitespace, symbol encoding.", correctOutput, output);
|
||||
//Test whitespace, symbol decoding with mangled keyword
|
||||
inputString = "B A-T";
|
||||
keyword = "Z Y+ X-";
|
||||
correctOutput = "1514-52";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no whitespace whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolEncode() throws InvalidCharacterException, Exception{
|
||||
PolybiusSquare cipher = new PolybiusSquare(true, false);
|
||||
|
||||
//Test simple encoding
|
||||
String inputString = "BAT";
|
||||
String keyword = "";
|
||||
String correctOutput = "121144";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no symbol simple encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "B A T";
|
||||
keyword = "";
|
||||
correctOutput = "12 11 44";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no symbol whitespace encoding.", correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "B@A+T-";
|
||||
keyword = "";
|
||||
correctOutput = "121144";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no symbol symbol encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace, symbol decoding
|
||||
inputString = "B A-T";
|
||||
keyword = "";
|
||||
correctOutput = "12 1144";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed whitespace, symbol encoding.", correctOutput, output);
|
||||
//Test whitespace, symbol decoding with mangled keyword
|
||||
inputString = "B A-T";
|
||||
keyword = "Z Y+ X-";
|
||||
correctOutput = "15 1452";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed no symbol whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceSymbolEncode() throws InvalidCharacterException, Exception{
|
||||
PolybiusSquare cipher = new PolybiusSquare(false, false);
|
||||
|
||||
//Test simple encoding
|
||||
String inputString = "BAT";
|
||||
String keyword = "";
|
||||
String correctOutput = "12 11 44";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed secure simple encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "B A T";
|
||||
keyword = "";
|
||||
correctOutput = "12 11 44";
|
||||
assertEquals("PolybiusSquare failed secure whitespace encoding.", correctOutput, output);
|
||||
output = cipher.encode(keyword, inputString);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "B@A+T-";
|
||||
keyword = "";
|
||||
correctOutput = "12 11 44";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed secure symbol encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace, symbol decoding
|
||||
inputString = "B A-T";
|
||||
keyword = "";
|
||||
correctOutput = "12 11 44";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed secure whitespace, symbol encoding.", correctOutput, output);
|
||||
//Test whitespace, symbol decoding with mangled keyword
|
||||
inputString = "B A-T";
|
||||
keyword = "Z Y+ X-";
|
||||
correctOutput = "15 14 52";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed secure whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
}
|
||||
522
src/test/java/com/mattrixwv/CipherStreamJava/TestVigenere.java
Normal file
522
src/test/java/com/mattrixwv/CipherStreamJava/TestVigenere.java
Normal file
@@ -0,0 +1,522 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/TestVigenere.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-25-21
|
||||
//Modified: 01-04-22
|
||||
package com.mattrixwv.CipherStreamJava;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class TestVigenere{
|
||||
@Test
|
||||
public void testDecode() throws Exception{
|
||||
Vigenere cipher = new Vigenere(true, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String input = "xzb";
|
||||
String keyword = "xyz";
|
||||
String correctOutput = "abc";
|
||||
String output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "XZB";
|
||||
keyword = "XYZ";
|
||||
correctOutput = "ABC";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed uppercase decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
input = "x z b";
|
||||
keyword = "xyz";
|
||||
correctOutput = "a b c";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed whitespace decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "x@z^b";
|
||||
keyword = "xyz";
|
||||
correctOutput = "a@b^c";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed symbol decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
input = "Lxfopv ef - rnhr";
|
||||
keyword = "lemon";
|
||||
correctOutput = "Attack at - dawn";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||
input = "'Csastp' kv siqut gqu 'Csastpiuaqjb'";
|
||||
keyword = " a@b C=d";
|
||||
correctOutput = "'Crypto' is short for 'Cryptography'";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceDecode() throws Exception{
|
||||
Vigenere cipher = new Vigenere(true, false, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String input = "xzb";
|
||||
String keyword = "xyz";
|
||||
String correctOutput = "abc";
|
||||
String output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "XZB";
|
||||
keyword = "XYZ";
|
||||
correctOutput = "ABC";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed uppercase decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
input = "x z b";
|
||||
keyword = "xyz";
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed whitespace decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "x@z^b";
|
||||
keyword = "xyz";
|
||||
correctOutput = "a@b^c";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed symbol decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
input = "Lxfopv ef - rnhr";
|
||||
keyword = "lemon";
|
||||
correctOutput = "Attackat-dawn";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||
input = "'Csastp' kv siqut gqu 'Csastpiuaqjb'";
|
||||
keyword = " a@b C=d";
|
||||
correctOutput = "'Crypto'isshortfor'Cryptography'";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalDecode() throws Exception{
|
||||
Vigenere cipher = new Vigenere(false, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String input = "xzb";
|
||||
String keyword = "xyz";
|
||||
String correctOutput = "abc";
|
||||
String output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "XZB";
|
||||
keyword = "XYZ";
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed uppercase decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
input = "x z b";
|
||||
keyword = "xyz";
|
||||
correctOutput = "a b c";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed whitespace decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "x@z^b";
|
||||
keyword = "xyz";
|
||||
correctOutput = "a@b^c";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed symbol decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
input = "Lxfopv ef - rnhr";
|
||||
keyword = "lemon";
|
||||
correctOutput = "attack at - dawn";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||
input = "'Csastp' kv siqut gqu 'Csastpiuaqjb'";
|
||||
keyword = " a@b C=d";
|
||||
correctOutput = "'crypto' is short for 'cryptography'";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolDecode() throws Exception{
|
||||
Vigenere cipher = new Vigenere(true, true, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
String input = "xzb";
|
||||
String keyword = "xyz";
|
||||
String correctOutput = "abc";
|
||||
String output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "XZB";
|
||||
keyword = "XYZ";
|
||||
correctOutput = "ABC";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed uppercase decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
input = "x z b";
|
||||
keyword = "xyz";
|
||||
correctOutput = "a b c";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed whitespace decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "x@z^b";
|
||||
keyword = "xyz";
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed symbol decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
input = "Lxfopv ef - rnhr";
|
||||
keyword = "lemon";
|
||||
correctOutput = "Attack at dawn";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||
input = "'Csastp' kv siqut gqu 'Csastpiuaqjb'";
|
||||
keyword = " a@b C=d";
|
||||
correctOutput = "Crypto is short for Cryptography";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolDecode() throws Exception{
|
||||
Vigenere cipher = new Vigenere(false, false, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
String input = "xzb";
|
||||
String keyword = "xyz";
|
||||
String correctOutput = "abc";
|
||||
String output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
input = "XZB";
|
||||
keyword = "XYZ";
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed uppercase decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace decoding
|
||||
input = "x z b";
|
||||
keyword = "xyz";
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed whitespace decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "x@z^b";
|
||||
keyword = "xyz";
|
||||
correctOutput = "abc";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed symbol decoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
input = "Lxfopv ef rnhr";
|
||||
keyword = "lemon";
|
||||
correctOutput = "attackatdawn";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol decoding with mangled keyword
|
||||
input = "'Csastp' kv siqut gqu 'Csastpiuaqjb'";
|
||||
keyword = " a@b C=d";
|
||||
correctOutput = "cryptoisshortforcryptography";
|
||||
output = cipher.decode(keyword, input);
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncode() throws Exception{
|
||||
Vigenere cipher = new Vigenere(true, true, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
String input = "abc";
|
||||
String keyword = "xyz";
|
||||
String correctOutput = "xzb";
|
||||
String output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed lowercase encoding.", correctOutput, output);
|
||||
//Test upercase encoding
|
||||
input = "ABC";
|
||||
keyword = "xyz";
|
||||
correctOutput = "XZB";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed uppercase encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace encoding
|
||||
input = "a b c";
|
||||
keyword = "xyz";
|
||||
correctOutput = "x z b";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed whitespace encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "a@b^c";
|
||||
keyword = "xyz";
|
||||
correctOutput = "x@z^b";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed symbol encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
input = "Attack at dawn";
|
||||
keyword = "lemon";
|
||||
correctOutput = "Lxfopv ef rnhr";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol decoding test 2
|
||||
input = "'Crypto' is short for 'Cryptography'";
|
||||
keyword = " a@b C=d";
|
||||
correctOutput = "'Csastp' kv siqut gqu 'Csastpiuaqjb'";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceEncode() throws Exception{
|
||||
Vigenere cipher = new Vigenere(true, false, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
String input = "abc";
|
||||
String keyword = "xyz";
|
||||
String correctOutput = "xzb";
|
||||
String output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed lowercase encoding.", correctOutput, output);
|
||||
//Test upercase encoding
|
||||
input = "ABC";
|
||||
keyword = "xyz";
|
||||
correctOutput = "XZB";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed uppercase encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace encoding
|
||||
input = "a b c";
|
||||
keyword = "xyz";
|
||||
correctOutput = "xzb";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed whitespace encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "a@b^c";
|
||||
keyword = "xyz";
|
||||
correctOutput = "x@z^b";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed symbol encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
input = "Attack at dawn";
|
||||
keyword = "lemon";
|
||||
correctOutput = "Lxfopvefrnhr";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol decoding test 2
|
||||
input = "'Crypto' is short for 'Cryptography'";
|
||||
keyword = " a@b C=d";
|
||||
correctOutput = "'Csastp'kvsiqutgqu'Csastpiuaqjb'";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalEncode() throws Exception{
|
||||
Vigenere cipher = new Vigenere(false, true, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
String input = "abc";
|
||||
String keyword = "xyz";
|
||||
String correctOutput = "xzb";
|
||||
String output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed lowercase encoding.", correctOutput, output);
|
||||
//Test upercase encoding
|
||||
input = "ABC";
|
||||
keyword = "xyz";
|
||||
correctOutput = "xzb";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed uppercase encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace encoding
|
||||
input = "a b c";
|
||||
keyword = "xyz";
|
||||
correctOutput = "x z b";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed whitespace encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "a@b^c";
|
||||
keyword = "xyz";
|
||||
correctOutput = "x@z^b";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed symbol encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
input = "Attack at dawn";
|
||||
keyword = "lemon";
|
||||
correctOutput = "lxfopv ef rnhr";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol decoding test 2
|
||||
input = "'Crypto' is short for 'Cryptography'";
|
||||
keyword = " a@b C=d";
|
||||
correctOutput = "'csastp' kv siqut gqu 'csastpiuaqjb'";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolEncode() throws Exception{
|
||||
Vigenere cipher = new Vigenere(true, true, false);
|
||||
|
||||
//Test lowercase encoding
|
||||
String input = "abc";
|
||||
String keyword = "xyz";
|
||||
String correctOutput = "xzb";
|
||||
String output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed lowercase encoding.", correctOutput, output);
|
||||
//Test upercase encoding
|
||||
input = "ABC";
|
||||
keyword = "xyz";
|
||||
correctOutput = "XZB";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed uppercase encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace encoding
|
||||
input = "a b c";
|
||||
keyword = "xyz";
|
||||
correctOutput = "x z b";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed whitespace encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "a@b^c";
|
||||
keyword = "xyz";
|
||||
correctOutput = "xzb";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed symbol encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
input = "Attack at dawn";
|
||||
keyword = "lemon";
|
||||
correctOutput = "Lxfopv ef rnhr";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol decoding test 2
|
||||
input = "'Crypto' is short for 'Cryptography'";
|
||||
keyword = " a@b C=d";
|
||||
correctOutput = "Csastp kv siqut gqu Csastpiuaqjb";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolEncode() throws Exception{
|
||||
Vigenere cipher = new Vigenere(false, false, false);
|
||||
|
||||
//Test lowercase encoding
|
||||
String input = "abc";
|
||||
String keyword = "xyz";
|
||||
String correctOutput = "xzb";
|
||||
String output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed lowercase encoding.", correctOutput, output);
|
||||
//Test upercase encoding
|
||||
input = "ABC";
|
||||
keyword = "xyz";
|
||||
correctOutput = "xzb";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed uppercase encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test whitespace encoding
|
||||
input = "a b c";
|
||||
keyword = "xyz";
|
||||
correctOutput = "xzb";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed whitespace encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test symbol decoding
|
||||
input = "a@b^c";
|
||||
keyword = "xyz";
|
||||
correctOutput = "xzb";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed symbol encoding.", correctOutput, output);
|
||||
|
||||
|
||||
//Test mixed case, whitespace, symbol decoding
|
||||
input = "Attack at dawn";
|
||||
keyword = "lemon";
|
||||
correctOutput = "lxfopvefrnhr";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol decoding test 2
|
||||
input = "'Crypto' is short for 'Cryptography'";
|
||||
keyword = " a@b C=d";
|
||||
correctOutput = "csastpkvsiqutgqucsastpiuaqjb";
|
||||
output = cipher.encode(keyword, input);
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testKeyword() throws Exception{
|
||||
Vigenere cipher = new Vigenere();
|
||||
|
||||
//Test keyword with whitespace
|
||||
String keyword = "x y z ";
|
||||
String correctOutput = "XYZ";
|
||||
cipher.setKeyword(keyword);
|
||||
String output = cipher.getKeyword();
|
||||
assertEquals("Vigenere failed keyword with whitespace", correctOutput, output);
|
||||
|
||||
|
||||
//Test keyword with symbol
|
||||
keyword = "x-y@z0";
|
||||
correctOutput = "XYZ";
|
||||
cipher.setKeyword(keyword);
|
||||
output = cipher.getKeyword();
|
||||
assertEquals("Vigenere failed keyword with symbol", correctOutput, output);
|
||||
|
||||
|
||||
//Test keyword with mixed case
|
||||
keyword = "xYz";
|
||||
correctOutput = "XYZ";
|
||||
cipher.setKeyword(keyword);
|
||||
output = cipher.getKeyword();
|
||||
assertEquals("Vigenere failed keyword with mixed case", correctOutput, output);
|
||||
|
||||
//Test keyword with whitespace, symbol and keyword
|
||||
keyword = "x Y%z ";
|
||||
correctOutput = "XYZ";
|
||||
cipher.setKeyword(keyword);
|
||||
output = cipher.getKeyword();
|
||||
assertEquals("Vigenere failed keyword with space, symbol, and mixed case", correctOutput, output);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user