Rot13 is a simple encryption method, mainly used to encrypt the first 13 letters and the last 13 letters of 26 English letters. Today, let's take a look at the implementation of using rot13 for encryption and decryption in C #. Let's use an instance to answer your questions.
Although the encryption method is simple, the rot13 encryption is used in the Windows registry.
Public String rot13encode (string inputtext)
{
Int I;
Char currentcharacter;
Int currentcharactercode;
String encodedtext = \"\";
// Iterate through the length of the input parameter
For (I = 0; I <inputtext. length; I ++)
{
// Convert the current character to a char
Currentcharacter = system. Convert. tochar (inputtext. substring (I, 1 ));
// Get the character code of the Current Character
Currentcharactercode = (INT) currentcharacter;
// Modify the character code of the character,-this
// So that \ "A \" becomes \ "n \", \ "Z \" becomes \ "m \", \ "n \" becomes \ "Y \" and so on
If (currentcharactercode> = 97 & currentcharactercode <= 109)
{
Currentcharactercode = currentcharactercode + 13; [Page]
}
Else if (currentcharactercode> = 110 & currentcharactercode <= 122)
{
Currentcharactercode = currentcharactercode-13;
}
Else if (currentcharactercode> = 65 & currentcharactercode <= 77)
{
Currentcharactercode = currentcharactercode + 13;
}
Else if (currentcharactercode >=78 & currentcharactercode <= 90)
{
Currentcharactercode = currentcharactercode-13;
}
// Add the current character to the string to be returned
Encodedtext = encodedtext + (char) currentcharactercode;
}
Return encodedtext;
}
[Page]
The encryption and decryption methods are the same. The string to be encrypted and decrypted is returned by passing the string into the method.