ROT-13 function in java?

Might as well contribute my function to save other developers the valuable seconds

public static String rot13(String input) {
   StringBuilder sb = new StringBuilder();
   for (int i = 0; i < input.length(); i++) {
       char c = input.charAt(i);
       if       (c >= 'a' && c <= 'm') c += 13;
       else if  (c >= 'A' && c <= 'M') c += 13;
       else if  (c >= 'n' && c <= 'z') c -= 13;
       else if  (c >= 'N' && c <= 'Z') c -= 13;
       sb.append(c);
   }
   return sb.toString();
}

Leave a Comment