Atbash chaptial transform started
This commit is contained in:
@@ -1,15 +1,16 @@
|
|||||||
//CipherStreamJava/src/main/java/mattrixwv/CipherStreamJava/Atbash.java
|
//CipherStreamJava/src/main/java/mattrixwv/CipherStreamJava/Atbash.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 07-25-21
|
// Created: 07-25-21
|
||||||
//Modified: 07-25-21
|
//Modified: 12-25-21
|
||||||
//This is the declaration of the Atbash class
|
//This is the declaration of the Atbash class
|
||||||
package mattrixwv.CipherStreamJava;
|
package mattrixwv.CipherStreamJava;
|
||||||
|
|
||||||
|
|
||||||
public class Atbash{
|
public class Atbash{
|
||||||
public static final String version = "1.0";
|
|
||||||
private String inputString; //Holds the string that needs encoded or decoded
|
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
|
//Decodes inputString and stores in outputString
|
||||||
private String decode(){
|
private String decode(){
|
||||||
StringBuilder output = new StringBuilder();
|
StringBuilder output = new StringBuilder();
|
||||||
@@ -26,7 +27,16 @@ public class Atbash{
|
|||||||
StringBuilder output = new StringBuilder();
|
StringBuilder output = new StringBuilder();
|
||||||
//Step through every element in the inputString and shift it the correct amount
|
//Step through every element in the inputString and shift it the correct amount
|
||||||
for(int cnt = 0;cnt < inputString.length();++cnt){
|
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();
|
outputString = output.toString();
|
||||||
@@ -34,15 +44,29 @@ public class Atbash{
|
|||||||
}
|
}
|
||||||
//Removes all invalid characters and sets inputString
|
//Removes all invalid characters and sets inputString
|
||||||
private void setInputString(String input){
|
private void setInputString(String input){
|
||||||
//Convert all letters to uppercase
|
if(!leaveCapitals){
|
||||||
input = input.toUpperCase();
|
//Convert all letters to uppercase
|
||||||
//Remove all characters except capital letters
|
input = input.toUpperCase();
|
||||||
input = input.replaceAll("[^A-Z]", "");
|
}
|
||||||
|
if(!leaveWhitespace){
|
||||||
|
//Remove all characters except capital letters
|
||||||
|
input = input.toLowerCase();
|
||||||
|
}
|
||||||
//Save the string
|
//Save the string
|
||||||
inputString = input;
|
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(){
|
public String getInputString(){
|
||||||
return inputString;
|
return inputString;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ public class Morse{
|
|||||||
"--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", //M-Z
|
"--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", //M-Z
|
||||||
"-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----." //0-9
|
"-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----." //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 inputString; //The string that needs encoded/decoded
|
||||||
private String outputString; //The encoded/decoded message
|
private String outputString; //The encoded/decoded message
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ package mattrixwv.CipherStreamJava;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class Vigenere{
|
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 inputString; //This is the string that needs encoded/decoded
|
||||||
protected String outputString; //This is the string that is output after encoding/decoding
|
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
|
protected String keyword; //This is the keyword that is resposible for determining the offsets that you change each character by
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//CipherStreamJava/src/main/java/mattrixwv/CipherStreamJava/TestAtbash.java
|
//CipherStreamJava/src/main/java/mattrixwv/CipherStreamJava/TestAtbash.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 07-25-21
|
// Created: 07-25-21
|
||||||
//Modified: 07-25-21
|
//Modified: 12-25-21
|
||||||
//These are the tests for the Atbash class
|
//These are the tests for the Atbash class
|
||||||
package mattrixwv.CipherStreamJava;
|
package mattrixwv.CipherStreamJava;
|
||||||
|
|
||||||
@@ -18,13 +18,13 @@ public class TestAtbash{
|
|||||||
|
|
||||||
//Test 1
|
//Test 1
|
||||||
String input = "zyx";
|
String input = "zyx";
|
||||||
String correctOutput = "ABC";
|
String correctOutput = "abc";
|
||||||
String output = cipher.decode(input);
|
String output = cipher.decode(input);
|
||||||
assertEquals("Atbash Decoding failed the first test", correctOutput, output);
|
assertEquals("Atbash Decoding failed the first test", correctOutput, output);
|
||||||
|
|
||||||
//Test 2
|
//Test 2
|
||||||
input = "GSV JFRXP YILDM ULC QFNKH LEVI - GSV OZAB WLT";
|
input = "GSV JFRXP YILDM ULC QFNKH LEVI - GSV OZAB WLT";
|
||||||
correctOutput = "THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG";
|
correctOutput = "thequickbrownfoxjumpsoverthelazydog";
|
||||||
output = cipher.decode(input);
|
output = cipher.decode(input);
|
||||||
assertEquals("Atbash Decoding failed the second test", correctOutput, output);
|
assertEquals("Atbash Decoding failed the second test", correctOutput, output);
|
||||||
}
|
}
|
||||||
@@ -34,13 +34,13 @@ public class TestAtbash{
|
|||||||
|
|
||||||
//Test 1
|
//Test 1
|
||||||
String input = "abc";
|
String input = "abc";
|
||||||
String correctOutput = "ZYX";
|
String correctOutput = "zyx";
|
||||||
String output = cipher.encode(input);
|
String output = cipher.encode(input);
|
||||||
assertEquals("Atbash Encoding failed the first test", correctOutput, output);
|
assertEquals("Atbash Encoding failed the first test", correctOutput, output);
|
||||||
|
|
||||||
//Test 2
|
//Test 2
|
||||||
input = "The quick brown fox jumps over - the lazy dog";
|
input = "The quick brown fox jumps over - the lazy dog";
|
||||||
correctOutput = "GSVJFRXPYILDMULCQFNKHLEVIGSVOZABWLT";
|
correctOutput = "gsvjfrxpyildmulcqfnkhlevigsvozabwlt";
|
||||||
output = cipher.encode(input);
|
output = cipher.encode(input);
|
||||||
assertEquals("Atbash Encoding failed the second test", correctOutput, output);
|
assertEquals("Atbash Encoding failed the second test", correctOutput, output);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user