Created
January 4, 2014 00:44
-
-
Save mikedugan/8249803 to your computer and use it in GitHub Desktop.
the rot13 is essentially the caesar transform applied with an offset of 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
| static class Rot13 | |
| { | |
| /// <summary> | |
| /// Performs the ROT13 character rotation. | |
| /// </summary> | |
| public static string Transform(string value) | |
| { | |
| char[] array = value.ToCharArray(); | |
| for (int i = 0; i < array.Length; i++) | |
| { | |
| int number = (int)array[i]; | |
| if (number >= 'a' && number <= 'z') | |
| { | |
| if (number > 'm') | |
| { | |
| number -= 13; | |
| } | |
| else | |
| { | |
| number += 13; | |
| } | |
| } | |
| else if (number >= 'A' && number <= 'Z') | |
| { | |
| if (number > 'M') | |
| { | |
| number -= 13; | |
| } | |
| else | |
| { | |
| number += 13; | |
| } | |
| } | |
| array[i] = (char)number; | |
| } | |
| return new string(array); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment