Atbash chaptial transform started
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
//CipherStreamJava/src/main/java/mattrixwv/CipherStreamJava/Atbash.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-25-21
|
||||
//Modified: 07-25-21
|
||||
//Modified: 12-25-21
|
||||
//This is the declaration of the Atbash class
|
||||
package mattrixwv.CipherStreamJava;
|
||||
|
||||
|
||||
public class Atbash{
|
||||
public static final String version = "1.0";
|
||||
private String inputString; //Holds the string that needs encoded or decoded
|
||||
private String outputString; //Holds teh current version of the library
|
||||
private String outputString; //The encoded/decoded string
|
||||
private boolean leaveCapitals; //Whether to respect capitals in the output string
|
||||
private boolean leaveWhitespace; //Whether to respect whitespace in the output string
|
||||
//Decodes inputString and stores in outputString
|
||||
private String decode(){
|
||||
StringBuilder output = new StringBuilder();
|
||||
@@ -26,7 +27,16 @@ public class Atbash{
|
||||
StringBuilder output = new StringBuilder();
|
||||
//Step through every element in the inputString and shift it the correct amount
|
||||
for(int cnt = 0;cnt < inputString.length();++cnt){
|
||||
output.append((char)(inputString.charAt(cnt) + 25 - (2 * (inputString.charAt(cnt) - 'A'))));
|
||||
//Skip any whitespace
|
||||
if(Character.isWhitespace(inputString.charAt(cnt))){
|
||||
continue;
|
||||
}
|
||||
//Use either uppercase or lowercase for the base
|
||||
char letterBase = 'a';
|
||||
if(Character.isUpperCase(inputString.charAt(cnt))){
|
||||
letterBase = 'A';
|
||||
}
|
||||
output.append((char)(inputString.charAt(cnt) + 25 - (2 * (inputString.charAt(cnt) - letterBase))));
|
||||
}
|
||||
|
||||
outputString = output.toString();
|
||||
@@ -34,15 +44,29 @@ public class Atbash{
|
||||
}
|
||||
//Removes all invalid characters and sets inputString
|
||||
private void setInputString(String input){
|
||||
//Convert all letters to uppercase
|
||||
input = input.toUpperCase();
|
||||
//Remove all characters except capital letters
|
||||
input = input.replaceAll("[^A-Z]", "");
|
||||
if(!leaveCapitals){
|
||||
//Convert all letters to uppercase
|
||||
input = input.toUpperCase();
|
||||
}
|
||||
if(!leaveWhitespace){
|
||||
//Remove all characters except capital letters
|
||||
input = input.toLowerCase();
|
||||
}
|
||||
//Save the string
|
||||
inputString = input;
|
||||
}
|
||||
|
||||
|
||||
public Atbash(){
|
||||
reset();
|
||||
leaveCapitals = false;
|
||||
leaveWhitespace = false;
|
||||
}
|
||||
public Atbash(boolean leaveCapitals, boolean leaveWhitespace){
|
||||
reset();
|
||||
this.leaveCapitals = leaveCapitals;
|
||||
this.leaveWhitespace = leaveWhitespace;
|
||||
}
|
||||
public String getInputString(){
|
||||
return inputString;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ public class Morse{
|
||||
"--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", //M-Z
|
||||
"-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----." //0-9
|
||||
};
|
||||
public static final String version = "1.0"; //The current library's version
|
||||
private String inputString; //The string that needs encoded/decoded
|
||||
private String outputString; //The encoded/decoded message
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ package mattrixwv.CipherStreamJava;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Vigenere{
|
||||
public static final String version = "1.0"; //The current library's version number
|
||||
protected String inputString; //This is the string that needs encoded/decoded
|
||||
protected String outputString; //This is the string that is output after encoding/decoding
|
||||
protected String keyword; //This is the keyword that is resposible for determining the offsets that you change each character by
|
||||
|
||||
Reference in New Issue
Block a user