XOR Encryption in x64 Assembly: Fixed Key, Rolling Key & the lea vs mov Pointer Bug | No libc
XOR encryption in assembly is three operations: open a file, XOR each byte against a key in a tight loop, write the output. The fixed-key version is eight instructions per iteration; the rolling-key version adds one — add r15b, 0x11 — which updates the key every cycle and wraps automatically at 0xFF because r15b is 8-bit. Both versions decrypt with the same code. The real lesson is a pointer bug that every assembly programmer hits: mov rdx, [buffer] dereferences the label, turning file data into a memory address and segfaulting; lea rdx, [buffer] takes the address itself.