Updated tests
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/TestVigenere.java
|
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/monoSubstitution/TestVigenere.java
|
||||||
//Matthew Ellison
|
//Mattrixwv
|
||||||
// Created: 07-25-21
|
// Created: 07-25-21
|
||||||
//Modified: 01-09-22
|
//Modified: 02-22-22
|
||||||
package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
||||||
|
|
||||||
|
|
||||||
@@ -19,235 +19,194 @@ public class TestVigenere{
|
|||||||
Vigenere cipher = new Vigenere(true, true, true);
|
Vigenere cipher = new Vigenere(true, true, true);
|
||||||
|
|
||||||
//Test lowercase encoding
|
//Test lowercase encoding
|
||||||
String input = "abc";
|
String inputString = "messagetoencode";
|
||||||
String keyword = "xyz";
|
String keyword = "keyword";
|
||||||
String correctOutput = "xzb";
|
String correctOutput = "wiqooxhdscjqfgo";
|
||||||
String output = cipher.encode(keyword, input);
|
String output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed lowercase encoding.", correctOutput, output);
|
assertEquals("Vigenere failed lowercase encoding.", correctOutput, output);
|
||||||
//Test upercase encoding
|
//Test uppercase encoding
|
||||||
input = "ABC";
|
inputString = "MESSAGETOENCODE";
|
||||||
keyword = "xyz";
|
keyword = "keyword";
|
||||||
correctOutput = "XZB";
|
correctOutput = "WIQOOXHDSCJQFGO";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed uppercase encoding.", correctOutput, output);
|
assertEquals("Vigenere failed uppercase encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace encoding
|
//Test whitespace encoding
|
||||||
input = "a b c";
|
inputString = "message to encode";
|
||||||
keyword = "xyz";
|
keyword = "keyword";
|
||||||
correctOutput = "x z b";
|
correctOutput = "wiqooxh ds cjqfgo";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed whitespace encoding.", correctOutput, output);
|
assertEquals("Vigenere failed whitespace encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test symbol encoding
|
||||||
//Test symbol decoding
|
inputString = "message*to+encode";
|
||||||
input = "a@b^c";
|
keyword = "keyword";
|
||||||
keyword = "xyz";
|
correctOutput = "wiqooxh*ds+cjqfgo";
|
||||||
correctOutput = "x@z^b";
|
output = cipher.encode(keyword, inputString);
|
||||||
output = cipher.encode(keyword, input);
|
|
||||||
assertEquals("Vigenere failed symbol encoding.", correctOutput, output);
|
assertEquals("Vigenere failed symbol encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol encoding
|
||||||
//Test mixed case, whitespace, symbol decoding
|
inputString = "Message to^encode";
|
||||||
input = "Attack at dawn";
|
keyword = "keyword";
|
||||||
keyword = "lemon";
|
correctOutput = "Wiqooxh ds^cjqfgo";
|
||||||
correctOutput = "Lxfopv ef rnhr";
|
output = cipher.encode(keyword, inputString);
|
||||||
output = cipher.encode(keyword, input);
|
assertEquals("Vigenere failed symbol encoding.", correctOutput, output);
|
||||||
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
|
@Test
|
||||||
public void testNoCapitalEncode() throws InvalidKeywordException, InvalidInputException{
|
public void testNoCapitalEncode() throws InvalidKeywordException, InvalidInputException{
|
||||||
Vigenere cipher = new Vigenere(false, true, true);
|
Vigenere cipher = new Vigenere(false, true, true);
|
||||||
|
|
||||||
//Test lowercase encoding
|
//Test lowercase encoding
|
||||||
String input = "abc";
|
String inputString = "messagetoencode";
|
||||||
String keyword = "xyz";
|
String keyword = "keyword";
|
||||||
String correctOutput = "xzb";
|
String correctOutput = "WIQOOXHDSCJQFGO";
|
||||||
String output = cipher.encode(keyword, input);
|
String output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed lowercase encoding.", correctOutput, output);
|
assertEquals("Vigenere failed no capital lowercase encoding.", correctOutput, output);
|
||||||
//Test upercase encoding
|
//Test uppercase encoding
|
||||||
input = "ABC";
|
inputString = "MESSAGETOENCODE";
|
||||||
keyword = "xyz";
|
keyword = "keyword";
|
||||||
correctOutput = "xzb";
|
correctOutput = "WIQOOXHDSCJQFGO";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed uppercase encoding.", correctOutput, output);
|
assertEquals("Vigenere failed no capital uppercase encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace encoding
|
//Test whitespace encoding
|
||||||
input = "a b c";
|
inputString = "message to encode";
|
||||||
keyword = "xyz";
|
keyword = "keyword";
|
||||||
correctOutput = "x z b";
|
correctOutput = "WIQOOXH DS CJQFGO";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed whitespace encoding.", correctOutput, output);
|
assertEquals("Vigenere failed no capital whitespace encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test symbol encoding
|
||||||
|
inputString = "message*to+encode";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "WIQOOXH*DS+CJQFGO";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Vigenere failed no capital symbol encoding.", correctOutput, output);
|
||||||
|
|
||||||
//Test symbol decoding
|
//Test mixed case, whitespace, symbol encoding
|
||||||
input = "a@b^c";
|
inputString = "Message to^encode";
|
||||||
keyword = "xyz";
|
keyword = "keyword";
|
||||||
correctOutput = "x@z^b";
|
correctOutput = "WIQOOXH DS^CJQFGO";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed symbol encoding.", correctOutput, output);
|
assertEquals("Vigenere failed no capital 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
|
@Test
|
||||||
public void testNoWhitespaceEncode() throws InvalidKeywordException, InvalidInputException{
|
public void testNoWhitespaceEncode() throws InvalidKeywordException, InvalidInputException{
|
||||||
Vigenere cipher = new Vigenere(true, false, true);
|
Vigenere cipher = new Vigenere(true, false, true);
|
||||||
|
|
||||||
//Test lowercase encoding
|
//Test lowercase encoding
|
||||||
String input = "abc";
|
String inputString = "messagetoencode";
|
||||||
String keyword = "xyz";
|
String keyword = "keyword";
|
||||||
String correctOutput = "xzb";
|
String correctOutput = "wiqooxhdscjqfgo";
|
||||||
String output = cipher.encode(keyword, input);
|
String output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed lowercase encoding.", correctOutput, output);
|
assertEquals("Vigenere failed no whitespace lowercase encoding.", correctOutput, output);
|
||||||
//Test upercase encoding
|
//Test uppercase encoding
|
||||||
input = "ABC";
|
inputString = "MESSAGETOENCODE";
|
||||||
keyword = "xyz";
|
keyword = "keyword";
|
||||||
correctOutput = "XZB";
|
correctOutput = "WIQOOXHDSCJQFGO";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed uppercase encoding.", correctOutput, output);
|
assertEquals("Vigenere failed no whitespace uppercase encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace encoding
|
//Test whitespace encoding
|
||||||
input = "a b c";
|
inputString = "message to encode";
|
||||||
keyword = "xyz";
|
keyword = "keyword";
|
||||||
correctOutput = "xzb";
|
correctOutput = "wiqooxhdscjqfgo";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed whitespace encoding.", correctOutput, output);
|
assertEquals("Vigenere failed no whitespace whitespace encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test symbol encoding
|
||||||
|
inputString = "message*to+encode";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "wiqooxh*ds+cjqfgo";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Vigenere failed no whitespace symbol encoding.", correctOutput, output);
|
||||||
|
|
||||||
//Test symbol decoding
|
//Test mixed case, whitespace, symbol encoding
|
||||||
input = "a@b^c";
|
inputString = "Message to^encode";
|
||||||
keyword = "xyz";
|
keyword = "keyword";
|
||||||
correctOutput = "x@z^b";
|
correctOutput = "Wiqooxhds^cjqfgo";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed symbol encoding.", correctOutput, output);
|
assertEquals("Vigenere failed no whitespace 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
|
@Test
|
||||||
public void testNoSymbolEncode() throws InvalidKeywordException, InvalidInputException{
|
public void testNoSymbolEncode() throws InvalidKeywordException, InvalidInputException{
|
||||||
Vigenere cipher = new Vigenere(true, true, false);
|
Vigenere cipher = new Vigenere(true, true, false);
|
||||||
|
|
||||||
//Test lowercase encoding
|
//Test lowercase encoding
|
||||||
String input = "abc";
|
String inputString = "messagetoencode";
|
||||||
String keyword = "xyz";
|
String keyword = "keyword";
|
||||||
String correctOutput = "xzb";
|
String correctOutput = "wiqooxhdscjqfgo";
|
||||||
String output = cipher.encode(keyword, input);
|
String output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed lowercase encoding.", correctOutput, output);
|
assertEquals("Vigenere failed no symbol lowercase encoding.", correctOutput, output);
|
||||||
//Test upercase encoding
|
//Test uppercase encoding
|
||||||
input = "ABC";
|
inputString = "MESSAGETOENCODE";
|
||||||
keyword = "xyz";
|
keyword = "keyword";
|
||||||
correctOutput = "XZB";
|
correctOutput = "WIQOOXHDSCJQFGO";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed uppercase encoding.", correctOutput, output);
|
assertEquals("Vigenere failed no symbol uppercase encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace encoding
|
//Test whitespace encoding
|
||||||
input = "a b c";
|
inputString = "message to encode";
|
||||||
keyword = "xyz";
|
keyword = "keyword";
|
||||||
correctOutput = "x z b";
|
correctOutput = "wiqooxh ds cjqfgo";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed whitespace encoding.", correctOutput, output);
|
assertEquals("Vigenere failed no symbol whitespace encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test symbol encoding
|
||||||
|
inputString = "message*to+encode";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "wiqooxhdscjqfgo";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Vigenere failed no symbol symbol encoding.", correctOutput, output);
|
||||||
|
|
||||||
//Test symbol decoding
|
//Test mixed case, whitespace, symbol encoding
|
||||||
input = "a@b^c";
|
inputString = "Message to^encode";
|
||||||
keyword = "xyz";
|
keyword = "keyword";
|
||||||
correctOutput = "xzb";
|
correctOutput = "Wiqooxh dscjqfgo";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed symbol encoding.", correctOutput, output);
|
assertEquals("Vigenere failed no symbol 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
|
@Test
|
||||||
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidKeywordException, InvalidInputException{
|
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidKeywordException, InvalidInputException{
|
||||||
Vigenere cipher = new Vigenere(false, false, false);
|
Vigenere cipher = new Vigenere(false, false, false);
|
||||||
|
|
||||||
//Test lowercase encoding
|
//Test lowercase encoding
|
||||||
String input = "abc";
|
String inputString = "messagetoencode";
|
||||||
String keyword = "xyz";
|
String keyword = "keyword";
|
||||||
String correctOutput = "xzb";
|
String correctOutput = "WIQOOXHDSCJQFGO";
|
||||||
String output = cipher.encode(keyword, input);
|
String output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed lowercase encoding.", correctOutput, output);
|
assertEquals("Vigenere failed secure lowercase encoding.", correctOutput, output);
|
||||||
//Test upercase encoding
|
//Test uppercase encoding
|
||||||
input = "ABC";
|
inputString = "MESSAGETOENCODE";
|
||||||
keyword = "xyz";
|
keyword = "keyword";
|
||||||
correctOutput = "xzb";
|
correctOutput = "WIQOOXHDSCJQFGO";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed uppercase encoding.", correctOutput, output);
|
assertEquals("Vigenere failed secure uppercase encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace encoding
|
//Test whitespace encoding
|
||||||
input = "a b c";
|
inputString = "message to encode";
|
||||||
keyword = "xyz";
|
keyword = "keyword";
|
||||||
correctOutput = "xzb";
|
correctOutput = "WIQOOXHDSCJQFGO";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed whitespace encoding.", correctOutput, output);
|
assertEquals("Vigenere failed secure whitespace encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test symbol encoding
|
||||||
|
inputString = "message*to+encode";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "WIQOOXHDSCJQFGO";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Vigenere failed secure symbol encoding.", correctOutput, output);
|
||||||
|
|
||||||
//Test symbol decoding
|
//Test mixed case, whitespace, symbol encoding
|
||||||
input = "a@b^c";
|
inputString = "Message to^encode";
|
||||||
keyword = "xyz";
|
keyword = "keyword";
|
||||||
correctOutput = "xzb";
|
correctOutput = "WIQOOXHDSCJQFGO";
|
||||||
output = cipher.encode(keyword, input);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed symbol encoding.", correctOutput, output);
|
assertEquals("Vigenere failed secure 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -256,270 +215,193 @@ public class TestVigenere{
|
|||||||
Vigenere cipher = new Vigenere(true, true, true);
|
Vigenere cipher = new Vigenere(true, true, true);
|
||||||
|
|
||||||
//Test lowercase decoding
|
//Test lowercase decoding
|
||||||
String input = "xzb";
|
String inputString = "wiqooxhdscjqfgo";
|
||||||
String keyword = "xyz";
|
String keyword = "keyword";
|
||||||
String correctOutput = "abc";
|
String correctOutput = "messagetoencode";
|
||||||
String output = cipher.decode(keyword, input);
|
String output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed lowercase decoding.", correctOutput, output);
|
assertEquals("Vigenere failed lowercase decoding.", correctOutput, output);
|
||||||
//Test uppercase decoding
|
//Test uppercase decoding
|
||||||
input = "XZB";
|
inputString = "WIQOOXHDSCJQFGO";
|
||||||
keyword = "XYZ";
|
keyword = "keyword";
|
||||||
correctOutput = "ABC";
|
correctOutput = "MESSAGETOENCODE";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed uppercase decoding.", correctOutput, output);
|
assertEquals("Vigenere failed uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace decoding
|
//Test whitespace decoding
|
||||||
input = "x z b";
|
inputString = "wiqooxh ds cjqfgo";
|
||||||
keyword = "xyz";
|
keyword = "keyword";
|
||||||
correctOutput = "a b c";
|
correctOutput = "message to encode";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed whitespace decoding.", correctOutput, output);
|
assertEquals("Vigenere failed whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
//Test symbol decoding
|
||||||
input = "x@z^b";
|
inputString = "wiqooxh*ds+cjqfgo";
|
||||||
keyword = "xyz";
|
keyword = "keyword";
|
||||||
correctOutput = "a@b^c";
|
correctOutput = "message*to+encode";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed symbol decoding.", correctOutput, output);
|
assertEquals("Vigenere failed symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, symbol decoding
|
//Test mixed case, whitespace, symbol decoding
|
||||||
input = "Lxfopv ef - rnhr";
|
inputString = "Wiqooxh ds^cjqfgo";
|
||||||
keyword = "lemon";
|
keyword = "keyword";
|
||||||
correctOutput = "Attack at - dawn";
|
correctOutput = "Message to^encode";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
assertEquals("Vigenere failed 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
|
@Test
|
||||||
public void testNoCapitalDecode() throws InvalidKeywordException, InvalidInputException{
|
public void testNoCapitalDecode() throws InvalidKeywordException, InvalidInputException{
|
||||||
Vigenere cipher = new Vigenere(false, true, true);
|
Vigenere cipher = new Vigenere(false, true, true);
|
||||||
|
|
||||||
//Test lowercase decoding
|
//Test lowercase decoding
|
||||||
String input = "xzb";
|
String inputString = "wiqooxhdscjqfgo";
|
||||||
String keyword = "xyz";
|
String keyword = "keyword";
|
||||||
String correctOutput = "abc";
|
String correctOutput = "MESSAGETOENCODE";
|
||||||
String output = cipher.decode(keyword, input);
|
String output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed lowercase decoding.", correctOutput, output);
|
assertEquals("Vigenere failed no capital lowercase decoding.", correctOutput, output);
|
||||||
//Test uppercase decoding
|
//Test uppercase decoding
|
||||||
input = "XZB";
|
inputString = "WIQOOXHDSCJQFGO";
|
||||||
keyword = "XYZ";
|
keyword = "keyword";
|
||||||
correctOutput = "abc";
|
correctOutput = "MESSAGETOENCODE";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed uppercase decoding.", correctOutput, output);
|
assertEquals("Vigenere failed no capital uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace decoding
|
//Test whitespace decoding
|
||||||
input = "x z b";
|
inputString = "wiqooxh ds cjqfgo";
|
||||||
keyword = "xyz";
|
keyword = "keyword";
|
||||||
correctOutput = "a b c";
|
correctOutput = "MESSAGE TO ENCODE";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed whitespace decoding.", correctOutput, output);
|
assertEquals("Vigenere failed no capital whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
//Test symbol decoding
|
||||||
input = "x@z^b";
|
inputString = "wiqooxh*ds+cjqfgo";
|
||||||
keyword = "xyz";
|
keyword = "keyword";
|
||||||
correctOutput = "a@b^c";
|
correctOutput = "MESSAGE*TO+ENCODE";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed symbol decoding.", correctOutput, output);
|
assertEquals("Vigenere failed no capital symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, symbol decoding
|
//Test mixed case, whitespace, symbol decoding
|
||||||
input = "Lxfopv ef - rnhr";
|
inputString = "Wiqooxh ds^cjqfgo";
|
||||||
keyword = "lemon";
|
keyword = "keyword";
|
||||||
correctOutput = "attack at - dawn";
|
correctOutput = "MESSAGE TO^ENCODE";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
assertEquals("Vigenere failed no capital 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
|
@Test
|
||||||
public void testNoWhitespaceDecode() throws InvalidKeywordException, InvalidInputException{
|
public void testNoWhitespaceDecode() throws InvalidKeywordException, InvalidInputException{
|
||||||
Vigenere cipher = new Vigenere(true, false, true);
|
Vigenere cipher = new Vigenere(true, false, true);
|
||||||
|
|
||||||
//Test lowercase decoding
|
//Test lowercase decoding
|
||||||
String input = "xzb";
|
String inputString = "wiqooxhdscjqfgo";
|
||||||
String keyword = "xyz";
|
String keyword = "keyword";
|
||||||
String correctOutput = "abc";
|
String correctOutput = "messagetoencode";
|
||||||
String output = cipher.decode(keyword, input);
|
String output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed lowercase decoding.", correctOutput, output);
|
assertEquals("Vigenere failed no whitespace lowercase decoding.", correctOutput, output);
|
||||||
//Test uppercase decoding
|
//Test uppercase decoding
|
||||||
input = "XZB";
|
inputString = "WIQOOXHDSCJQFGO";
|
||||||
keyword = "XYZ";
|
keyword = "keyword";
|
||||||
correctOutput = "ABC";
|
correctOutput = "MESSAGETOENCODE";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed uppercase decoding.", correctOutput, output);
|
assertEquals("Vigenere failed no whitespace uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace decoding
|
//Test whitespace decoding
|
||||||
input = "x z b";
|
inputString = "wiqooxh ds cjqfgo";
|
||||||
keyword = "xyz";
|
keyword = "keyword";
|
||||||
correctOutput = "abc";
|
correctOutput = "messagetoencode";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed whitespace decoding.", correctOutput, output);
|
assertEquals("Vigenere failed no whitespace whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
//Test symbol decoding
|
||||||
input = "x@z^b";
|
inputString = "wiqooxh*ds+cjqfgo";
|
||||||
keyword = "xyz";
|
keyword = "keyword";
|
||||||
correctOutput = "a@b^c";
|
correctOutput = "message*to+encode";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed symbol decoding.", correctOutput, output);
|
assertEquals("Vigenere failed no whitespace symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, symbol decoding
|
//Test mixed case, whitespace, symbol decoding
|
||||||
input = "Lxfopv ef - rnhr";
|
inputString = "Wiqooxh ds^cjqfgo";
|
||||||
keyword = "lemon";
|
keyword = "keyword";
|
||||||
correctOutput = "Attackat-dawn";
|
correctOutput = "Messageto^encode";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
assertEquals("Vigenere failed no 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
|
@Test
|
||||||
public void testNoSymbolDecode() throws InvalidKeywordException, InvalidInputException{
|
public void testNoSymbolDecode() throws InvalidKeywordException, InvalidInputException{
|
||||||
Vigenere cipher = new Vigenere(true, true, false);
|
Vigenere cipher = new Vigenere(true, true, false);
|
||||||
|
|
||||||
//Test lowercase decoding
|
//Test lowercase decoding
|
||||||
String input = "xzb";
|
String inputString = "wiqooxhdscjqfgo";
|
||||||
String keyword = "xyz";
|
String keyword = "keyword";
|
||||||
String correctOutput = "abc";
|
String correctOutput = "messagetoencode";
|
||||||
String output = cipher.decode(keyword, input);
|
String output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed lowercase decoding.", correctOutput, output);
|
assertEquals("Vigenere failed no symbol lowercase decoding.", correctOutput, output);
|
||||||
//Test uppercase decoding
|
//Test uppercase decoding
|
||||||
input = "XZB";
|
inputString = "WIQOOXHDSCJQFGO";
|
||||||
keyword = "XYZ";
|
keyword = "keyword";
|
||||||
correctOutput = "ABC";
|
correctOutput = "MESSAGETOENCODE";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed uppercase decoding.", correctOutput, output);
|
assertEquals("Vigenere failed no symbol uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace decoding
|
//Test whitespace decoding
|
||||||
input = "x z b";
|
inputString = "wiqooxh ds cjqfgo";
|
||||||
keyword = "xyz";
|
keyword = "keyword";
|
||||||
correctOutput = "a b c";
|
correctOutput = "message to encode";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed whitespace decoding.", correctOutput, output);
|
assertEquals("Vigenere failed no symbol whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
//Test symbol decoding
|
||||||
input = "x@z^b";
|
inputString = "wiqooxh*ds+cjqfgo";
|
||||||
keyword = "xyz";
|
keyword = "keyword";
|
||||||
correctOutput = "abc";
|
correctOutput = "messagetoencode";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed symbol decoding.", correctOutput, output);
|
assertEquals("Vigenere failed no symbol symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, symbol decoding
|
//Test mixed case, whitespace, symbol decoding
|
||||||
input = "Lxfopv ef - rnhr";
|
inputString = "Wiqooxh ds^cjqfgo";
|
||||||
keyword = "lemon";
|
keyword = "keyword";
|
||||||
correctOutput = "Attack at dawn";
|
correctOutput = "Message toencode";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
assertEquals("Vigenere failed no symbol 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
|
@Test
|
||||||
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidKeywordException, InvalidInputException{
|
public void testNoWhitespaceSymbolDecode() throws InvalidKeywordException, InvalidInputException{
|
||||||
Vigenere cipher = new Vigenere(false, false, false);
|
Vigenere cipher = new Vigenere(false, false, false);
|
||||||
|
|
||||||
//Test lowercase decoding
|
//Test lowercase decoding
|
||||||
String input = "xzb";
|
String inputString = "wiqooxhdscjqfgo";
|
||||||
String keyword = "xyz";
|
String keyword = "keyword";
|
||||||
String correctOutput = "abc";
|
String correctOutput = "MESSAGETOENCODE";
|
||||||
String output = cipher.decode(keyword, input);
|
String output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed lowercase decoding.", correctOutput, output);
|
assertEquals("Vigenere failed secure lowercase decoding.", correctOutput, output);
|
||||||
//Test uppercase decoding
|
//Test uppercase decoding
|
||||||
input = "XZB";
|
inputString = "WIQOOXHDSCJQFGO";
|
||||||
keyword = "XYZ";
|
keyword = "keyword";
|
||||||
correctOutput = "abc";
|
correctOutput = "MESSAGETOENCODE";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed uppercase decoding.", correctOutput, output);
|
assertEquals("Vigenere failed secure uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test whitespace decoding
|
//Test whitespace decoding
|
||||||
input = "x z b";
|
inputString = "wiqooxh ds cjqfgo";
|
||||||
keyword = "xyz";
|
keyword = "keyword";
|
||||||
correctOutput = "abc";
|
correctOutput = "MESSAGETOENCODE";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed whitespace decoding.", correctOutput, output);
|
assertEquals("Vigenere failed secure whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test symbol decoding
|
//Test symbol decoding
|
||||||
input = "x@z^b";
|
inputString = "wiqooxh*ds+cjqfgo";
|
||||||
keyword = "xyz";
|
keyword = "keyword";
|
||||||
correctOutput = "abc";
|
correctOutput = "MESSAGETOENCODE";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed symbol decoding.", correctOutput, output);
|
assertEquals("Vigenere failed secure symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
|
||||||
//Test mixed case, whitespace, symbol decoding
|
//Test mixed case, whitespace, symbol decoding
|
||||||
input = "Lxfopv ef rnhr";
|
inputString = "Wiqooxh ds^cjqfgo";
|
||||||
keyword = "lemon";
|
keyword = "keyword";
|
||||||
correctOutput = "attackatdawn";
|
correctOutput = "MESSAGETOENCODE";
|
||||||
output = cipher.decode(keyword, input);
|
output = cipher.decode(keyword, inputString);
|
||||||
assertEquals("Vigenere failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
assertEquals("Vigenere failed secure 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 testKeyword() throws InvalidKeywordException{
|
|
||||||
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