Mohanapriya R Mohanapriya R
Updated date May 20, 2024
In this program, we will explore the world of ROT13 encryption. Also, we learn how to show hidden messages encoded with ROT13 and convert them into easily readable text.

How to Convert ROT13 Decoded Strings to Normal Strings in C#?

ROT13 (rotate by 13 places) is a simple letter substitution cipher that is used to obscure text by replacing each letter with the 13th letter after it in the alphabet. It's a basic and widely known form of encryption, often used for hiding messages in plain sight. In this program, we will explore how to convert ROT13 decoded strings back to their normal, human-readable form using C#.

ROT13 Decoding

To convert a ROT13 encoded string to its original form, you simply need to apply the ROT13 algorithm twice. Since ROT13 is a symmetric cipher, encoding and decoding are the same operations. In C#, this can be achieved by iterating through each character in the encoded string and applying the ROT13 transformation.

We will use the .NET framework's built-in methods for character manipulation.

using System;

class Program
{
    static void Main()
    {
        // Encoded string
        string encodedString = "Jrypbzr gb Grpuvrubbx.pbz";

        // Decode the ROT13 string
        string decodedString = DecodeROT13(encodedString);

        // Display the results
        Console.WriteLine("Encoded String: " + encodedString);
        Console.WriteLine("Decoded String: " + decodedString);
    }

    static string DecodeROT13(string encoded)
    {
        char[] characters = encoded.ToCharArray();

        for (int i = 0; i < characters.Length; i++)
        {
            char currentChar = characters[i];

            if (char.IsLetter(currentChar))
            {
                char baseChar = char.IsUpper(currentChar) ? 'A' : 'a';
                characters[i] = (char)(((currentChar - baseChar + 13) % 26) + baseChar);
            }
        }

        return new string(characters);
    }
}

Output:

Encoded String: Jrypbzr gb Grpuvrubbx.pbz
Decoded String: Welcome to Techiehook.com

Comments (0)

There are no comments. Be the first to comment!!!