Updated tests
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/TestAutokey.java
|
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/monoSubstitution/TestAutokey.java
|
||||||
//Matthew Ellison
|
//Mattrixwv
|
||||||
// Created: 07-26-21
|
// Created: 07-26-21
|
||||||
//Modified: 01-09-22
|
//Modified: 02-22-22
|
||||||
package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -18,236 +18,195 @@ public class TestAutokey{
|
|||||||
public void testEncode() throws InvalidKeywordException, InvalidInputException{
|
public void testEncode() throws InvalidKeywordException, InvalidInputException{
|
||||||
Autokey cipher = new Autokey(true, true, true);
|
Autokey cipher = new Autokey(true, true, true);
|
||||||
|
|
||||||
//Test lowercase decoding
|
//Test lowercase encoding
|
||||||
String input = "attack";
|
String inputString = "messagetoencode";
|
||||||
String keyword = "queenly";
|
String keyword = "keyword";
|
||||||
String correctOutput = "qnxepv";
|
String correctOutput = "wiqooxhfswfcuhx";
|
||||||
String output = cipher.encode(keyword, input);
|
String output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Autokey failed lowercase decoding.", correctOutput, output);
|
assertEquals("Autokey failed lowercase encoding.", correctOutput, output);
|
||||||
//Test uppercase decoding
|
//Test uppercase encoding
|
||||||
input = "ATTACK";
|
inputString = "MESSAGETOENCODE";
|
||||||
keyword = "queenly";
|
keyword = "keyword";
|
||||||
correctOutput = "QNXEPV";
|
correctOutput = "WIQOOXHFSWFCUHX";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Autokey failed uppercase decoding.", correctOutput, output);
|
assertEquals("Autokey failed uppercase encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test whitespace encoding
|
||||||
|
inputString = "message to encode";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "wiqooxh fs wfcuhx";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Autokey failed whitespace encoding.", correctOutput, output);
|
||||||
|
|
||||||
//Test whitespace decoding
|
//Test symbol encoding
|
||||||
input = "attack at dawn";
|
inputString = "message*to+encode";
|
||||||
keyword = "queenly";
|
keyword = "keyword";
|
||||||
correctOutput = "qnxepv yt wtwp";
|
correctOutput = "wiqooxh*fs+wfcuhx";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Autokey failed whitespace decoding.", correctOutput, output);
|
assertEquals("Autokey failed symbol encoding.", 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
|
//Test mixed case, whitespace, symbol encoding
|
||||||
input = "Attack at - dawn";
|
inputString = "Message to^encode";
|
||||||
keyword = "QUEENLY";
|
keyword = "keyword";
|
||||||
correctOutput = "Qnxepv yt - wtwp";
|
correctOutput = "Wiqooxh fs^wfcuhx";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Autokey failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
assertEquals("Autokey failed mixed case, whitespace, symbol encoding.", 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
|
@Test
|
||||||
public void testNoCapitalEncode() throws InvalidKeywordException, InvalidInputException{
|
public void testNoCapitalEncode() throws InvalidKeywordException, InvalidInputException{
|
||||||
Autokey cipher = new Autokey(false, true, true);
|
Autokey cipher = new Autokey(false, true, true);
|
||||||
|
|
||||||
//Test lowercase decoding
|
//Test lowercase encoding
|
||||||
String input = "attack";
|
String inputString = "messagetoencode";
|
||||||
String keyword = "queenly";
|
String keyword = "keyword";
|
||||||
String correctOutput = "qnxepv";
|
String correctOutput = "WIQOOXHFSWFCUHX";
|
||||||
String output = cipher.encode(keyword, input);
|
String output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no capital lowercase decoding.", correctOutput, output);
|
assertEquals("Autokey failed no capital lowercase encoding.", correctOutput, output);
|
||||||
//Test uppercase decoding
|
//Test uppercase encoding
|
||||||
input = "ATTACK";
|
inputString = "MESSAGETOENCODE";
|
||||||
keyword = "queenly";
|
keyword = "keyword";
|
||||||
correctOutput = "qnxepv";
|
correctOutput = "WIQOOXHFSWFCUHX";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no capital uppercase decoding.", correctOutput, output);
|
assertEquals("Autokey failed no capital uppercase encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test whitespace encoding
|
||||||
|
inputString = "message to encode";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "WIQOOXH FS WFCUHX";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Autokey failed no capital whitespace encoding.", correctOutput, output);
|
||||||
|
|
||||||
//Test whitespace decoding
|
//Test symbol encoding
|
||||||
input = "attack at dawn";
|
inputString = "message*to+encode";
|
||||||
keyword = "queenly";
|
keyword = "keyword";
|
||||||
correctOutput = "qnxepv yt wtwp";
|
correctOutput = "WIQOOXH*FS+WFCUHX";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no capital whitespace decoding.", correctOutput, output);
|
assertEquals("Autokey failed no capital symbol encoding.", 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
|
//Test mixed case, whitespace, symbol encoding
|
||||||
input = "Attack at - dawn";
|
inputString = "Message to^encode";
|
||||||
keyword = "QUEENLY";
|
keyword = "keyword";
|
||||||
correctOutput = "qnxepv yt - wtwp";
|
correctOutput = "WIQOOXH FS^WFCUHX";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no capital mixed case, whitespace, symbol decoding.", correctOutput, output);
|
assertEquals("Autokey failed no capital mixed case, whitespace, symbol encoding.", 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
|
@Test
|
||||||
public void testNoWhitespaceEncode() throws InvalidKeywordException, InvalidInputException{
|
public void testNoWhitespaceEncode() throws InvalidKeywordException, InvalidInputException{
|
||||||
Autokey cipher = new Autokey(true, false, true);
|
Autokey cipher = new Autokey(true, false, true);
|
||||||
|
|
||||||
//Test lowercase decoding
|
//Test lowercase encoding
|
||||||
String input = "attack";
|
String inputString = "messagetoencode";
|
||||||
String keyword = "queenly";
|
String keyword = "keyword";
|
||||||
String correctOutput = "qnxepv";
|
String correctOutput = "wiqooxhfswfcuhx";
|
||||||
String output = cipher.encode(keyword, input);
|
String output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no whitespace lowercase decoding.", correctOutput, output);
|
assertEquals("Autokey failed no whitespace lowercase encoding.", correctOutput, output);
|
||||||
//Test uppercase decoding
|
//Test uppercase encoding
|
||||||
input = "ATTACK";
|
inputString = "MESSAGETOENCODE";
|
||||||
keyword = "queenly";
|
keyword = "keyword";
|
||||||
correctOutput = "QNXEPV";
|
correctOutput = "WIQOOXHFSWFCUHX";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no whitespace uppercase decoding.", correctOutput, output);
|
assertEquals("Autokey failed no whitespace uppercase encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test whitespace encoding
|
||||||
|
inputString = "message to encode";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "wiqooxhfswfcuhx";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Autokey failed no whitespace whitespace encoding.", correctOutput, output);
|
||||||
|
|
||||||
//Test whitespace decoding
|
//Test symbol encoding
|
||||||
input = "attack at dawn";
|
inputString = "message*to+encode";
|
||||||
keyword = "queenly";
|
keyword = "keyword";
|
||||||
correctOutput = "qnxepvytwtwp";
|
correctOutput = "wiqooxh*fs+wfcuhx";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no whitespace whitespace decoding.", correctOutput, output);
|
assertEquals("Autokey failed no whitespace symbol encoding.", 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
|
//Test mixed case, whitespace, symbol encoding
|
||||||
input = "Attack at - dawn";
|
inputString = "Message to^encode";
|
||||||
keyword = "QUEENLY";
|
keyword = "keyword";
|
||||||
correctOutput = "Qnxepvyt-wtwp";
|
correctOutput = "Wiqooxhfs^wfcuhx";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no whitespace mixed case, whitespace, symbol decoding.", correctOutput, output);
|
assertEquals("Autokey failed no whitespace mixed case, whitespace, symbol encoding.", 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
|
@Test
|
||||||
public void testNoSymbolEncode() throws InvalidKeywordException, InvalidInputException{
|
public void testNoSymbolEncode() throws InvalidKeywordException, InvalidInputException{
|
||||||
Autokey cipher = new Autokey(true, true, false);
|
Autokey cipher = new Autokey(true, true, false);
|
||||||
|
|
||||||
//Test lowercase decoding
|
//Test lowercase encoding
|
||||||
String input = "attack";
|
String inputString = "messagetoencode";
|
||||||
String keyword = "queenly";
|
String keyword = "keyword";
|
||||||
String correctOutput = "qnxepv";
|
String correctOutput = "wiqooxhfswfcuhx";
|
||||||
String output = cipher.encode(keyword, input);
|
String output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no symbol lowercase decoding.", correctOutput, output);
|
assertEquals("Autokey failed no symbol lowercase encoding.", correctOutput, output);
|
||||||
//Test uppercase decoding
|
//Test uppercase encoding
|
||||||
input = "ATTACK";
|
inputString = "MESSAGETOENCODE";
|
||||||
keyword = "queenly";
|
keyword = "keyword";
|
||||||
correctOutput = "QNXEPV";
|
correctOutput = "WIQOOXHFSWFCUHX";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no symbol uppercase decoding.", correctOutput, output);
|
assertEquals("Autokey failed no symbol uppercase encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test whitespace encoding
|
||||||
|
inputString = "message to encode";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "wiqooxh fs wfcuhx";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Autokey failed no symbol whitespace encoding.", correctOutput, output);
|
||||||
|
|
||||||
//Test whitespace decoding
|
//Test symbol encoding
|
||||||
input = "attack at dawn";
|
inputString = "message*to+encode";
|
||||||
keyword = "queenly";
|
keyword = "keyword";
|
||||||
correctOutput = "qnxepv yt wtwp";
|
correctOutput = "wiqooxhfswfcuhx";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no symbol whitespace decoding.", correctOutput, output);
|
assertEquals("Autokey failed no symbol symbol encoding.", 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
|
//Test mixed case, whitespace, symbol encoding
|
||||||
input = "Attack at - dawn";
|
inputString = "Message to^encode";
|
||||||
keyword = "QUEENLY";
|
keyword = "keyword";
|
||||||
correctOutput = "Qnxepv yt wtwp";
|
correctOutput = "Wiqooxh fswfcuhx";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no symbol mixed case, whitespace, symbol decoding.", correctOutput, output);
|
assertEquals("Autokey failed no symbol mixed case, whitespace, symbol encoding.", 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
|
@Test
|
||||||
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidKeywordException, InvalidInputException{
|
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidKeywordException, InvalidInputException{
|
||||||
Autokey cipher = new Autokey(false, false, false);
|
Autokey cipher = new Autokey(false, false, false);
|
||||||
|
|
||||||
//Test lowercase decoding
|
//Test lowercase encoding
|
||||||
String input = "attack";
|
String inputString = "messagetoencode";
|
||||||
String keyword = "queenly";
|
String keyword = "keyword";
|
||||||
String correctOutput = "qnxepv";
|
String correctOutput = "WIQOOXHFSWFCUHX";
|
||||||
String output = cipher.encode(keyword, input);
|
String output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Autokey failed secure lowercase decoding.", correctOutput, output);
|
assertEquals("Autokey failed secure lowercase encoding.", correctOutput, output);
|
||||||
//Test uppercase decoding
|
//Test uppercase encoding
|
||||||
input = "ATTACK";
|
inputString = "MESSAGETOENCODE";
|
||||||
keyword = "queenly";
|
keyword = "keyword";
|
||||||
correctOutput = "qnxepv";
|
correctOutput = "WIQOOXHFSWFCUHX";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Autokey failed secure uppercase decoding.", correctOutput, output);
|
assertEquals("Autokey failed secure uppercase encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test whitespace encoding
|
||||||
|
inputString = "message to encode";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "WIQOOXHFSWFCUHX";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Autokey failed secure whitespace encoding.", correctOutput, output);
|
||||||
|
|
||||||
//Test whitespace decoding
|
//Test symbol encoding
|
||||||
input = "attack at dawn";
|
inputString = "message*to+encode";
|
||||||
keyword = "queenly";
|
keyword = "keyword";
|
||||||
correctOutput = "qnxepvytwtwp";
|
correctOutput = "WIQOOXHFSWFCUHX";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Autokey failed secure whitespace decoding.", correctOutput, output);
|
assertEquals("Autokey failed secure symbol encoding.", 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
|
//Test mixed case, whitespace, symbol encoding
|
||||||
input = "Attack at - dawn";
|
inputString = "Message to^encode";
|
||||||
keyword = "QUEENLY";
|
keyword = "keyword";
|
||||||
correctOutput = "qnxepvytwtwp";
|
correctOutput = "WIQOOXHFSWFCUHX";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Autokey failed secure mixed case, whitespace, symbol decoding.", correctOutput, output);
|
assertEquals("Autokey failed secure mixed case, whitespace, symbol encoding.", 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -256,235 +215,194 @@ public class TestAutokey{
|
|||||||
Autokey cipher = new Autokey(true, true, true);
|
Autokey cipher = new Autokey(true, true, true);
|
||||||
|
|
||||||
//Test lowercase decoding
|
//Test lowercase decoding
|
||||||
String input = "qnxepv";
|
String inputString = "wiqooxhfswfcuhx";
|
||||||
String keyword = "queenly";
|
String keyword = "keyword";
|
||||||
String correctOutput = "attack";
|
String correctOutput = "messagetoencode";
|
||||||
String output = cipher.decode(keyword, input);
|
String output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Autokey failed lowercase decoding.", correctOutput, output);
|
assertEquals("Autokey failed lowercase decoding.", correctOutput, output);
|
||||||
//Test uppercase decoding
|
//Test uppercase decoding
|
||||||
input = "QNXEPV";
|
inputString = "WIQOOXHFSWFCUHX";
|
||||||
keyword = "queenly";
|
keyword = "keyword";
|
||||||
correctOutput = "ATTACK";
|
correctOutput = "MESSAGETOENCODE";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Autokey failed uppercase decoding.", correctOutput, output);
|
assertEquals("Autokey failed uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace decoding
|
//Test whitespace decoding
|
||||||
input = "qnxepv yt wtwp";
|
inputString = "wiqooxh fs wfcuhx";
|
||||||
keyword = "queenly";
|
keyword = "keyword";
|
||||||
correctOutput = "attack at dawn";
|
correctOutput = "message to encode";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Autokey failed whitespace decoding.", correctOutput, output);
|
assertEquals("Autokey failed whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
//Test symbol decoding
|
||||||
input = "qnxepv@yt-wtwp";
|
inputString = "wiqooxh*fs+wfcuhx";
|
||||||
keyword = "queenly";
|
keyword = "keyword";
|
||||||
correctOutput = "attack@at-dawn";
|
correctOutput = "message*to+encode";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Autokey failed symbol decoding.", correctOutput, output);
|
assertEquals("Autokey failed symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, symbol decoding
|
//Test mixed case, whitespace, symbol decoding
|
||||||
input = "Qnxepv yt - wtwp";
|
inputString = "Wiqooxh fs^wfcuhx";
|
||||||
keyword = "QUEENLY";
|
keyword = "keyword";
|
||||||
correctOutput = "Attack at - dawn";
|
correctOutput = "Message to^encode";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Autokey failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
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
|
@Test
|
||||||
public void testNoCapitalDecode() throws InvalidKeywordException, InvalidInputException{
|
public void testNoCapitalDecode() throws InvalidKeywordException, InvalidInputException{
|
||||||
Autokey cipher = new Autokey(false, true, true);
|
Autokey cipher = new Autokey(false, true, true);
|
||||||
|
|
||||||
//Test lowercase decoding
|
//Test lowercase decoding
|
||||||
String input = "qnxepv";
|
String inputString = "WIQOOXHFSWFCUHX";
|
||||||
String keyword = "queenly";
|
String keyword = "keyword";
|
||||||
String correctOutput = "attack";
|
String correctOutput = "MESSAGETOENCODE";
|
||||||
String output = cipher.decode(keyword, input);
|
String output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no capital lowercase decoding.", correctOutput, output);
|
assertEquals("Autokey failed no capital lowercase decoding.", correctOutput, output);
|
||||||
//Test uppercase decoding
|
//Test uppercase decoding
|
||||||
input = "QNXEPV";
|
inputString = "WIQOOXHFSWFCUHX";
|
||||||
keyword = "queenly";
|
keyword = "keyword";
|
||||||
correctOutput = "attack";
|
correctOutput = "MESSAGETOENCODE";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no capital uppercase decoding.", correctOutput, output);
|
assertEquals("Autokey failed no capital uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace decoding
|
//Test whitespace decoding
|
||||||
input = "qnxepv yt wtwp";
|
inputString = "WIQOOXH FS WFCUHX";
|
||||||
keyword = "queenly";
|
keyword = "keyword";
|
||||||
correctOutput = "attack at dawn";
|
correctOutput = "MESSAGE TO ENCODE";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no capital whitespace decoding.", correctOutput, output);
|
assertEquals("Autokey failed no capital whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
//Test symbol decoding
|
||||||
input = "qnxepv@yt-wtwp";
|
inputString = "WIQOOXH*FS+WFCUHX";
|
||||||
keyword = "queenly";
|
keyword = "keyword";
|
||||||
correctOutput = "attack@at-dawn";
|
correctOutput = "MESSAGE*TO+ENCODE";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no capital symbol decoding.", correctOutput, output);
|
assertEquals("Autokey failed no capital symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, symbol decoding
|
//Test mixed case, whitespace, symbol decoding
|
||||||
input = "Qnxepv yt - wtwp";
|
inputString = "WIQOOXH FS^WFCUHX";
|
||||||
keyword = "QUEENLY";
|
keyword = "keyword";
|
||||||
correctOutput = "attack at - dawn";
|
correctOutput = "MESSAGE TO^ENCODE";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no capital mixed case, whitespace, symbol decoding.", correctOutput, output);
|
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
|
@Test
|
||||||
public void testNoWhitespaceDecode() throws InvalidKeywordException, InvalidInputException{
|
public void testNoWhitespaceDecode() throws InvalidKeywordException, InvalidInputException{
|
||||||
Autokey cipher = new Autokey(true, false, true);
|
Autokey cipher = new Autokey(true, false, true);
|
||||||
|
|
||||||
//Test lowercase decoding
|
//Test lowercase decoding
|
||||||
String input = "qnxepv";
|
String inputString = "wiqooxhfswfcuhx";
|
||||||
String keyword = "queenly";
|
String keyword = "keyword";
|
||||||
String correctOutput = "attack";
|
String correctOutput = "messagetoencode";
|
||||||
String output = cipher.decode(keyword, input);
|
String output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no whitespace lowercase decoding.", correctOutput, output);
|
assertEquals("Autokey failed no whitespace lowercase decoding.", correctOutput, output);
|
||||||
//Test uppercase decoding
|
//Test uppercase decoding
|
||||||
input = "QNXEPV";
|
inputString = "WIQOOXHFSWFCUHX";
|
||||||
keyword = "queenly";
|
keyword = "keyword";
|
||||||
correctOutput = "ATTACK";
|
correctOutput = "MESSAGETOENCODE";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no whitespace uppercase decoding.", correctOutput, output);
|
assertEquals("Autokey failed no whitespace uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace decoding
|
//Test whitespace decoding
|
||||||
input = "qnxepv yt wtwp";
|
inputString = "wiqooxh fs wfcuhx";
|
||||||
keyword = "queenly";
|
keyword = "keyword";
|
||||||
correctOutput = "attackatdawn";
|
correctOutput = "messagetoencode";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no whitespace whitespace decoding.", correctOutput, output);
|
assertEquals("Autokey failed no whitespace whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
//Test symbol decoding
|
||||||
input = "qnxepv@yt-wtwp";
|
inputString = "wiqooxh*fs+wfcuhx";
|
||||||
keyword = "queenly";
|
keyword = "keyword";
|
||||||
correctOutput = "attack@at-dawn";
|
correctOutput = "message*to+encode";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no whitespace symbol decoding.", correctOutput, output);
|
assertEquals("Autokey failed no whitespace symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, symbol decoding
|
//Test mixed case, whitespace, symbol decoding
|
||||||
input = "Qnxepv yt - wtwp";
|
inputString = "Wiqooxh fs^wfcuhx";
|
||||||
keyword = "QUEENLY";
|
keyword = "keyword";
|
||||||
correctOutput = "Attackat-dawn";
|
correctOutput = "Messageto^encode";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no whitespace mixed case, whitespace, symbol decoding.", correctOutput, output);
|
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
|
@Test
|
||||||
public void testNoSymbolDecode() throws InvalidKeywordException, InvalidInputException{
|
public void testNoSymbolDecode() throws InvalidKeywordException, InvalidInputException{
|
||||||
Autokey cipher = new Autokey(true, true, false);
|
Autokey cipher = new Autokey(true, true, false);
|
||||||
|
|
||||||
//Test lowercase decoding
|
//Test lowercase decoding
|
||||||
String input = "qnxepv";
|
String inputString = "wiqooxhfswfcuhx";
|
||||||
String keyword = "queenly";
|
String keyword = "keyword";
|
||||||
String correctOutput = "attack";
|
String correctOutput = "messagetoencode";
|
||||||
String output = cipher.decode(keyword, input);
|
String output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no symbol lowercase decoding.", correctOutput, output);
|
assertEquals("Autokey failed no symbol lowercase decoding.", correctOutput, output);
|
||||||
//Test uppercase decoding
|
//Test uppercase decoding
|
||||||
input = "QNXEPV";
|
inputString = "WIQOOXHFSWFCUHX";
|
||||||
keyword = "queenly";
|
keyword = "keyword";
|
||||||
correctOutput = "ATTACK";
|
correctOutput = "MESSAGETOENCODE";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no symbol uppercase decoding.", correctOutput, output);
|
assertEquals("Autokey failed no symbol uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace decoding
|
//Test whitespace decoding
|
||||||
input = "qnxepv yt wtwp";
|
inputString = "wiqooxh fs wfcuhx";
|
||||||
keyword = "queenly";
|
keyword = "keyword";
|
||||||
correctOutput = "attack at dawn";
|
correctOutput = "message to encode";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no symbol whitespace decoding.", correctOutput, output);
|
assertEquals("Autokey failed no symbol whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
//Test symbol decoding
|
||||||
input = "qnxepv@yt-wtwp";
|
inputString = "wiqooxh*fs+wfcuhx";
|
||||||
keyword = "queenly";
|
keyword = "keyword";
|
||||||
correctOutput = "attackatdawn";
|
correctOutput = "messagetoencode";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no symbol symbol decoding.", correctOutput, output);
|
assertEquals("Autokey failed no symbol symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, symbol decoding
|
//Test mixed case, whitespace, symbol decoding
|
||||||
input = "Qnxepv yt - wtwp";
|
inputString = "Wiqooxh fs^wfcuhx";
|
||||||
keyword = "QUEENLY";
|
keyword = "keyword";
|
||||||
correctOutput = "Attack at dawn";
|
correctOutput = "Message toencode";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Autokey failed no symbol mixed case, whitespace, symbol decoding.", correctOutput, output);
|
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
|
@Test
|
||||||
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidKeywordException, InvalidInputException{
|
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidKeywordException, InvalidInputException{
|
||||||
Autokey cipher = new Autokey(false, false, false);
|
Autokey cipher = new Autokey(false, false, false);
|
||||||
|
|
||||||
//Test lowercase decoding
|
//Test lowercase decoding
|
||||||
String input = "qnxepv";
|
String inputString = "WIQOOXHFSWFCUHX";
|
||||||
String keyword = "queenly";
|
String keyword = "keyword";
|
||||||
String correctOutput = "attack";
|
String correctOutput = "MESSAGETOENCODE";
|
||||||
String output = cipher.decode(keyword, input);
|
String output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Autokey failed secure lowercase decoding.", correctOutput, output);
|
assertEquals("Autokey failed secure lowercase decoding.", correctOutput, output);
|
||||||
//Test uppercase decoding
|
//Test uppercase decoding
|
||||||
input = "QNXEPV";
|
inputString = "WIQOOXHFSWFCUHX";
|
||||||
keyword = "queenly";
|
keyword = "keyword";
|
||||||
correctOutput = "attack";
|
correctOutput = "MESSAGETOENCODE";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Autokey failed secure uppercase decoding.", correctOutput, output);
|
assertEquals("Autokey failed secure uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace decoding
|
//Test whitespace decoding
|
||||||
input = "qnxepv yt wtwp";
|
inputString = "WIQOOXH FS WFCUHX";
|
||||||
keyword = "queenly";
|
keyword = "keyword";
|
||||||
correctOutput = "attackatdawn";
|
correctOutput = "MESSAGETOENCODE";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Autokey failed secure whitespace decoding.", correctOutput, output);
|
assertEquals("Autokey failed secure whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
//Test symbol decoding
|
||||||
input = "qnxepv@yt-wtwp";
|
inputString = "WIQOOXH*FS+WFCUHX";
|
||||||
keyword = "queenly";
|
keyword = "keyword";
|
||||||
correctOutput = "attackatdawn";
|
correctOutput = "MESSAGETOENCODE";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Autokey failed secure symbol decoding.", correctOutput, output);
|
assertEquals("Autokey failed secure symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, symbol decoding
|
//Test mixed case, whitespace, symbol decoding
|
||||||
input = "Qnxepv yt - wtwp";
|
inputString = "WIQOOXH FS^WFCUHX";
|
||||||
keyword = "QUEENLY";
|
keyword = "keyword";
|
||||||
correctOutput = "attackatdawn";
|
correctOutput = "MESSAGETOENCODE";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Autokey failed secure mixed case, whitespace, symbol decoding.", correctOutput, output);
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -497,7 +415,7 @@ public class TestAutokey{
|
|||||||
String correctOutput = "XYZ";
|
String correctOutput = "XYZ";
|
||||||
cipher.setKeyword(keyword);
|
cipher.setKeyword(keyword);
|
||||||
String output = cipher.getKeyword();
|
String output = cipher.getKeyword();
|
||||||
assertEquals("Vigenere failed keyword with whitespace", correctOutput, output);
|
assertEquals("Vigenere failed keyword with whitespace.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test keyword with symbol
|
//Test keyword with symbol
|
||||||
@@ -505,7 +423,7 @@ public class TestAutokey{
|
|||||||
correctOutput = "XYZ";
|
correctOutput = "XYZ";
|
||||||
cipher.setKeyword(keyword);
|
cipher.setKeyword(keyword);
|
||||||
output = cipher.getKeyword();
|
output = cipher.getKeyword();
|
||||||
assertEquals("Vigenere failed keyword with symbol", correctOutput, output);
|
assertEquals("Vigenere failed keyword with symbol.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test keyword with mixed case
|
//Test keyword with mixed case
|
||||||
@@ -513,13 +431,13 @@ public class TestAutokey{
|
|||||||
correctOutput = "XYZ";
|
correctOutput = "XYZ";
|
||||||
cipher.setKeyword(keyword);
|
cipher.setKeyword(keyword);
|
||||||
output = cipher.getKeyword();
|
output = cipher.getKeyword();
|
||||||
assertEquals("Vigenere failed keyword with mixed case", correctOutput, output);
|
assertEquals("Vigenere failed keyword with mixed case.", correctOutput, output);
|
||||||
|
|
||||||
//Test keyword with whitespace, symbol and keyword
|
//Test keyword with whitespace, symbol and keyword
|
||||||
keyword = "x Y%z ";
|
keyword = "x Y%z ";
|
||||||
correctOutput = "XYZ";
|
correctOutput = "XYZ";
|
||||||
cipher.setKeyword(keyword);
|
cipher.setKeyword(keyword);
|
||||||
output = cipher.getKeyword();
|
output = cipher.getKeyword();
|
||||||
assertEquals("Vigenere failed keyword with space, symbol, and mixed case", correctOutput, output);
|
assertEquals("Vigenere failed keyword with space, symbol, and mixed case.", correctOutput, output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user