One of the most widely used and useful operations in
cryptographic algorithms is XOR. It is worth understanding
just why XOR is such a helpful operation. XOR, as
it is used in cryptography, is a bitwise numeric function
with a domain of a bit pair, and the range of a result bit.
(It has a slightly different, but isomorphic, use in formal
logic.) Most readers are probably already familiar with
XOR's result table, but let us take a look at it as a
reminder:
XOR(1, 1) --> 0
XOR(1, 0) --> 1
XOR(0, 1) --> 1
XOR(0, 0) --> 0
We write the XOR function in the above table in a prefix
notation, but most programming languages use an infix form.
Don't worry about the notation -- the above just helps
illustrate the functional nature of XOR. Also, in most
programming languages, the operation called XOR (or more
accurately "bitwise XOR") does more than the above table
shows, but only as a generalization. That is, in an operation
like C, Perl, or Python, "^" is actually the Boolean XOR of
each corresponding bit in two bit-fields (or ASCII characters,
integers, etc., considered as bit-fields). In principle, a
language with only a single-bit XOR could simulate the
bit-field XOR behavior by looping through each bit position
(but computational efficiency benefits greatly from the
compound bit-field XOR).