So here I have a piece of code that takes a string named key ("ALICE") and passes it into the method keyReader() to get the position of the alphabet of each index - to clarify A would be 1, L would be 12, I would be 9, C would be 3, and E would be 5. These numbers are stored into an array named keyArray[].
My problem is now using keyArray[] with these 5 elements that are stored in it and passing it into the method keyNumber() as a parameter in order change each number to base 27 and add it to a total which is keyNo in this case.
Any help and or suggestions are appreciated.
public class Problem2 {
public static void main(String[] args) {
String key = "ALICE"; //VARIABLE - Will be read from text file
String cipherThis = "JLMRSULTQTXLRCQQEBCHQFWWE"; //VARIABLE - Will be read from text file
int noKey = 0;
int[] keyArray = new int[5];
keyReader(key, keyArray); //reads the key
keyNumber(noKey, keyArray); //evaluates the keyNumber of keyReader
}
//Method for reading each letter of the key
private static void keyReader(String key, int[] keyArray) {
for (int x = 0; x < 5; x++) {
keyArray[x] = key.charAt(x) - 64;
}
}
//Method for evaluating the key number
private static void keyNumber(int noKey, int[] keyArray) {
int i = 0; //Counter for the numbers of the letters stored into the array using the keyReader() method
int k = 4; //Counter for the 5 letters of the key (4,3,2,1,0)
while (i < 5) {
while (k >= 0) {
noKey += Math.pow(27, k) * keyArray[i];
k--;
i++;
}
}
}
}