Skip to content

Instantly share code, notes, and snippets.

@mikedugan
Created January 4, 2014 00:44
Show Gist options
  • Select an option

  • Save mikedugan/8249803 to your computer and use it in GitHub Desktop.

Select an option

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
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