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 neededRelated terms
- keystream — A stream of random-looking bytes made from a key and a nonce, which a stream cipher combines with the message using XOR to encrypt it.
- bit-flipping attack — An attack that changes chosen bits of encrypted data so that, after decryption, the message says something different, without the attacker knowing the key.
- bit — The smallest unit of data: a single binary digit that is either 0 or 1.
- CTR mode — Counter mode: a way of using a block cipher that encrypts a running counter to make keystream, then combines that with the message using XOR.
- hex string — A YARA pattern written as hexadecimal bytes in braces, which can include wildcards and jumps for bytes that vary.
- packer — A tool that compresses or encrypts a program and wraps it in a small unpacking stub, hiding the real code and strings from static analysis.
- malware — Software written to cause harm, such as stealing data, encrypting files for ransom or mining cryptocurrency.
Taught in
- Symmetric Encryption: AES-GCM & ChaCha20 — Cybersecurity Fundamentals, GRC & Cryptography
- YARA Rule Authoring & File Signature Matching — Security Operations & Threat Hunting (SOC)