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: