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


Leave a comment

Your comment