Last active
February 25, 2025 14:50
-
-
Save aliozgur/70ff04f99416559f7dada9a995503a7e to your computer and use it in GitHub Desktop.
ROT13
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 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