@Test public void runTest() { assertEquals("KHOOR", Caesar.caesar("HELLO", 3, Mode.ENCRYPT)); assertEquals("HELLO", Caesar.caesar("KHOOR", 3, Mode.DECRYPT)); }
public static String caesar(String inputText, int shiftCount, final Mode mode) { try { String output = ""; int ascii; if (mode == Mode.DECRYPT) { shiftCount=-1*shiftCount; } shiftCount=(shiftCount+26)%26; for(int a=0;a<inputText.length();a++){ ascii=(((int)inputText.charAt(a))+shiftCount); output+=(ascii>'Z')?Character.toString((char)((ascii%'Z')+'A'-1)):Character.toString((char)(ascii)); } return output; } catch (ArrayIndexOutOfBoundsException e) { return e.toString(); } }
Caesar { public static String caesar(String inputText, int shiftCount, final Mode mode) { try { String output = ""; int ascii; if (mode == Mode.DECRYPT) { shiftCount=-1*shiftCount; } shiftCount=(shiftCount+26)%26; for(int a=0;a<inputText.length();a++){ ascii=(((int)inputText.charAt(a))+shiftCount); output+=(ascii>'Z')?Character.toString((char)((ascii%'Z')+'A'-1)):Character.toString((char)(ascii)); } return output; } catch (ArrayIndexOutOfBoundsException e) { return e.toString(); } } }
Caesar { public static String caesar(String inputText, int shiftCount, final Mode mode) { try { String output = ""; int ascii; if (mode == Mode.DECRYPT) { shiftCount=-1*shiftCount; } shiftCount=(shiftCount+26)%26; for(int a=0;a<inputText.length();a++){ ascii=(((int)inputText.charAt(a))+shiftCount); output+=(ascii>'Z')?Character.toString((char)((ascii%'Z')+'A'-1)):Character.toString((char)(ascii)); } return output; } catch (ArrayIndexOutOfBoundsException e) { return e.toString(); } }  }
Caesar { public static String caesar(String inputText, int shiftCount, final Mode mode) { try { String output = ""; int ascii; if (mode == Mode.DECRYPT) { shiftCount=-1*shiftCount; } shiftCount=(shiftCount+26)%26; for(int a=0;a<inputText.length();a++){ ascii=(((int)inputText.charAt(a))+shiftCount); output+=(ascii>'Z')?Character.toString((char)((ascii%'Z')+'A'-1)):Character.toString((char)(ascii)); } return output; } catch (ArrayIndexOutOfBoundsException e) { return e.toString(); } }  static void main(String[] args); static String caesar(String inputText, int shiftCount, final Mode mode); }
Caesar { public static String caesar(String inputText, int shiftCount, final Mode mode) { try { String output = ""; int ascii; if (mode == Mode.DECRYPT) { shiftCount=-1*shiftCount; } shiftCount=(shiftCount+26)%26; for(int a=0;a<inputText.length();a++){ ascii=(((int)inputText.charAt(a))+shiftCount); output+=(ascii>'Z')?Character.toString((char)((ascii%'Z')+'A'-1)):Character.toString((char)(ascii)); } return output; } catch (ArrayIndexOutOfBoundsException e) { return e.toString(); } }  static void main(String[] args); static String caesar(String inputText, int shiftCount, final Mode mode);  }