Understanding ROT13:
The ROT13 algorithm involves shifting each letter in a string by 13 positions in the alphabet. It is a symmetric key algorithm, meaning the same algorithm is used for both encryption and decryption. ROT13 is often used for obfuscation, simple encryption, and as an easy way to hide text in plain sight.
Implementing ROT13 Decoding in C#:
Below is a C# program that takes a string as input and decodes it using the ROT13 algorithm:
using System;
class Program
{
static void Main()
{
Console.Write("Enter the string to decode: ");
string input = Console.ReadLine();
string decodedString = DecodeROT13(input);
Console.WriteLine($"Decoded string: {decodedString}");
}
static string DecodeROT13(string input)
{
char[] charArray = input.ToCharArray();
for (int i = 0; i < charArray.Length; i++)
{
char currentChar = charArray[i];
if (char.IsLetter(currentChar))
{
char baseChar = (char)(char.IsUpper(currentChar) ? 'A' : 'a');
charArray[i] = (char)((currentChar - baseChar + 13) % 26 + baseChar);
}
}
return new string(charArray);
}
}
The program prompts the user to input a string, which is then passed to the DecodeROT13
method. This method iterates through each character of the input string, applying the ROT13 algorithm only to alphabetical characters. The decoded string is then displayed to the user.
Output:
Enter the string to decode: Welcome to Techiehook.com
Decoded string: Jrypbzr gb Grpuvrubbx.pbz
Comments (0)