XOR

Exclusive or: a bit operation that outputs 1 when two bits differ and 0 when they match.

In more detail

Applying the same value twice undoes it, so XOR with a keystream encrypts and XOR with it again decrypts. That property is also the danger: XOR of known plaintext with its ciphertext reveals the keystream, and flipping a ciphertext bit flips the matching plaintext bit. Malware often uses XOR with a short key as a simple way to hide strings and code.

Example

tampered[4] ^= ord("0") ^ ord("9")  # XOR mask: '0' becomes '9' with no key needed

Related terms

Taught in

References