Skip to content

Instantly share code, notes, and snippets.

@Jabriko
Created March 20, 2018 08:19
Show Gist options
  • Save Jabriko/39dcbd4a59df999fd2ae2cfebc56ed87 to your computer and use it in GitHub Desktop.
Save Jabriko/39dcbd4a59df999fd2ae2cfebc56ed87 to your computer and use it in GitHub Desktop.
package id.indrasudirman.bahanujicoba;
/**
* Created by Jabrikos on 3/16/2018.
*/
public class Rot13 {
public static String rot13 (String value) {
char[] values = value.toCharArray();
for (int i = 0; i < values.length; i++) {
char letter = values[i];
if (letter >= 'a' && letter <= 'z') {
// Rotate lowercase letters.
if (letter > 'm') {
letter -= 13;
} else {
letter += 13;
}
} else if (letter >= 'A' && letter <= 'Z') {
// Rotate uppercase letters.
if (letter > 'M') {
letter -= 13;
} else {
letter += 13;
}
}
values[i] = letter;
}
// Convert array to a new String.
return new String(values);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment