Java Reference
In-Depth Information
The XOR operator has an interesting property that makes it a simple way to encode
a message. When some value X is XORed with another value Y, and then that result is
XORed with Y again, X is produced. That is, given the sequence
then R2 is the same value as X. Thus, the outcome of a sequence of two XORs can produce
the original value.
You can use this principle to create a simple cipher program in which some integer is
the key that is used to both encode and decode a message by XORing the characters in that
message. To encode, the XOR operation is applied the first time, yielding the cipher text.
To decode, the XOR is applied a second time, yielding the plain text. Of course, such a
cipher has no practical value, being trivially easy to break. It does, however, provide an in-
teresting way to demonstrate the XOR. Here is a program that uses this approach to encode
and decode a short message:
Search WWH ::




Custom Search