Added encryption options
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
//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
|
||||
private boolean leaveSymbols; //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 +20,15 @@ public class Caesar{
|
||||
}
|
||||
//Sets the input string
|
||||
private void setInputString(String inputString){
|
||||
if(!leaveCapitals){
|
||||
inputString = inputString.toLowerCase();
|
||||
}
|
||||
if(!leaveWhitespace){
|
||||
inputString = inputString.replaceAll("\\s+", "");
|
||||
}
|
||||
if(!leaveSymbols){
|
||||
inputString = inputString.replaceAll("[^a-zA-Z0-9\\s+]", "");
|
||||
}
|
||||
this.inputString = inputString;
|
||||
}
|
||||
//Encodes the inputString and stores the result in outputString
|
||||
@@ -63,6 +74,7 @@ public class Caesar{
|
||||
//If it is an upper case letter shift it and wrap if necessary
|
||||
if(Character.isUpperCase(currentChar)){
|
||||
currentChar -= shift;
|
||||
//Wrap around if the letter is now out of bounds
|
||||
if(currentChar < 'A'){
|
||||
currentChar += 26;
|
||||
}
|
||||
@@ -73,6 +85,7 @@ public class Caesar{
|
||||
//If it is a lower case letter shift it and wrap if necessary
|
||||
else if(Character.isLowerCase(currentChar)){
|
||||
currentChar -= shift;
|
||||
//Wrap around if the letter is now out of bounds
|
||||
if(currentChar < 'a'){
|
||||
currentChar += 26;
|
||||
}
|
||||
@@ -92,6 +105,15 @@ public class Caesar{
|
||||
//Constructor
|
||||
public Caesar(){
|
||||
reset();
|
||||
leaveCapitals = false;
|
||||
leaveWhitespace = false;
|
||||
leaveSymbols = false;
|
||||
}
|
||||
public Caesar(boolean leaveCapitals, boolean leaveWhitespace, boolean leaveSymbols){
|
||||
reset();
|
||||
this.leaveCapitals = leaveCapitals;
|
||||
this.leaveWhitespace = leaveWhitespace;
|
||||
this.leaveSymbols = leaveSymbols;
|
||||
}
|
||||
//Returns the inputString
|
||||
public String getInputString(){
|
||||
@@ -105,6 +127,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();
|
||||
|
||||
Reference in New Issue
Block a user