Implement simple encryption and decryption with unique or nature

Source: Internet
Author: User
The XOR operation is represented by ^. The XOR operation is performed on integers a and B. When the two numbers have different binary locations, this bit is 1. Otherwise, it is 0.
The exclusive or operation has a property:
If a ^ B = c, c ^ B = a, that is, the result of two XOR operations on a by the same number is.

This feature allows you to encrypt and decrypt strings.

Example code: private void button#click (object sender, EventArgs e)
{
Char a1 = '9', a2 = 'point', a3 = 'in', a4 = 'attacking ';
Char secret = 'bcc ';
A1 = (char) (a1 ^ secret );
A2 = (char) (a2 ^ secret );
A3 = (char) (a3 ^ secret );
A4 = (char) (a4 ^ secret );
String secretStr = "ciphertext:" + a1 + a2 + a3 + a4;
A1 = (char) (a1 ^ secret );
A2 = (char) (a2 ^ secret );
A3 = (char) (a3 ^ secret );
A4 = (char) (a4 ^ secret );
String realStr = "plaintext:" + a1 + a2 + a3 + a4;
MessageBox. Show (secretStr + "\ r \ n" + realStr );
}

Result:

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.