Finished Playfair cipher
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/main/java/mattrixwv/CipherStreamJava/TestPlayfair.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-30-21
|
||||
//Modified: 07-30-21
|
||||
//Modified: 01-04-22
|
||||
//These are the tests for the Playfair class
|
||||
package mattrixwv.CipherStreamJava;
|
||||
|
||||
@@ -10,18 +10,508 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import mattrixwv.CipherStreamJava.Playfair.InvalidCharacterException;
|
||||
|
||||
|
||||
public class TestPlayfair{
|
||||
@Test
|
||||
public void testDecode(){
|
||||
Playfair cipher = new Playfair();
|
||||
public void testDecode() throws InvalidCharacterException, Exception{
|
||||
Playfair cipher = new Playfair(true, true, true);
|
||||
|
||||
//Test 1
|
||||
//Test lowercase decoding
|
||||
String inputString = "bmodzbxdnabekudmuixmmouvif";
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "hidethegoldinthetrexestump";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed uppercase decoding.", correctOutput, output);
|
||||
//Test odd letter count decoding
|
||||
inputString = "bmodzbxdnabekudmuixmmouvim";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hidethegoldinthetrexestumx";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed odd letter count decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "bmod zbx dnab ek udm uixmm ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hide the gold in the trexe stump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "bmodzbxdnabek-udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hidethegoldin-the@trexe+stump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whtiespace, symbol decoding
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "Hide the gold in - the@trexe+stump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whtiespace, symbol decoding with mangled keyword
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "Hide the gold in - the@trexe+stump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testEncode(){
|
||||
Playfair cipher = new Playfair();
|
||||
public void testNoWhitespaceDecode() throws InvalidCharacterException, Exception{
|
||||
Playfair cipher = new Playfair(true, false, true);
|
||||
|
||||
//Test 1
|
||||
//Test lowercase decoding
|
||||
String inputString = "bmodzbxdnabekudmuixmmouvif";
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "hidethegoldinthetrexestump";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace uppercase decoding.", correctOutput, output);
|
||||
//Test odd letter count decoding
|
||||
inputString = "bmodzbxdnabekudmuixmmouvim";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hidethegoldinthetrexestumx";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace odd letter count decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "bmodzbxdnabekudmuixmmouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hidethegoldinthetrexestump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "bmodzbxdnabek-udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hidethegoldin-the@trexe+stump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whtiespace, symbol decoding
|
||||
inputString = "Bmodzbxdnabek-udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "Hidethegoldin-the@trexe+stump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whtiespace, symbol decoding with mangled keyword
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "Hidethegoldin-the@trexe+stump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalDecode() throws InvalidCharacterException, Exception{
|
||||
Playfair cipher = new Playfair(false, true, true);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "bmodzbxdnabekudmuixmmouvif";
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital uppercase decoding.", correctOutput, output);
|
||||
//Test odd letter count decoding
|
||||
inputString = "bmodzbxdnabekudmuixmmouvim";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMX";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital odd letter count decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "bmod zbx dnab ek udm uixmm ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDE THE GOLD IN THE TREXE STUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "bmodzbxdnabek-udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDIN-THE@TREXE+STUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whtiespace, symbol decoding
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDE THE GOLD IN - THE@TREXE+STUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whtiespace, symbol decoding with mangled keyword
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "HIDE THE GOLD IN - THE@TREXE+STUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolDecode() throws InvalidCharacterException, Exception{
|
||||
Playfair cipher = new Playfair(true, true, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "bmodzbxdnabekudmuixmmouvif";
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "hidethegoldinthetrexestump";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol uppercase decoding.", correctOutput, output);
|
||||
//Test odd letter count decoding
|
||||
inputString = "bmodzbxdnabekudmuixmmouvim";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hidethegoldinthetrexestumx";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol odd letter count decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "bmod zbx dnab ek udm uixmm ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hide the gold in the trexe stump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "bmodzbxdnabek-udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "hidethegoldinthetrexestump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whtiespace, symbol decoding
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "Hide the gold in thetrexestump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whtiespace, symbol decoding with mangled keyword
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "Hide the gold in thetrexestump";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidCharacterException, Exception{
|
||||
Playfair cipher = new Playfair(false, false, false);
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "bmodzbxdnabekudmuixmmouvif";
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
String output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure uppercase decoding.", correctOutput, output);
|
||||
//Test odd letter count decoding
|
||||
inputString = "bmodzbxdnabekudmuixmmouvim";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMX";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure odd letter count decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "bmod zbx dnab ek udm uixmm ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "bmodzbxdnabek-udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whtiespace, symbol decoding
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||
//Test mixed case, whtiespace, symbol decoding with mangled keyword
|
||||
inputString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
output = cipher.decode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure mixed case, whitespace, symbol decoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testEncode() throws InvalidCharacterException, Exception{
|
||||
Playfair cipher = new Playfair(true, true, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "hidethegoldinthetrexestump";
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "bmodzbxdnabekudmuixmmouvif";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed uppercase encoding.", correctOutput, output);
|
||||
//Test odd letter count encoding
|
||||
inputString = "hidethegoldinthetrexestum";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmodzbxdnabekudmuixmmouviM";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed odd letter count encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "hide the gold in the trexe stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmod zbx dnab ek udm uixmm ouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed whitespace encoding.", correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "hidethegoldin-the@trexe+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmodzbxdnabek-udm@uixmm+ouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed symbol encoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "Bmod zbx dnab ek - udm@uixMm+ouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol encoding with mangled keyword
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "Bmod zbx dnab ek - udm@uixMm+ouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoWhitespaceEncode() throws InvalidCharacterException, Exception{
|
||||
Playfair cipher = new Playfair(true, false, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "hidethegoldinthetrexestump";
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "bmodzbxdnabekudmuixmmouvif";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace uppercase encoding.", correctOutput, output);
|
||||
//Test odd letter count encoding
|
||||
inputString = "hidethegoldinthetrexestum";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmodzbxdnabekudmuixmmouviM";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace odd letter count encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "hide the gold in the trexe stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmodzbxdnabekudmuixmmouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace whitespace encoding.", correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "hidethegoldin-the@trexe+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmodzbxdnabek-udm@uixmm+ouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace symbol encoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "Bmodzbxdnabek-udm@uixMm+ouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol encoding with mangled keyword
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "Bmodzbxdnabek-udm@uixMm+ouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no whitespace mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalEncode() throws InvalidCharacterException, Exception{
|
||||
Playfair cipher = new Playfair(false, true, true);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "hidethegoldinthetrexestump";
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital uppercase encoding.", correctOutput, output);
|
||||
//Test odd letter count encoding
|
||||
inputString = "hidethegoldinthetrexestum";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIM";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital odd letter count encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "hide the gold in the trexe stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMOD ZBX DNAB EK UDM UIXMM OUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital whitespace encoding.", correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "hidethegoldin-the@trexe+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEK-UDM@UIXMM+OUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital symbol encoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMOD ZBX DNAB EK - UDM@UIXMM+OUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol encoding with mangled keyword
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "BMOD ZBX DNAB EK - UDM@UIXMM+OUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no capital mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoSymbolEncode() throws InvalidCharacterException, Exception{
|
||||
Playfair cipher = new Playfair(true, true, false);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "hidethegoldinthetrexestump";
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "bmodzbxdnabekudmuixmmouvif";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol uppercase encoding.", correctOutput, output);
|
||||
//Test odd letter count encoding
|
||||
inputString = "hidethegoldinthetrexestum";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmodzbxdnabekudmuixmmouviM";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol odd letter count encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "hide the gold in the trexe stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmod zbx dnab ek udm uixmm ouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol whitespace encoding.", correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "hidethegoldin-the@trexe+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "bmodzbxdnabekudmuixmmouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol symbol encoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "Bmod zbx dnab ek udmuixMmouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol encoding with mangled keyword
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "Bmod zbx dnab ek udmuixMmouvif";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed no symbol mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidCharacterException, Exception{
|
||||
Playfair cipher = new Playfair(false, false, false);
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "hidethegoldinthetrexestump";
|
||||
String keyword = "Playfair Example";
|
||||
String correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
String output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "HIDETHEGOLDINTHETREXESTUMP";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure uppercase encoding.", correctOutput, output);
|
||||
//Test odd letter count encoding
|
||||
inputString = "hidethegoldinthetrexestum";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIM";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure odd letter count encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "hide the gold in the trexe stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure whitespace encoding.", correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "hidethegoldin-the@trexe+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure symbol encoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, symbol encoding
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Playfair Example";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||
//Test mixed case, whitespace, symbol encoding with mangled keyword
|
||||
inputString = "Hide the gold in - the@tree+stump";
|
||||
keyword = "Play-fair@Exam ple";
|
||||
correctOutput = "BMODZBXDNABEKUDMUIXMMOUVIF";
|
||||
output = cipher.encode(keyword, inputString);
|
||||
assertEquals("Playfair failed secure mixed case, whitespace, symbol encoding with mangled keyword.", correctOutput, output);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user