Use rot13 to encrypt and decrypt data in C #

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.