Skip to content

Instantly share code, notes, and snippets.

@aliozgur
Last active February 25, 2025 14:50
Show Gist options
  • Save aliozgur/70ff04f99416559f7dada9a995503a7e to your computer and use it in GitHub Desktop.
Save aliozgur/70ff04f99416559f7dada9a995503a7e to your computer and use it in GitHub Desktop.
ROT13
public static string EncodeROT13(string input)
{
return string.Join("", input.Select(x => char.IsLetter(x) ? (x >= 65 && x <= 77) || (x >= 97 && x <= 109) ? (char)(x + 13) : (char)(x - 13) : x));
}
public static string DecodeRot13(string input)
{
if (string.IsNullOrEmpty(input))
return input;
StringBuilder result = new StringBuilder(input.Length);
foreach (char c in input)
{
if (c >= 'a' && c <= 'z')
{
result.Append((char)('a' + (c - 'a' + 13) % 26));
}
else if (c >= 'A' && c <= 'Z')
{
result.Append((char)('A' + (c - 'A' + 13) % 26));
}
else
{
result.Append(c);
}
}
return result.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment