Updated Vigenere to work with Autokey

This commit is contained in:
2021-07-28 20:57:31 -04:00
parent a142b679a9
commit b9e4efa6c0

View File

@@ -9,13 +9,13 @@ import java.util.ArrayList;
public class Vigenere{ public class Vigenere{
public static final String version = "1.0"; //The current library's version number public static final String version = "1.0"; //The current library's version number
private String inputString; //This is the string that needs encoded/decoded protected String inputString; //This is the string that needs encoded/decoded
private 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
private 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
private ArrayList<Integer> offset; //Holds the offsets coputed from each character in the keyword protected ArrayList<Integer> offset; //Holds the offsets coputed from each character in the keyword
//Uses keyword to calculate the offset for the Caesar cipher for each character //Uses keyword to calculate the offset for the Caesar cipher for each character
private void setOffset(){ protected void setOffset(){
//Reserve the correct size to increase speed later //Reserve the correct size to increase speed later
offset.ensureCapacity(keyword.length()); offset.ensureCapacity(keyword.length());
@@ -26,7 +26,7 @@ public class Vigenere{
} }
} }
//Sets inputString //Sets inputString
private void setInputString(String input){ protected void setInputString(String input){
//Convert all letters to uppercase //Convert all letters to uppercase
input = input.toUpperCase(); input = input.toUpperCase();
//Remove all characters except capital letters //Remove all characters except capital letters
@@ -35,7 +35,7 @@ public class Vigenere{
inputString = input; inputString = input;
} }
//Sets keyword //Sets keyword
private void setKeyword(String key) throws Exception{ protected void setKeyword(String key) throws Exception{
//Convert all letters to uppercase //Convert all letters to uppercase
key = key.toUpperCase(); key = key.toUpperCase();
//Remove all characters except capital letters //Remove all characters except capital letters
@@ -52,7 +52,7 @@ public class Vigenere{
} }
} }
//Encodes inputString and stores the result in outputString //Encodes inputString and stores the result in outputString
private String encode(){ protected String encode(){
StringBuilder output = new StringBuilder(); StringBuilder output = new StringBuilder();
//Step through every character in the inputString and advance it the correct amount, according to offset //Step through every character in the inputString and advance it the correct amount, according to offset
@@ -72,7 +72,7 @@ public class Vigenere{
return outputString; return outputString;
} }
//Decodes inputString and stores the result in outputString //Decodes inputString and stores the result in outputString
private String decode(){ protected String decode(){
StringBuilder output = new StringBuilder(); StringBuilder output = new StringBuilder();
//Step through every character in the inputString and advance it the correct amount, according to offset //Step through every character in the inputString and advance it the correct amount, according to offset