Practice ^ Operator

Source: Internet
Author: User

Before introducing an instance, let's take a short look at the concept of encryption.
Encryption refers to modifying the content of existing information through a special method, so that unauthorized users can obtain encrypted information without correct decryption methods, therefore, the information cannot be obtained.

When talking about encryption, some readers will be very interested and think of complicated encryption algorithms, in this example, only the unique or "^" operator is used to encrypt a number.

[Key Technologies]
In this example, the "XOR" operator is used to perform "XOR" operations on numbers to encrypt numbers in a simple way. The following describes how to encrypt a number in detail:

The XOR operator "^" is used to compare the corresponding bits of two binary numbers. During the bitwise "XOR" operation, if the corresponding bits of both binary numbers are 1 or the corresponding bits of both binary numbers are 0, 0 is returned; if one of the two bits is 1 and the other is 0, 1 is returned.

Now let's take a look at the execution process of encryption or decryption using "exclusive or". The value 23 is converted to binary 10111, and the value 15 of the encrypted number is converted to 1111.
Compare the values of two binary numbers by bit from the right to the left. If the corresponding bits of the two binary numbers are both 1 or the corresponding bits of the two binary numbers are both 0, 0 is returned ,; if one of the two bits is 1 and the other is 0, 1 is returned.
Finally, the encrypted result 24 and the number 15 are used to perform the "XOR" operation, convert 24 to 11000 in binary format, convert 15 to 1111 in binary format, and perform the "XOR" operation, the result is 23, which restores the encrypted data.

Design Process]
(1) Open Visual Studio, create a Windows form application, and name it Encrypt.
(2) Change the Name attribute of the default form Form1 to FrmEncrypt. The form layout is as follows:


The key source code is as follows:

 

Btn_Encrypt_ OK _Click ((.TryParse(.txt _ Num. text, P_int_Num) & .TryParse(.txt _ Key. text ,. txt_Encrypt_1.Text =. txt_Encrypt_2.Text = (P_int_Num ^ MessageBox. show (, btn_Revert_ OK _Click ((.TryParse(.txt _ Encrypt_2.Text, P_int_Key) & .TryParse(.txt _ Key. text ,. txt_Revert.Text = (P_int_Encrypt ^ MessageBox. show (,}Key code

 

 

 

 

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.