@Test public void runTest() { assertEquals("MIKMBRYMPVY", Autokey.autokey("TESTINGTHIS", "TEST", Mode.ENCRYPT)); assertEquals("TESTINGTHIS", Autokey.autokey("MIKMBRYMPVY", "TEST", Mode.DECRYPT)); }
public static String autokey(String input, String key, Mode mode) { StringBuilder output = new StringBuilder(); if (mode == Mode.ENCRYPT) { output = new StringBuilder(Vigenere.vigenere(input, key + input, Mode.ENCRYPT)); } if (mode == Mode.DECRYPT) { int[] shiftKey = new int[(input + key).length()]; int index = key.length(); for (int i = 0; i < index; i++) { shiftKey[i] = findIndex(key.charAt(i)); } String cur; for (int i = 0; i < input.length(); i++) { cur = getChar(input.charAt(i), shiftKey[i], false); output.append(cur); shiftKey[index] = findIndex(cur.charAt(0)); index++; } } return output.toString().toUpperCase(); }
Autokey { public static String autokey(String input, String key, Mode mode) { StringBuilder output = new StringBuilder(); if (mode == Mode.ENCRYPT) { output = new StringBuilder(Vigenere.vigenere(input, key + input, Mode.ENCRYPT)); } if (mode == Mode.DECRYPT) { int[] shiftKey = new int[(input + key).length()]; int index = key.length(); for (int i = 0; i < index; i++) { shiftKey[i] = findIndex(key.charAt(i)); } String cur; for (int i = 0; i < input.length(); i++) { cur = getChar(input.charAt(i), shiftKey[i], false); output.append(cur); shiftKey[index] = findIndex(cur.charAt(0)); index++; } } return output.toString().toUpperCase(); } }
Autokey { public static String autokey(String input, String key, Mode mode) { StringBuilder output = new StringBuilder(); if (mode == Mode.ENCRYPT) { output = new StringBuilder(Vigenere.vigenere(input, key + input, Mode.ENCRYPT)); } if (mode == Mode.DECRYPT) { int[] shiftKey = new int[(input + key).length()]; int index = key.length(); for (int i = 0; i < index; i++) { shiftKey[i] = findIndex(key.charAt(i)); } String cur; for (int i = 0; i < input.length(); i++) { cur = getChar(input.charAt(i), shiftKey[i], false); output.append(cur); shiftKey[index] = findIndex(cur.charAt(0)); index++; } } return output.toString().toUpperCase(); }  }
Autokey { public static String autokey(String input, String key, Mode mode) { StringBuilder output = new StringBuilder(); if (mode == Mode.ENCRYPT) { output = new StringBuilder(Vigenere.vigenere(input, key + input, Mode.ENCRYPT)); } if (mode == Mode.DECRYPT) { int[] shiftKey = new int[(input + key).length()]; int index = key.length(); for (int i = 0; i < index; i++) { shiftKey[i] = findIndex(key.charAt(i)); } String cur; for (int i = 0; i < input.length(); i++) { cur = getChar(input.charAt(i), shiftKey[i], false); output.append(cur); shiftKey[index] = findIndex(cur.charAt(0)); index++; } } return output.toString().toUpperCase(); }  static void main(String[] args); static String autokey(String input, String key, Mode mode); }
Autokey { public static String autokey(String input, String key, Mode mode) { StringBuilder output = new StringBuilder(); if (mode == Mode.ENCRYPT) { output = new StringBuilder(Vigenere.vigenere(input, key + input, Mode.ENCRYPT)); } if (mode == Mode.DECRYPT) { int[] shiftKey = new int[(input + key).length()]; int index = key.length(); for (int i = 0; i < index; i++) { shiftKey[i] = findIndex(key.charAt(i)); } String cur; for (int i = 0; i < input.length(); i++) { cur = getChar(input.charAt(i), shiftKey[i], false); output.append(cur); shiftKey[index] = findIndex(cur.charAt(0)); index++; } } return output.toString().toUpperCase(); }  static void main(String[] args); static String autokey(String input, String key, Mode mode);  }