Skip to content

Instantly share code, notes, and snippets.

@vcsjones
Last active December 18, 2015 11:29
Show Gist options
  • Save vcsjones/5776232 to your computer and use it in GitHub Desktop.
Save vcsjones/5776232 to your computer and use it in GitHub Desktop.
ROT13
private static string Rot13(string inputText)
{
return new string(inputText.Select(c =>
{
var lower = Char.ToLower(c);
if (lower >= 'a' && lower <= 'z' && lower > 'm') return (char)(c - 13);
if (lower >= 'a' && lower <= 'z') return (char)(c + 13);
return c;
}).ToArray());
}
let rot13 (inputText:string) =
new string(inputText |> Seq.map(fun x ->
let lower = System.Char.ToLower(x)
match lower with
| c when c >= 'a' && c <= 'z' && c > 'm' -> int x-13 |> char
| c when c >= 'a' && c <= 'z' -> int x+13 |> char
| _ -> x
) |> Seq.toArray)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment