Finished Trifid cipher
This commit is contained in:
@@ -201,7 +201,7 @@ public class Trifid{
|
|||||||
locations.add(location);
|
locations.add(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Take the rows and split the numbers up by group
|
//Split the locations up by group
|
||||||
int numGroups = inputString.length() / groupSize;
|
int numGroups = inputString.length() / groupSize;
|
||||||
if(numGroups == 0){
|
if(numGroups == 0){
|
||||||
numGroups = 1;
|
numGroups = 1;
|
||||||
@@ -212,15 +212,17 @@ public class Trifid{
|
|||||||
}
|
}
|
||||||
int groupCnt = -1;
|
int groupCnt = -1;
|
||||||
for(int locCnt = 0;locCnt < locations.size();++locCnt){
|
for(int locCnt = 0;locCnt < locations.size();++locCnt){
|
||||||
|
//If you've reached the end of the group move to the next one
|
||||||
if((locCnt % groupSize) == 0){
|
if((locCnt % groupSize) == 0){
|
||||||
++groupCnt;
|
++groupCnt;
|
||||||
}
|
}
|
||||||
groups.get(groupCnt).add(locations.get(locCnt));
|
groups.get(groupCnt).add(locations.get(locCnt));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Creation locations from the groups
|
//Split the coordinates into rows
|
||||||
ArrayList<Integer> coordinates = new ArrayList<Integer>(locations.size() * 3);
|
ArrayList<Integer> coordinates = new ArrayList<Integer>(locations.size() * 3);
|
||||||
for(ArrayList<CharLocation> group : groups){
|
for(ArrayList<CharLocation> group : groups){
|
||||||
|
//Split the coordinates up into 3 rows
|
||||||
ArrayList<Integer> layers = new ArrayList<Integer>(group.size());
|
ArrayList<Integer> layers = new ArrayList<Integer>(group.size());
|
||||||
ArrayList<Integer> rows = new ArrayList<Integer>(group.size());
|
ArrayList<Integer> rows = new ArrayList<Integer>(group.size());
|
||||||
ArrayList<Integer> cols = new ArrayList<Integer>(group.size());
|
ArrayList<Integer> cols = new ArrayList<Integer>(group.size());
|
||||||
@@ -233,6 +235,7 @@ public class Trifid{
|
|||||||
coordinates.addAll(rows);
|
coordinates.addAll(rows);
|
||||||
coordinates.addAll(cols);
|
coordinates.addAll(cols);
|
||||||
}
|
}
|
||||||
|
//Create new locations from the rows of coordinates
|
||||||
ArrayList<CharLocation> newLocations = new ArrayList<CharLocation>(locations.size());
|
ArrayList<CharLocation> newLocations = new ArrayList<CharLocation>(locations.size());
|
||||||
for(int cnt = 0;cnt < coordinates.size();){
|
for(int cnt = 0;cnt < coordinates.size();){
|
||||||
int z = coordinates.get(cnt++);
|
int z = coordinates.get(cnt++);
|
||||||
@@ -252,7 +255,69 @@ public class Trifid{
|
|||||||
}
|
}
|
||||||
//Decodes inputString using a polybius square and stores the result in outputString
|
//Decodes inputString using a polybius square and stores the result in outputString
|
||||||
private void decode() throws InvalidCharacterException{
|
private void decode() throws InvalidCharacterException{
|
||||||
//TODO:
|
//Step through every element in the sanitized inputString encoding the letters
|
||||||
|
ArrayList<CharLocation> locations = new ArrayList<CharLocation>();
|
||||||
|
for(char ch : getCleanInputString().toCharArray()){
|
||||||
|
//Get the location of the char in the grid
|
||||||
|
CharLocation location = findChar(ch);
|
||||||
|
locations.add(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Split the locations up by group
|
||||||
|
int numGroups = inputString.length() / groupSize;
|
||||||
|
if(numGroups == 0){
|
||||||
|
numGroups = 1;
|
||||||
|
}
|
||||||
|
ArrayList<ArrayList<CharLocation>> groups = new ArrayList<ArrayList<CharLocation>>(numGroups);
|
||||||
|
for(int cnt = 0;cnt < numGroups;++cnt){
|
||||||
|
groups.add(new ArrayList<CharLocation>());
|
||||||
|
}
|
||||||
|
int groupCnt = -1;
|
||||||
|
for(int locCnt = 0;locCnt < locations.size();++locCnt){
|
||||||
|
//If you've reached the end of the group move to the next one
|
||||||
|
if((locCnt % groupSize) == 0){
|
||||||
|
++groupCnt;
|
||||||
|
}
|
||||||
|
groups.get(groupCnt).add(locations.get(locCnt));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Split the coordinates into rows by group and create the original grid locations
|
||||||
|
ArrayList<CharLocation> originalLocations = new ArrayList<CharLocation>(locations.size());
|
||||||
|
for(ArrayList<CharLocation> group : groups){
|
||||||
|
//Read all of the coordinates from the group out into a row
|
||||||
|
ArrayList<Integer> coordinates = new ArrayList<Integer>(group.size() * 3);
|
||||||
|
for(CharLocation loc : group){
|
||||||
|
coordinates.add(loc.getZ());
|
||||||
|
coordinates.add(loc.getX());
|
||||||
|
coordinates.add(loc.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
//Read out the coordinates into new locations
|
||||||
|
ArrayList<CharLocation> originalGroup = new ArrayList<CharLocation>(group.size());
|
||||||
|
for(int cnt = 0;cnt < group.size();++cnt){
|
||||||
|
originalGroup.add(new CharLocation(0, 0, 0));
|
||||||
|
}
|
||||||
|
int coordinateCnt = 0;
|
||||||
|
for(CharLocation loc : originalGroup){
|
||||||
|
loc.z = coordinates.get(coordinateCnt++);
|
||||||
|
}
|
||||||
|
for(CharLocation loc : originalGroup){
|
||||||
|
loc.x = coordinates.get(coordinateCnt++);
|
||||||
|
}
|
||||||
|
for(CharLocation loc : originalGroup){
|
||||||
|
loc.y = coordinates.get(coordinateCnt++);
|
||||||
|
}
|
||||||
|
originalLocations.addAll(originalGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get the original letters from the grid
|
||||||
|
StringBuilder output = new StringBuilder();
|
||||||
|
for(CharLocation loc : originalLocations){
|
||||||
|
output.append(getChar(loc));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Format the output
|
||||||
|
formatOutput(output.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class TestTrifid{
|
|||||||
output = cipher.encode(keyword, inputString);
|
output = cipher.encode(keyword, inputString);
|
||||||
assertEquals("Trifid failed uppercase encoding.", correctOutput, output);
|
assertEquals("Trifid failed uppercase encoding.", correctOutput, output);
|
||||||
|
|
||||||
//Test groupLength
|
//Test groupLength encoding
|
||||||
inputString = "messagetoencode";
|
inputString = "messagetoencode";
|
||||||
keyword = "keyword";
|
keyword = "keyword";
|
||||||
int groupLength = 3;
|
int groupLength = 3;
|
||||||
@@ -70,21 +70,490 @@ public class TestTrifid{
|
|||||||
assertEquals("Trifid failed mixed case, whitespace, symbol, groupLength encoding.", correctOutput, output);
|
assertEquals("Trifid failed mixed case, whitespace, symbol, groupLength encoding.", correctOutput, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testNoCapitalEncode() throws InvalidCharacterException, InvalidBaseException, InvalidKeywordException, InvalidInputException{
|
public void testNoCapitalEncode() throws InvalidCharacterException, InvalidBaseException, InvalidKeywordException, InvalidInputException{
|
||||||
//TODO:
|
Trifid cipher = new Trifid(false, true, true, '+');
|
||||||
|
|
||||||
|
//Test lowercase encoding
|
||||||
|
String inputString = "messagetoencode";
|
||||||
|
String keyword = "keyword";
|
||||||
|
String correctOutput = "GQDOKPDODLJVFLF";
|
||||||
|
String output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no capital lowercase encoding.", correctOutput, output);
|
||||||
|
//Test uppercase encoding
|
||||||
|
inputString = "MESSAGETOENCODE";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "GQDOKPDODLJVFLF";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no capital uppercase encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test groupLength encoding
|
||||||
|
inputString = "messagetoencode";
|
||||||
|
keyword = "keyword";
|
||||||
|
int groupLength = 3;
|
||||||
|
correctOutput = "GPJQDVDOFODLKLF";
|
||||||
|
output = cipher.encode(keyword, groupLength, inputString);
|
||||||
|
assertEquals("Trifid failed no capital groupLength encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test whitespace encoding
|
||||||
|
inputString = "message to encode";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "GQDOKPD OD LJVFLF";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no capital whitespace encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test symbol encoding
|
||||||
|
inputString = "message*to-encode";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "GQDOKPD*OD-LJVFLF";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no capital symbol encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol encoding
|
||||||
|
inputString = "Message to^encode";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "GQDOKPD OD^LJVFLF";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no capital mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||||
|
//Throw in groupLength for good measure
|
||||||
|
inputString = "Message to^encode";
|
||||||
|
keyword = "keyword";
|
||||||
|
groupLength = 3;
|
||||||
|
correctOutput = "GPJQDVD OF^ODLKLF";
|
||||||
|
output = cipher.encode(keyword, groupLength, inputString);
|
||||||
|
assertEquals("Trifid failed no capital mixed case, whitespace, symbol, groupLength encoding.", correctOutput, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testNoWhitespaceEncode() throws InvalidCharacterException, InvalidBaseException, InvalidKeywordException, InvalidInputException{
|
public void testNoWhitespaceEncode() throws InvalidCharacterException, InvalidBaseException, InvalidKeywordException, InvalidInputException{
|
||||||
//TODO:
|
Trifid cipher = new Trifid(true, false, true, '+');
|
||||||
|
|
||||||
|
//Test lowercase encoding
|
||||||
|
String inputString = "messagetoencode";
|
||||||
|
String keyword = "keyword";
|
||||||
|
String correctOutput = "gqdokpdodljvflf";
|
||||||
|
String output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no whitespace lowercase encoding.", correctOutput, output);
|
||||||
|
//Test uppercase encoding
|
||||||
|
inputString = "MESSAGETOENCODE";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "GQDOKPDODLJVFLF";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no whitespace uppercase encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test groupLength encoding
|
||||||
|
inputString = "messagetoencode";
|
||||||
|
keyword = "keyword";
|
||||||
|
int groupLength = 3;
|
||||||
|
correctOutput = "gpjqdvdofodlklf";
|
||||||
|
output = cipher.encode(keyword, groupLength, inputString);
|
||||||
|
assertEquals("Trifid failed no whitespace groupLength encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test whitespace encoding
|
||||||
|
inputString = "message to encode";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "gqdokpdodljvflf";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no whitespace whitespace encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test symbol encoding
|
||||||
|
inputString = "message*to-encode";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "gqdokpd*od-ljvflf";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no whitespace symbol encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol encoding
|
||||||
|
inputString = "Message to^encode";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "Gqdokpdod^ljvflf";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no whitespace mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||||
|
//Throw in groupLength for good measure
|
||||||
|
inputString = "Message to^encode";
|
||||||
|
keyword = "keyword";
|
||||||
|
groupLength = 3;
|
||||||
|
correctOutput = "Gpjqdvdof^odlklf";
|
||||||
|
output = cipher.encode(keyword, groupLength, inputString);
|
||||||
|
assertEquals("Trifid failed no whitespace mixed case, whitespace, symbol, groupLength encoding.", correctOutput, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testNoSymbolEncode() throws InvalidCharacterException, InvalidBaseException, InvalidKeywordException, InvalidInputException{
|
public void testNoSymbolEncode() throws InvalidCharacterException, InvalidBaseException, InvalidKeywordException, InvalidInputException{
|
||||||
//TODO:
|
Trifid cipher = new Trifid(true, true, false, '+');
|
||||||
|
|
||||||
|
//Test lowercase encoding
|
||||||
|
String inputString = "messagetoencode";
|
||||||
|
String keyword = "keyword";
|
||||||
|
String correctOutput = "gqdokpdodljvflf";
|
||||||
|
String output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no symbol lowercase encoding.", correctOutput, output);
|
||||||
|
//Test uppercase encoding
|
||||||
|
inputString = "MESSAGETOENCODE";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "GQDOKPDODLJVFLF";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no symbol uppercase encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test groupLength encoding
|
||||||
|
inputString = "messagetoencode";
|
||||||
|
keyword = "keyword";
|
||||||
|
int groupLength = 3;
|
||||||
|
correctOutput = "gpjqdvdofodlklf";
|
||||||
|
output = cipher.encode(keyword, groupLength, inputString);
|
||||||
|
assertEquals("Trifid failed no symbol groupLength encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test whitespace encoding
|
||||||
|
inputString = "message to encode";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "gqdokpd od ljvflf";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no symbol whitespace encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test symbol encoding
|
||||||
|
inputString = "message*to-encode";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "gqdokpdodljvflf";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no symbol symbol encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol encoding
|
||||||
|
inputString = "Message to^encode";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "Gqdokpd odljvflf";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no symbol mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||||
|
//Throw in groupLength for good measure
|
||||||
|
inputString = "Message to^encode";
|
||||||
|
keyword = "keyword";
|
||||||
|
groupLength = 3;
|
||||||
|
correctOutput = "Gpjqdvd ofodlklf";
|
||||||
|
output = cipher.encode(keyword, groupLength, inputString);
|
||||||
|
assertEquals("Trifid failed no symbol mixed case, whitespace, symbol, groupLength encoding.", correctOutput, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNoCapitalWhitespaceSymbolEncode() throws InvalidCharacterException, InvalidBaseException, InvalidKeywordException, InvalidInputException{
|
||||||
|
Trifid cipher = new Trifid(false, false, false, '+');
|
||||||
|
|
||||||
|
//Test lowercase encoding
|
||||||
|
String inputString = "messagetoencode";
|
||||||
|
String keyword = "keyword";
|
||||||
|
String correctOutput = "GQDOKPDODLJVFLF";
|
||||||
|
String output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed secure lowercase encoding.", correctOutput, output);
|
||||||
|
//Test uppercase encoding
|
||||||
|
inputString = "MESSAGETOENCODE";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "GQDOKPDODLJVFLF";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed secure uppercase encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test groupLength encoding
|
||||||
|
inputString = "messagetoencode";
|
||||||
|
keyword = "keyword";
|
||||||
|
int groupLength = 3;
|
||||||
|
correctOutput = "GPJQDVDOFODLKLF";
|
||||||
|
output = cipher.encode(keyword, groupLength, inputString);
|
||||||
|
assertEquals("Trifid failed secure groupLength encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test whitespace encoding
|
||||||
|
inputString = "message to encode";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "GQDOKPDODLJVFLF";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed secure whitespace encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test symbol encoding
|
||||||
|
inputString = "message*to-encode";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "GQDOKPDODLJVFLF";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed secure symbol encoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol encoding
|
||||||
|
inputString = "Message to^encode";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "GQDOKPDODLJVFLF";
|
||||||
|
output = cipher.encode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed secure mixed case, whitespace, symbol encoding.", correctOutput, output);
|
||||||
|
//Throw in groupLength for good measure
|
||||||
|
inputString = "Message to^encode";
|
||||||
|
keyword = "keyword";
|
||||||
|
groupLength = 3;
|
||||||
|
correctOutput = "GPJQDVDOFODLKLF";
|
||||||
|
output = cipher.encode(keyword, groupLength, inputString);
|
||||||
|
assertEquals("Trifid failed secure mixed case, whitespace, symbol, groupLength encoding.", correctOutput, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDecode() throws InvalidCharacterException, InvalidBaseException, InvalidKeywordException, InvalidInputException{
|
public void testDecode() throws InvalidCharacterException, InvalidBaseException, InvalidKeywordException, InvalidInputException{
|
||||||
//TODO:
|
Trifid cipher = new Trifid(true, true, true, '+');
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String inputString = "gqdokpdodljvflf";
|
||||||
|
String keyword = "keyword";
|
||||||
|
String correctOutput = "messagetoencode";
|
||||||
|
String output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
inputString = "GQDOKPDODLJVFLF";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "MESSAGETOENCODE";
|
||||||
|
output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test groupLength decoding
|
||||||
|
inputString = "gpjqdvdofodlklf";
|
||||||
|
keyword = "keyword";
|
||||||
|
int groupLength = 3;
|
||||||
|
correctOutput = "messagetoencode";
|
||||||
|
output = cipher.decode(keyword, groupLength, inputString);
|
||||||
|
assertEquals("Trifid failed groupLength decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test whitespace decoding
|
||||||
|
inputString = "gqdokpd od ljvflf";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "message to encode";
|
||||||
|
output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
inputString = "gqdokpd*od-ljvflf";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "message*to-encode";
|
||||||
|
output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol decoding
|
||||||
|
inputString = "Gqdokpd od^ljvflf";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "Message to^encode";
|
||||||
|
output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||||
|
//Throw in groupLength for good measure
|
||||||
|
inputString = "Gpjqdvd of^odlklf";
|
||||||
|
keyword = "keyword";
|
||||||
|
groupLength = 3;
|
||||||
|
correctOutput = "Message to^encode";
|
||||||
|
output = cipher.decode(keyword, groupLength, inputString);
|
||||||
|
assertEquals("Trifid failed mixed case, whitespace, symbol, groupLength decoding.", correctOutput, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNoCapitalDecode() throws InvalidCharacterException, InvalidBaseException, InvalidKeywordException, InvalidInputException{
|
||||||
|
Trifid cipher = new Trifid(false, true, true, '+');
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String inputString = "gqdokpdodljvflf";
|
||||||
|
String keyword = "keyword";
|
||||||
|
String correctOutput = "MESSAGETOENCODE";
|
||||||
|
String output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no capital lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
inputString = "GQDOKPDODLJVFLF";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "MESSAGETOENCODE";
|
||||||
|
output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no capital uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test groupLength decoding
|
||||||
|
inputString = "gpjqdvdofodlklf";
|
||||||
|
keyword = "keyword";
|
||||||
|
int groupLength = 3;
|
||||||
|
correctOutput = "MESSAGETOENCODE";
|
||||||
|
output = cipher.decode(keyword, groupLength, inputString);
|
||||||
|
assertEquals("Trifid failed no capital groupLength decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test whitespace decoding
|
||||||
|
inputString = "gqdokpd od ljvflf";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "MESSAGE TO ENCODE";
|
||||||
|
output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no capital whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
inputString = "gqdokpd*od-ljvflf";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "MESSAGE*TO-ENCODE";
|
||||||
|
output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no capital symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol decoding
|
||||||
|
inputString = "Gqdokpd od^ljvflf";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "MESSAGE TO^ENCODE";
|
||||||
|
output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no capital mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||||
|
//Throw in groupLength for good measure
|
||||||
|
inputString = "Gpjqdvd of^odlklf";
|
||||||
|
keyword = "keyword";
|
||||||
|
groupLength = 3;
|
||||||
|
correctOutput = "MESSAGE TO^ENCODE";
|
||||||
|
output = cipher.decode(keyword, groupLength, inputString);
|
||||||
|
assertEquals("Trifid failed no capital mixed case, whitespace, symbol, groupLength decoding.", correctOutput, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNoWhitespaceDecode() throws InvalidCharacterException, InvalidBaseException, InvalidKeywordException, InvalidInputException{
|
||||||
|
Trifid cipher = new Trifid(true, false, true, '+');
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String inputString = "gqdokpdodljvflf";
|
||||||
|
String keyword = "keyword";
|
||||||
|
String correctOutput = "messagetoencode";
|
||||||
|
String output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no whitespace lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
inputString = "GQDOKPDODLJVFLF";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "MESSAGETOENCODE";
|
||||||
|
output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no whitespace uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test groupLength decoding
|
||||||
|
inputString = "gpjqdvdofodlklf";
|
||||||
|
keyword = "keyword";
|
||||||
|
int groupLength = 3;
|
||||||
|
correctOutput = "messagetoencode";
|
||||||
|
output = cipher.decode(keyword, groupLength, inputString);
|
||||||
|
assertEquals("Trifid failed no whitespace groupLength decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test whitespace decoding
|
||||||
|
inputString = "gqdokpd od ljvflf";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "messagetoencode";
|
||||||
|
output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no whitespace whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
inputString = "gqdokpd*od-ljvflf";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "message*to-encode";
|
||||||
|
output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no whitespace symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol decoding
|
||||||
|
inputString = "Gqdokpd od^ljvflf";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "Messageto^encode";
|
||||||
|
output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no whitespace mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||||
|
//Throw in groupLength for good measure
|
||||||
|
inputString = "Gpjqdvd of^odlklf";
|
||||||
|
keyword = "keyword";
|
||||||
|
groupLength = 3;
|
||||||
|
correctOutput = "Messageto^encode";
|
||||||
|
output = cipher.decode(keyword, groupLength, inputString);
|
||||||
|
assertEquals("Trifid failed no whitespace mixed case, whitespace, symbol, groupLength decoding.", correctOutput, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNoSymbolDeocde() throws InvalidCharacterException, InvalidBaseException, InvalidKeywordException, InvalidInputException{
|
||||||
|
Trifid cipher = new Trifid(true, true, false, '+');
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String inputString = "gqdokpdodljvflf";
|
||||||
|
String keyword = "keyword";
|
||||||
|
String correctOutput = "messagetoencode";
|
||||||
|
String output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no symbol lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
inputString = "GQDOKPDODLJVFLF";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "MESSAGETOENCODE";
|
||||||
|
output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no symbol uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test groupLength decoding
|
||||||
|
inputString = "gpjqdvdofodlklf";
|
||||||
|
keyword = "keyword";
|
||||||
|
int groupLength = 3;
|
||||||
|
correctOutput = "messagetoencode";
|
||||||
|
output = cipher.decode(keyword, groupLength, inputString);
|
||||||
|
assertEquals("Trifid failed no symbol groupLength decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test whitespace decoding
|
||||||
|
inputString = "gqdokpd od ljvflf";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "message to encode";
|
||||||
|
output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no symbol whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
inputString = "gqdokpd*od-ljvflf";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "messagetoencode";
|
||||||
|
output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no symbol symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol decoding
|
||||||
|
inputString = "Gqdokpd od^ljvflf";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "Message toencode";
|
||||||
|
output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed no symbol mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||||
|
//Throw in groupLength for good measure
|
||||||
|
inputString = "Gpjqdvd of^odlklf";
|
||||||
|
keyword = "keyword";
|
||||||
|
groupLength = 3;
|
||||||
|
correctOutput = "Message toencode";
|
||||||
|
output = cipher.decode(keyword, groupLength, inputString);
|
||||||
|
assertEquals("Trifid failed no symbol mixed case, whitespace, symbol, groupLength decoding.", correctOutput, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNoCapitalWhitespaceSymbolDecode() throws InvalidCharacterException, InvalidBaseException, InvalidKeywordException, InvalidInputException{
|
||||||
|
Trifid cipher = new Trifid(false, false, false, '+');
|
||||||
|
|
||||||
|
//Test lowercase decoding
|
||||||
|
String inputString = "gqdokpdodljvflf";
|
||||||
|
String keyword = "keyword";
|
||||||
|
String correctOutput = "MESSAGETOENCODE";
|
||||||
|
String output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed secure lowercase decoding.", correctOutput, output);
|
||||||
|
//Test uppercase decoding
|
||||||
|
inputString = "GQDOKPDODLJVFLF";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "MESSAGETOENCODE";
|
||||||
|
output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed secure uppercase decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test groupLength decoding
|
||||||
|
inputString = "gpjqdvdofodlklf";
|
||||||
|
keyword = "keyword";
|
||||||
|
int groupLength = 3;
|
||||||
|
correctOutput = "MESSAGETOENCODE";
|
||||||
|
output = cipher.decode(keyword, groupLength, inputString);
|
||||||
|
assertEquals("Trifid failed secure groupLength decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test whitespace decoding
|
||||||
|
inputString = "gqdokpd od ljvflf";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "MESSAGETOENCODE";
|
||||||
|
output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed secure whitespace decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test symbol decoding
|
||||||
|
inputString = "gqdokpd*od-ljvflf";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "MESSAGETOENCODE";
|
||||||
|
output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed secure symbol decoding.", correctOutput, output);
|
||||||
|
|
||||||
|
//Test mixed case, whitespace, symbol decoding
|
||||||
|
inputString = "Gqdokpd od^ljvflf";
|
||||||
|
keyword = "keyword";
|
||||||
|
correctOutput = "MESSAGETOENCODE";
|
||||||
|
output = cipher.decode(keyword, inputString);
|
||||||
|
assertEquals("Trifid failed secure mixed case, whitespace, symbol decoding.", correctOutput, output);
|
||||||
|
//Throw in groupLength for good measure
|
||||||
|
inputString = "Gpjqdvd of^odlklf";
|
||||||
|
keyword = "keyword";
|
||||||
|
groupLength = 3;
|
||||||
|
correctOutput = "MESSAGETOENCODE";
|
||||||
|
output = cipher.decode(keyword, groupLength, inputString);
|
||||||
|
assertEquals("Trifid failed secure mixed case, whitespace, symbol, groupLength decoding.", correctOutput, output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user