Quiz Entry - updated: 2026.07.10
How do you XOR two 4-byte values in C?
Apply ^ to two uint32_t values; XOR combines them bit-by-bit, setting each result bit only where the two inputs differ.
uint32_t a = 0x12345678;
uint32_t b = 0xDEADBEEF;
// 0xCC99E897
uint32_t result = a ^ b;
XOR properties (useful in crypto/RE):
a ^ a = 0(anything XOR itself is zero)a ^ 0 = a(XOR with zero is identity)a ^ b ^ b = a(XOR is reversible - used in encryption!)a ^ b = b ^ a(commutative)
XOR swap trick (no temp variable):
// a = a ^ b
a ^= b;
// b = b ^ (a ^ b) = a
b ^= a;
// a = (a ^ b) ^ a = b
a ^= b;
Common use - simple encryption:
for (int i = 0; i < len; i++)
// XOR with repeating key
data[i] ^= key[i % keylen];