Logical XOR, or exclusive OR, is true when exactly one operand is true and false when both operands share the same truth value. At the bit level, it produces 1 for 0 ^ 1 and 1 ^ 0, but 0 for 0 ^ 0 and 1 ^ 1. section 1.3
XOR becomes useful in byte-oriented encryption because its reversible combinations preserve each operand:
- A ^ B = C; recombining C with B recovers A, while recombining C with A recovers B. section 1.3
- Swift uses ^ for XOR, including element-by-element operations on UInt8 values. section 1.3
One-time pad
encryptOTP() XORs each byte of a String with a randomly generated dummy key and returns the dummy data plus the encrypted product. decryptOTP() XORs those two keys again and converts the resulting bytes back to a String. section 1.3


