Updated more tests
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//MattrixwvWebsite/src/main/java/com/mattrixwv/CipherStreamJava/polySubstitution/Columnar.java
|
||||
//Mattrixwv
|
||||
// Created: 01-16-22
|
||||
//Modified: 07-09-22
|
||||
//Modified: 04-26-23
|
||||
package com.mattrixwv.cipherstream.polysubstitution;
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
public class Columnar{
|
||||
protected static final Logger logger = LoggerFactory.getLogger(Columnar.class);
|
||||
protected static Logger logger = LoggerFactory.getLogger(Columnar.class);
|
||||
|
||||
//Fields
|
||||
protected String inputString; //The message that needs to be encoded/decoded
|
||||
@@ -108,7 +108,7 @@ public class Columnar{
|
||||
inputString = inputString.replaceAll("\\s", "");
|
||||
}
|
||||
if(!preserveSymbols){
|
||||
logger.debug("Remoing symbols");
|
||||
logger.debug("Removing symbols");
|
||||
|
||||
inputString = inputString.replaceAll("[^a-zA-Z\\s]", "");
|
||||
}
|
||||
@@ -158,7 +158,7 @@ public class Columnar{
|
||||
if(!preserveWhitespace){
|
||||
logger.debug("Removing whitespace");
|
||||
|
||||
inputString = inputString.replaceAll("[\\s]", "");
|
||||
inputString = inputString.replaceAll("\\s", "");
|
||||
}
|
||||
if(!preserveSymbols){
|
||||
logger.debug("Removing symbols");
|
||||
@@ -271,8 +271,8 @@ public class Columnar{
|
||||
}
|
||||
|
||||
//Save and return the output
|
||||
logger.debug("Output string '{}'", output);
|
||||
outputString = output.toString();
|
||||
logger.debug("Output string '{}'", output.toString());
|
||||
}
|
||||
protected void createOutputStringFromRows(){
|
||||
logger.debug("Creating output string for decoding");
|
||||
@@ -315,15 +315,22 @@ public class Columnar{
|
||||
continue;
|
||||
}
|
||||
|
||||
logger.debug("Working character {}", gridOutput.charAt(outputLoc));
|
||||
if(Character.isUpperCase(inputChar)){
|
||||
logger.debug("Adding upper case");
|
||||
|
||||
output.append(Character.toUpperCase(gridOutput.charAt(outputLoc++)));
|
||||
++row;
|
||||
}
|
||||
else if(Character.isLowerCase(inputChar)){
|
||||
logger.debug("Adding lower case");
|
||||
|
||||
output.append(Character.toLowerCase(gridOutput.charAt(outputLoc++)));
|
||||
++row;
|
||||
}
|
||||
else{
|
||||
logger.debug("Adding symbol");
|
||||
|
||||
output.append(inputChar);
|
||||
}
|
||||
|
||||
@@ -334,20 +341,21 @@ public class Columnar{
|
||||
}
|
||||
|
||||
//Save and return the output
|
||||
logger.debug("Decoded output string '{}'", output);
|
||||
outputString = output.toString();
|
||||
logger.debug("Decoded output string '{}'", outputString);
|
||||
}
|
||||
//Strips invalid characters from the keyword and creates the grid
|
||||
protected void setKeyword(String keyword) throws InvalidKeywordException{
|
||||
//Ensure the keyword isn't null
|
||||
if(keyword == null){
|
||||
throw new NullPointerException("Keyword cannot be null");
|
||||
throw new InvalidKeywordException("Keyword cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Original keyword {}", keyword);
|
||||
|
||||
//Strip all non-letter characters and change them to uppercase
|
||||
this.keyword = keyword.toUpperCase().replaceAll("[^A-Z]", "");
|
||||
keyword = keyword.toUpperCase().replaceAll("[^A-Z]", "");
|
||||
this.keyword = keyword;
|
||||
|
||||
logger.debug("Cleaned keyword {}", keyword);
|
||||
|
||||
@@ -362,15 +370,14 @@ public class Columnar{
|
||||
throw new InvalidCharacterException("Character to add must be a letter");
|
||||
}
|
||||
|
||||
logger.debug("Setting character to add");
|
||||
logger.debug("Setting character to add {}", characterToAdd);
|
||||
|
||||
if(!preserveCapitals){
|
||||
this.characterToAdd = Character.toUpperCase(characterToAdd);
|
||||
}
|
||||
else{
|
||||
this.characterToAdd = characterToAdd;
|
||||
characterToAdd = Character.toUpperCase(characterToAdd);
|
||||
}
|
||||
|
||||
this.characterToAdd = characterToAdd;
|
||||
|
||||
logger.debug("Character to add for padding {}", characterToAdd);
|
||||
}
|
||||
//Returns a list of integers that represents the location of the characters of the keyword in alphabetic order
|
||||
@@ -409,7 +416,7 @@ public class Columnar{
|
||||
}
|
||||
|
||||
//Returning the locations
|
||||
logger.debug("Array of keyword letters {}", orderedLocations);
|
||||
logger.debug("Array of keyword letters {}", originalOrder);
|
||||
return originalOrder;
|
||||
}
|
||||
//Rearanges the grid based on the list of numbers given
|
||||
|
||||
Reference in New Issue
Block a user