Added exceptions
This commit is contained in:
@@ -7,6 +7,7 @@ package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidKeywordException;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -14,244 +15,7 @@ import org.junit.Test;
|
||||
|
||||
public class TestAutokey{
|
||||
@Test
|
||||
public void testDecode() throws InvalidKeywordException{
|
||||
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 InvalidKeywordException{
|
||||
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 InvalidKeywordException{
|
||||
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 InvalidKeywordException{
|
||||
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 InvalidKeywordException{
|
||||
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 InvalidKeywordException{
|
||||
public void testEncode() throws InvalidKeywordException, InvalidInputException{
|
||||
Autokey cipher = new Autokey(true, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -298,54 +62,7 @@ public class TestAutokey{
|
||||
assertEquals("Autokey failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceEncode() throws InvalidKeywordException{
|
||||
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 InvalidKeywordException{
|
||||
public void testNoCapitalEncode() throws InvalidKeywordException, InvalidInputException{
|
||||
Autokey cipher = new Autokey(false, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -392,7 +109,54 @@ public class TestAutokey{
|
||||
assertEquals("Autokey failed no capital mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolEncode() throws InvalidKeywordException{
|
||||
public void testNoWhitespaceEncode() throws InvalidKeywordException, InvalidInputException{
|
||||
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 testNoSymbolEncode() throws InvalidKeywordException, InvalidInputException{
|
||||
Autokey cipher = new Autokey(true, true, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -439,7 +203,7 @@ public class TestAutokey{
|
||||
assertEquals("Autokey failed no symbol mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidKeywordException{
|
||||
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidKeywordException, InvalidInputException{
|
||||
Autokey cipher = new Autokey(false, false, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
@@ -487,6 +251,243 @@ public class TestAutokey{
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDecode() throws InvalidKeywordException, InvalidInputException{
|
||||
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 testNoCapitalDecode() throws InvalidKeywordException, InvalidInputException{
|
||||
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 testNoWhitespaceDecode() throws InvalidKeywordException, InvalidInputException{
|
||||
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 testNoSymbolDecode() throws InvalidKeywordException, InvalidInputException{
|
||||
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 InvalidKeywordException, InvalidInputException{
|
||||
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 testKeyword() throws InvalidKeywordException{
|
||||
Autokey cipher = new Autokey();
|
||||
|
||||
@@ -8,55 +8,14 @@ package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class TestBaconian{
|
||||
@Test
|
||||
public void testDecode() throws InvalidCharacterException{
|
||||
Baconian cipher = new Baconian(true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "ababb aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(inputString);
|
||||
assertEquals("Baconian failed lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "ABABB AABAA BAAAB BAAAB AAAAA AABBA AABAA BAABA ABBAB AABAA ABBAA AAABA ABBAB AAABB AABAA";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Baconian failed uppercase decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
correctOutput = "Messagetoencode";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Baconian failed mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testDecodeNoCapital() throws InvalidCharacterException{
|
||||
Baconian cipher = new Baconian(false);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "ababb aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(inputString);
|
||||
assertEquals("Baconian failed no capital lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "ABABB AABAA BAAAB BAAAB AAAAA AABBA AABAA BAABA ABBAB AABAA ABBAA AAABA ABBAB AAABB AABAA";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Baconian failed no capital uppercase decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Baconian failed no capital mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testEncode(){
|
||||
public void testEncode() throws InvalidInputException{
|
||||
Baconian cipher = new Baconian(true);
|
||||
|
||||
//Test lowercase encoding
|
||||
@@ -77,7 +36,7 @@ public class TestBaconian{
|
||||
assertEquals("Baconian failed mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testEncodeNoCapital(){
|
||||
public void testEncodeNoCapital() throws InvalidInputException{
|
||||
Baconian cipher = new Baconian(false);
|
||||
|
||||
//Test lowercase encoding
|
||||
@@ -97,4 +56,48 @@ public class TestBaconian{
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Baconian failed no capital mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDecode() throws InvalidCharacterException, InvalidInputException{
|
||||
Baconian cipher = new Baconian(true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "ababb aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(inputString);
|
||||
assertEquals("Baconian failed lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "ABABB AABAA BAAAB BAAAB AAAAA AABBA AABAA BAABA ABBAB AABAA ABBAA AAABA ABBAB AAABB AABAA";
|
||||
correctOutput = "MESSAGETOENCODE";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Baconian failed uppercase decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
correctOutput = "Messagetoencode";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Baconian failed mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testDecodeNoCapital() throws InvalidCharacterException, InvalidInputException{
|
||||
Baconian cipher = new Baconian(false);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "ababb aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
String correctOutput = "messagetoencode";
|
||||
String output = cipher.decode(inputString);
|
||||
assertEquals("Baconian failed no capital lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "ABABB AABAA BAAAB BAAAB AAAAA AABBA AABAA BAABA ABBAB AABAA ABBAA AAABA ABBAB AAABB AABAA";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Baconian failed no capital uppercase decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
correctOutput = "messagetoencode";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Baconian failed no capital mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,145 +9,14 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidBaseException;
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidCharacterException;
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class TestBaseX{
|
||||
@Test
|
||||
public void testBinaryDecode() throws InvalidCharacterException, InvalidBaseException{
|
||||
BaseX cipher = new BaseX();
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "1100001";
|
||||
String correctOutput = "a";
|
||||
String output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed binary lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "1000001";
|
||||
correctOutput = "A";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed binary uppercase decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "1000001 100000 1000010 1001 1000011 1010";
|
||||
correctOutput = "A B\tC\n";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed binary whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "1000001 1000000 1000010 101101 1000011 101011";
|
||||
correctOutput = "A@B-C+";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed binary symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "1000001 101011 1000010 1000000 1000011 100000 1100100 1001 1100101 1010 1100110";
|
||||
correctOutput = "A+B@C d\te\nf";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed binary mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testOctalDecode() throws InvalidCharacterException, InvalidBaseException{
|
||||
BaseX cipher = new BaseX(8);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "141";
|
||||
String correctOutput = "a";
|
||||
String output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed octal lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "101";
|
||||
correctOutput = "A";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed octal uppercase decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "101 40 102 11 103 12";
|
||||
correctOutput = "A B\tC\n";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed octal whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "101 100 102 55 103 53";
|
||||
correctOutput = "A@B-C+";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed octal symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "101 53 102 100 103 40 144 11 145 12 146";
|
||||
correctOutput = "A+B@C d\te\nf";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed octal mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testDecimalDecode() throws InvalidCharacterException, InvalidBaseException{
|
||||
BaseX cipher = new BaseX(10);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "97";
|
||||
String correctOutput = "a";
|
||||
String output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed decimal lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "65";
|
||||
correctOutput = "A";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed decimal uppercase decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "65 32 66 9 67 10";
|
||||
correctOutput = "A B\tC\n";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed decimal whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "65 64 66 45 67 43";
|
||||
correctOutput = "A@B-C+";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed decimal symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "65 43 66 64 67 32 100 9 101 10 102";
|
||||
correctOutput = "A+B@C d\te\nf";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed decimal mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testHexDecode() throws InvalidCharacterException, InvalidBaseException{
|
||||
BaseX cipher = new BaseX(16);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "61";
|
||||
String correctOutput = "a";
|
||||
String output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed hex lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "41";
|
||||
correctOutput = "A";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed hex uppercase decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "41 20 42 9 43 A";
|
||||
correctOutput = "A B\tC\n";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed hex whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "41 40 42 2D 43 2B";
|
||||
correctOutput = "A@B-C+";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed hex symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "41 2B 42 40 43 20 64 9 65 A 66";
|
||||
correctOutput = "A+B@C d\te\nf";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed hex mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testBinaryEncode() throws InvalidBaseException{
|
||||
public void testBinaryEncode() throws InvalidBaseException, InvalidInputException{
|
||||
BaseX cipher = new BaseX();
|
||||
|
||||
//Test lowercase encoding
|
||||
@@ -180,7 +49,7 @@ public class TestBaseX{
|
||||
assertEquals("Binary failed binary mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testOctalEncode() throws InvalidBaseException{
|
||||
public void testOctalEncode() throws InvalidBaseException, InvalidInputException{
|
||||
BaseX cipher = new BaseX(8);
|
||||
|
||||
//Test lowercase encoding
|
||||
@@ -213,7 +82,7 @@ public class TestBaseX{
|
||||
assertEquals("Binary failed octal mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testDecimalEncode() throws InvalidBaseException{
|
||||
public void testDecimalEncode() throws InvalidBaseException, InvalidInputException{
|
||||
BaseX cipher = new BaseX(10);
|
||||
|
||||
//Test lowercase encoding
|
||||
@@ -246,7 +115,7 @@ public class TestBaseX{
|
||||
assertEquals("Binary failed decimal mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testHexEncode() throws InvalidBaseException{
|
||||
public void testHexEncode() throws InvalidBaseException, InvalidInputException{
|
||||
BaseX cipher = new BaseX(16);
|
||||
|
||||
//Test lowercase encoding
|
||||
@@ -278,4 +147,138 @@ public class TestBaseX{
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed hex mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBinaryDecode() throws InvalidCharacterException, InvalidBaseException, InvalidInputException{
|
||||
BaseX cipher = new BaseX();
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "1100001";
|
||||
String correctOutput = "a";
|
||||
String output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed binary lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "1000001";
|
||||
correctOutput = "A";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed binary uppercase decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "1000001 100000 1000010 1001 1000011 1010";
|
||||
correctOutput = "A B\tC\n";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed binary whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "1000001 1000000 1000010 101101 1000011 101011";
|
||||
correctOutput = "A@B-C+";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed binary symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "1000001 101011 1000010 1000000 1000011 100000 1100100 1001 1100101 1010 1100110";
|
||||
correctOutput = "A+B@C d\te\nf";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed binary mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testOctalDecode() throws InvalidCharacterException, InvalidBaseException, InvalidInputException{
|
||||
BaseX cipher = new BaseX(8);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "141";
|
||||
String correctOutput = "a";
|
||||
String output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed octal lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "101";
|
||||
correctOutput = "A";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed octal uppercase decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "101 40 102 11 103 12";
|
||||
correctOutput = "A B\tC\n";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed octal whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "101 100 102 55 103 53";
|
||||
correctOutput = "A@B-C+";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed octal symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "101 53 102 100 103 40 144 11 145 12 146";
|
||||
correctOutput = "A+B@C d\te\nf";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed octal mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testDecimalDecode() throws InvalidCharacterException, InvalidBaseException, InvalidInputException{
|
||||
BaseX cipher = new BaseX(10);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "97";
|
||||
String correctOutput = "a";
|
||||
String output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed decimal lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "65";
|
||||
correctOutput = "A";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed decimal uppercase decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "65 32 66 9 67 10";
|
||||
correctOutput = "A B\tC\n";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed decimal whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "65 64 66 45 67 43";
|
||||
correctOutput = "A@B-C+";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed decimal symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "65 43 66 64 67 32 100 9 101 10 102";
|
||||
correctOutput = "A+B@C d\te\nf";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed decimal mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testHexDecode() throws InvalidCharacterException, InvalidBaseException, InvalidInputException{
|
||||
BaseX cipher = new BaseX(16);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "61";
|
||||
String correctOutput = "a";
|
||||
String output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed hex lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "41";
|
||||
correctOutput = "A";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed hex uppercase decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "41 20 42 9 43 A";
|
||||
correctOutput = "A B\tC\n";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed hex whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "41 40 42 2D 43 2B";
|
||||
correctOutput = "A@B-C+";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed hex symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "41 2B 42 40 43 20 64 9 65 A 66";
|
||||
correctOutput = "A+B@C d\te\nf";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed hex mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,319 +7,14 @@ package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
|
||||
|
||||
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(){
|
||||
public void testEncode() throws InvalidInputException{
|
||||
Caesar cipher = new Caesar(true, true, true);
|
||||
|
||||
//Test lowercase encode
|
||||
@@ -380,68 +75,7 @@ public class TestCaesar{
|
||||
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(){
|
||||
public void testNoCapitalEncode() throws InvalidInputException{
|
||||
Caesar cipher = new Caesar(false, true, true);
|
||||
|
||||
//Test lowercase encode
|
||||
@@ -502,7 +136,68 @@ public class TestCaesar{
|
||||
assertEquals("Caesar failed no capital mixed case, whitespace, and symbol encoding with negative shift.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolEncode(){
|
||||
public void testNoWhitespaceEncode() throws InvalidInputException{
|
||||
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 testNoSymbolEncode() throws InvalidInputException{
|
||||
Caesar cipher = new Caesar(true, true, false);
|
||||
|
||||
//Test lowercase encode
|
||||
@@ -563,7 +258,7 @@ public class TestCaesar{
|
||||
assertEquals("Caesar failed mixed case, whitespace, and symbol encoding with negative shift.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolEncode(){
|
||||
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidInputException{
|
||||
Caesar cipher = new Caesar(false, false, false);
|
||||
|
||||
//Test lowercase encode
|
||||
@@ -623,4 +318,311 @@ public class TestCaesar{
|
||||
output = cipher.encode(shift, input);
|
||||
assertEquals("Caesar failed secure mixed case, whitespace, and symbol encoding with negative shift.", correctOutput, output);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDecode() throws InvalidInputException{
|
||||
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 testNoCapitalDecode() throws InvalidInputException{
|
||||
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 testNoWhitespaceDecode() throws InvalidInputException{
|
||||
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 testNoSymbolDecode() throws InvalidInputException{
|
||||
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() throws InvalidInputException{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidKeywordException;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -14,244 +15,7 @@ import org.junit.Test;
|
||||
|
||||
public class TestVigenere{
|
||||
@Test
|
||||
public void testDecode() throws InvalidKeywordException{
|
||||
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 InvalidKeywordException{
|
||||
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 InvalidKeywordException{
|
||||
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 InvalidKeywordException{
|
||||
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 InvalidKeywordException{
|
||||
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 InvalidKeywordException{
|
||||
public void testEncode() throws InvalidKeywordException, InvalidInputException{
|
||||
Vigenere cipher = new Vigenere(true, true, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
@@ -298,54 +62,7 @@ public class TestVigenere{
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceEncode() throws InvalidKeywordException{
|
||||
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 InvalidKeywordException{
|
||||
public void testNoCapitalEncode() throws InvalidKeywordException, InvalidInputException{
|
||||
Vigenere cipher = new Vigenere(false, true, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
@@ -392,7 +109,54 @@ public class TestVigenere{
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolEncode() throws InvalidKeywordException{
|
||||
public void testNoWhitespaceEncode() throws InvalidKeywordException, InvalidInputException{
|
||||
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 testNoSymbolEncode() throws InvalidKeywordException, InvalidInputException{
|
||||
Vigenere cipher = new Vigenere(true, true, false);
|
||||
|
||||
//Test lowercase encoding
|
||||
@@ -439,7 +203,7 @@ public class TestVigenere{
|
||||
assertEquals("Vigenere failed mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidKeywordException{
|
||||
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidKeywordException, InvalidInputException{
|
||||
Vigenere cipher = new Vigenere(false, false, false);
|
||||
|
||||
//Test lowercase encoding
|
||||
@@ -487,6 +251,243 @@ public class TestVigenere{
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDecode() throws InvalidKeywordException, InvalidInputException{
|
||||
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 testNoCapitalDecode() throws InvalidKeywordException, InvalidInputException{
|
||||
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 testNoWhitespaceDecode() throws InvalidKeywordException, InvalidInputException{
|
||||
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 testNoSymbolDecode() throws InvalidKeywordException, InvalidInputException{
|
||||
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 InvalidKeywordException, InvalidInputException{
|
||||
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 testKeyword() throws InvalidKeywordException{
|
||||
Vigenere cipher = new Vigenere();
|
||||
|
||||
@@ -11,28 +11,6 @@ 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();
|
||||
@@ -55,4 +33,26 @@ public class TestMorse{
|
||||
output = cipher.encode(input);
|
||||
assertEquals("Morse Encoding failed the third test", correctOutput, output);
|
||||
}
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,256 @@ import org.junit.Test;
|
||||
|
||||
|
||||
public class TestPlayfair{
|
||||
@Test
|
||||
public void testEncode() throws InvalidCharacterException, InvalidInputException{
|
||||
Playfair cipher = new Playfair(true, true, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "hidethegoldinthetreestump";
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "bmodzbxdnabekudmuixMmouvif";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "HIDETHEGOLDINTHETREESTUMP";
|
||||
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 tree 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@tree+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, InvalidInputException{
|
||||
Playfair cipher = new Playfair(true, false, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "hidethegoldinthetreestump";
|
||||
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 = "HIDETHEGOLDINTHETREESTUMP";
|
||||
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 = "hidethegoldinthetreestum";
|
||||
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 tree 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@tree+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, InvalidInputException{
|
||||
Playfair cipher = new Playfair(false, true, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "hidethegoldinthetreestump";
|
||||
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 = "HIDETHEGOLDINTHETREESTUMP";
|
||||
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 = "hidethegoldinthetreestum";
|
||||
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 tree 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@tree+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, InvalidInputException{
|
||||
Playfair cipher = new Playfair(true, true, false);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "hidethegoldinthetreestump";
|
||||
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 = "HIDETHEGOLDINTHETREESTUMP";
|
||||
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 = "hidethegoldinthetreestum";
|
||||
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 tree 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@tree+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, InvalidInputException{
|
||||
Playfair cipher = new Playfair(false, false, false);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "hidethegoldinthetreestump";
|
||||
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 = "HIDETHEGOLDINTHETREESTUMP";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure uppercase encoding.", correctOutput, output);
|
||||
//Test odd letter count encoding
|
||||
inputString = "hidethegoldinthetreestum";
|
||||
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 tree 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@tree+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);
|
||||
}
|
||||
@Test
|
||||
public void testDecode() throws InvalidCharacterException, InvalidInputException{
|
||||
Playfair cipher = new Playfair(true, true, true);
|
||||
@@ -264,254 +514,4 @@ public class TestPlayfair{
|
||||
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, InvalidInputException{
|
||||
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, InvalidInputException{
|
||||
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, InvalidInputException{
|
||||
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, InvalidInputException{
|
||||
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, InvalidInputException{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,158 +14,6 @@ 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, InvalidInputException{
|
||||
PolybiusSquare cipher = new PolybiusSquare(true, true);
|
||||
@@ -318,4 +166,156 @@ public class TestPolybiusSquare{
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("PolybiusSquare failed secure whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testDecode() throws InvalidCharacterException, InvalidInputException{
|
||||
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, InvalidInputException{
|
||||
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, InvalidInputException{
|
||||
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, InvalidInputException{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user