{{ message }}

Instantly share code, notes, and snippets.

# RobertTalbert/bitwiseXOR.md

Last active Oct 14, 2015
Example of bitwise XOR encryption

This is an example of how the bitwise XOR can be used to make a simple encryption system.

Suppose Alice wants to send the message `CAT` to Bob using the key `11000101`.

First: Convert the characters in the message to ASCII:

• `C = 01000011`
• `A = 01000001`
• `T = 01010100`

Second: Alice shares the key with Bob.

Third: Perform bitwise XOR of each bitstring in the message with the key. (Using `xor` for this since math notation not supported here.)

• `01000011 xor 11000101 = 10000110`
• `01000001 xor 11000101 = 10000100`
• `01010100 xor 11000101 = 10010001`

Fourth: Alice sends the encrypted message `01000011 01000001 01010100` to Bob. If an eavesdropper intercepted the message and tried convert this sequence back to ASCII characters, they'd get three indecipherable control characters. (Check the table.)

Fifth: Bob receives the message and XOR's each bitstring with the key:

• `10000110 xor 11000101 = 01000011`
• `10000100 xor 11000101 = 01000001`
• `10010001 xor 11000101 = 01010100`

Sixth: Bob does a reverse lookup in the ASCII table (or using a computer) to convert from binary back to characters:

• `01000011 = C`
• `01000001 = A`
• `01010100 = T`

And that's the original message.