← Back

XOR Cipher


Welcome back.

This time we will discuss about 'how' can we encrypt a bit-text. Remember, our focus during encryption/decryption is to go from an original plaintext to a ciphertext using a key, and whatever we 'do-upon' (the operation) the original plaintext must also be 'reversible' or 'decrypt-able' using the key.

We can do mainly 4 operations on bits: AND, OR, NOT and XOR. Examples of these operations are given below:

O OR O = O |	O OR 1 = 1 |	1 OR 0 = 1 |	1 OR 1 = 1
O AND O = O |	O AND 1 = 0 |	1 AND 0 = 0 |	1 AND 1 = 1
O XOR O = O |	O XOR 1 = 1 |	1 XOR 0 = 1 |	1 XOR 1 = 0
NOT O = 1 | NOT 1 = 0				
On close inspection, you will find that only XOR operation is 'reversible', and since, that is an important requirement for encryption/decryption, we use XOR as a cipher operation.

Let's see an example.
Suppose your plaintext is 01000001 (binary for 'A'), and the 'key' you want to use is 01011000 (binary for 'X'). Then the XOR operation will result in the cipher-bits (00011001 in binary; or GQ== in base64) as follows:
Plaintext: 	0 1 0 0 0 0 0 1
Key:		0 1 0 1 1 0 0 0
Cipher(XOR)	0 0 0 1 1 0 0 1				
You might have noted that in the XOR cipher discussed here, the length of the plain-bits is equal to the key-bits, something like One Time Pad.
XOR Cipher is sometimes also known as Vernam Cipher because such use of XOR operations to the individual bits was specified in 1919 by Gilbert Sandford Vernam.

The Advances

This is the really just the basic, the primitive operation. The real usage is actually quite advanced.

Modern bit ciphers are mainly divided into two categories:
One way is the bit by bit XORing of the whole stream of plain-bits (after computing an as-random-as-possible bit-key-stream in an algorithmically clever way eg: RC4)

The second way is to divide the plaintext-bits into blocks (eg. 64-64 bits of blocks) and then 'working' upon those blocks-of-bits in different ways to encrypt the data.

Now, remember that our aim is to make it difficult for the attacker to 'break' the 'cipher-bits' (i.e. to crack cipher-bits, without the knowledge of key-bits). How can we do that?
We should primarily do two things - firstly: 'substituting' every bit with some other bit (ie. disguising or confusing); each plaintext element or group of elements is uniquely replaced by a corresponding ciphertext element or group of elements.
And secondly, re-arranging or scrambling or diffusing every plaintext-bit (like transpositioning or producing permutations) to arrive at a ciphertext.

Indeed this is what is done in 'advanced' versions of modern-day techniques which work on (blocks of) bits. Many 'rounds' of substitution and permutation; or confusion and diffusion are done to make the ciphertext, more and more complicated; and less and less breakable. (like in block ciphers DES, AES, etc.)

While operating on blocks, we also get to choose among different 'modes' of operations. For example, will you use the same 'key' to encrypt all the blocks of bits one-by-one, or will you try some chaining mechanism! There are many modes to consider.

Another consideration or the desired achievement is the "Avalanche effect" that means: small change in the plaintext or the keytext should result in a large change in ciphertext. This makes it difficult for the 'cracker' to find any 'pattern' in the ciphertext, and hence, also difficult to 'break' or 'crack' it.

So these are the advanced parts of the modern cryptography. To be more specific, 'symmetric' cryptography, where 'one' key (which must remain private to all the 'friend'-parties) can be used to both - encrypt and decrypt the plainbits.

More Next

In the next few posts, we will discuss-in-detail the above-mentioned modern symmetric ciphers - the RC4 stream cipher, and the DES block cipher. We will also see different modes of operations for the block cipher. Mini-versions of those techniques will also be implemented separately; and could be used to practically see the 'intermediate' steps involved in the processes.
Bye till then.

Post-15 Ended.