The symbol of XOR is ^. Bitwise XOR, the equivalent long Binary mode performs a bitwise XOR OR operation on each bit of a bitwise or binary number. The result of the operation is that if a bit is different then the bit is 1, otherwise the bit is the 0.xor operation of the inverse is itself, that is, two times or the same number of the final result is unchanged, i.e. (a XOR b) xor B = A. The XOR operation can be used for simple encryption, such as I want to say to my mm 1314520, but afraid of others know, so the two sides agreed to take my birthday 19880516 as a key. 1314520 xor 19880516 = 20665500, I will tell the 20665500 mm. MM again calculates the value of 20665500 xor 19880516 and gets 1314520, so she understands my intentions. The same bit differs by 1 and the same is 0. 0010111100 (^ or XOR)----------------11001 results x <-x # yy <-x @ yx <-x @ y Executes the first sentence after x becomes x # Y. Then the second sentence is actually y <-x # y @ y, because # and @ are inverse each other, then y becomes the original x. In the third sentence, X is actually assigned to (x # y) @ x, and if the # operation has an Exchange law, then x becomes the original y when the value is assigned. The result of these three sentences is that the positions of X and Y are interchanged. Using PHP with this principle allows for simple and efficient encryption
function Mycrypt ($STR, $key) {$slen = strlen ($str); $klen = strlen ($key); $cipher = "; for ($i =0; $i < $slen; $i = $i + $kle N) {$cipher. = substr ($str, $i, $klen) ^ $key;} return $cipher;}
The receiver implements simple decryption
function Myuncrypt ($STR, $key) {$slen = strlen ($str); $klen = strlen ($key); $plain = "; for ($i =0; $i < $slen; $i = $i + $kl EN) {$plain. = $key ^substr ($str, $i, $klen);} return $plain;}
[PHP] Simple cryptographic application of XOR or operation of [bit conversion accumulation]