Created
April 5, 2018 17:22
-
-
Save silmood/4daeff7d63e94c04adecdc1792b9d096 to your computer and use it in GitHub Desktop.
Rot 13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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