Skip to content

Instantly share code, notes, and snippets.

@silmood
Created April 5, 2018 17:22
Show Gist options
  • Select an option

  • Save silmood/4daeff7d63e94c04adecdc1792b9d096 to your computer and use it in GitHub Desktop.

Select an option

Save silmood/4daeff7d63e94c04adecdc1792b9d096 to your computer and use it in GitHub Desktop.
Rot 13
public class Cipher {
public String rot13(String text) {
char[] chars = text.toCharArray();
StringBuilder result = new StringBuilder();
for (char c : chars) {
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;
result.append(c);
}
return result.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment