Back

Logical operations and encryption

Introduction
There are some interesting things you can do using logical operations in encryption.

keyXOR
XOR is the Exclusive OR Boolean operator. In other words, if you have two inputs, the output is a one only if either input is a one (but if both inputs are a one or both inputs are a zero, then the output is a zero).

Now imagine you have this data 0100010011 that you want to encrypt. You are going to use this encryption key: 0101011001 to encode it. Let's use an XOR gate to do this:

xor1

Our encrypted data is now 0001001010. The only way we can decrypt this is if we know what the original key was and using an XOR gate again. Let's decrypt this using the original key and an XOR gate. We get:

xor2

As you can see, we now have the original data back again. This method of encryption using XOR works well because you need both the data and the key to encrypt and decrypt the message. You could easily apply this system to a message by creating a key and then XORing it to the ASCII codes of the string of characters in the message. If your message was longer than the key, you could implement various systems to deal with this, but the easiest method is simply to repeat the key to make it as long as you need it to be. The original key could be created using a random stream of ones and zeros to ensure that there is no accidental pattern chosen in the key.  

Back