Single post

ROT47 Caesar cipher encoder/decoder C#

Here you go, Dan!

private char Rot47(char chr)
{
    if (chr == ' ') return ' ';
    int ascii = chr;
    ascii += 47;
    if (ascii > 126) ascii -= 94;
    if (ascii < 33) ascii += 94;
    return (char)ascii;
}

public string Rot47(string str)
{
    string RetStr = "";
    foreach (char c in str.ToCharArray())
        RetStr += Rot47(c).ToString();
    return RetStr;
}

Examples? ;) Encode like:

string myRot47EncStr = Rot47("My string!");

Decode like:

string myRot47DecStr = Rot47("|J DEC:?8P");

ROT47 Wikipedia entry

John Henckel
July 27th, 2016 at 8:01 pm

Here’s another option.

public static string Rot47(string input)
{
return !string.IsNullOrEmpty(input) ? new string(input.Select(x =>
(x >= ‘!’ && x
(x >= ‘a’ && x = ‘A’ && x <= 'Z') ? (char)((x – 'A' + 13) % 26 + 'A') : x).ToArray()) : input;
}

LEAVE A COMMENT

theme by teslathemes