Finished Trifid cipher
This commit is contained in:
@@ -201,7 +201,7 @@ public class Trifid{
|
||||
locations.add(location);
|
||||
}
|
||||
|
||||
//Take the rows and split the numbers up by group
|
||||
//Split the locations up by group
|
||||
int numGroups = inputString.length() / groupSize;
|
||||
if(numGroups == 0){
|
||||
numGroups = 1;
|
||||
@@ -212,15 +212,17 @@ public class Trifid{
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
||||
//Creation locations from the groups
|
||||
//Split the coordinates into rows
|
||||
ArrayList<Integer> coordinates = new ArrayList<Integer>(locations.size() * 3);
|
||||
for(ArrayList<CharLocation> group : groups){
|
||||
//Split the coordinates up into 3 rows
|
||||
ArrayList<Integer> layers = new ArrayList<Integer>(group.size());
|
||||
ArrayList<Integer> rows = 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(cols);
|
||||
}
|
||||
//Create new locations from the rows of coordinates
|
||||
ArrayList<CharLocation> newLocations = new ArrayList<CharLocation>(locations.size());
|
||||
for(int cnt = 0;cnt < coordinates.size();){
|
||||
int z = coordinates.get(cnt++);
|
||||
@@ -252,7 +255,69 @@ public class Trifid{
|
||||
}
|
||||
//Decodes inputString using a polybius square and stores the result in outputString
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user