XOR

Back to Vertical XOR page • Back to GameX page

XOR is a binary operation. Given any two equal-length bit-strings, it produces a result such that every nth bit in the output is zero UNLESS the nth bit is set in EITHER of the two input bit-strings, but not both. In general, binary operations are shown in a so-called 'truth table'. The one below is the truth table for XOR. As you can see, if you read across the rows, the result is a zero unless one or other of the inputs is on, but not both.

The following table shows a few example input strings, and their XOR output

Uses of XOR
XOR is used lots in graphics because it's a reversible operation. For example, if I XOR 0011 with 0101 (second column of above table), I get 0110. If I then XOR 0110 with 0101 again, I get back my original 0011. This is perfect for drawing things like overlays. If you ever use a paint package, or select text, or drag a window larger, those 'rubber rectangles' are drawn by XORRING the rectangle to produce a different set of bits (which are generally a lot different from their original value), and then XORRING it back again when the rectangle moves. Occasionally you can leave 'smear trails' by making the computer too busy to de-XOR the pixels and the rubber rectangle doesn't get erased properly.

In Wasteland, XOR is used a lot for compression and encoding. Because it's a reversible operation, so long as you know (or can calculate) what your original values were XORred //with//, you can reverse the encoding quickly and effectively.

Coding issues
And now the good bit. For old games, if you wanted to encrypt your stuff, a 1024-bit public key encryption, or other trap-door cipher would have been so much burden on the PC, the game would have barfed, so you needed something which just obscured the data /enough/ to make it opaque, but was fast to recover. The beauty of XOR is that almost every processor on the planet can perform a byte-to-byte XOR in one operation. If you coded this on an old 8086, you could decode 4 million bytes per second. Given that a floppy disk originally only held 180k, you could theoretically process 8 floppies-worth of data per second. Of course, loading the data off disk, and sending it back and forth to memory would reduce this number drastically. However, this shows that XOR is perfect for the "Just enough" method of security.