Added options to leave whitespace and capitals

This commit is contained in:
2021-12-25 14:12:59 -05:00
parent a6a30f38a9
commit 6c40edbdfe
2 changed files with 269 additions and 15 deletions

View File

@@ -1,16 +1,17 @@
//CipherStreamJava/src/main/java/mattrixwv/CipherStreamJava/Caesar.java
//Matthew Ellison
// Created: 07-25-21
//Modified: 07-25-21
//Modified: 12-25-21
//This is the declaration of the Caesar class
package mattrixwv.CipherStreamJava;
public class Caesar{
public static final String version = "1.0"; //The current version number for the library
private String inputString; //The string that needs encoded/decoded
private String outputString; //The encoded/decoded string
private int shift; //The amount that you need to shift each letter
private boolean leaveCapitals; //Whether to respect capitals in the output string
private boolean leaveWhitespace; //Whether to respect whitespace in the output string
//Sets shift and makes sure it is within the propper bounds
private void setShift(int shiftAmount){
//If you shift more than 26 you will just be wrapping back around again
@@ -18,6 +19,12 @@ public class Caesar{
}
//Sets the input string
private void setInputString(String inputString){
if(!leaveCapitals){
inputString = inputString.toLowerCase();
}
if(!leaveWhitespace){
inputString = inputString.replaceAll("\\s+", "");
}
this.inputString = inputString;
}
//Encodes the inputString and stores the result in outputString
@@ -92,6 +99,13 @@ public class Caesar{
//Constructor
public Caesar(){
reset();
leaveCapitals = false;
leaveWhitespace = false;
}
public Caesar(boolean leaveCapitals, boolean leaveWhitespace){
reset();
this.leaveCapitals = leaveCapitals;
this.leaveWhitespace = leaveWhitespace;
}
//Returns the inputString
public String getInputString(){
@@ -105,6 +119,20 @@ public class Caesar{
public String getOutputString(){
return outputString;
}
//Returns if capitals should be respected in the output
public boolean getLeaveCapitals(){
return leaveCapitals;
}
public void setLeaveCapitals(boolean leaveCapitals){
this.leaveCapitals = leaveCapitals;
}
//Returns if whitespace should be respected in the output
public boolean getLeaveWhitespace(){
return leaveWhitespace;
}
public void setLeaveWhitespace(boolean leaveWhitespace){
this.leaveWhitespace = leaveWhitespace;
}
//Sets the shift and inputString and encodes the message
public String encode(int shiftAmount, String inputString){
reset();