Breaking XOR Cipher

Breaking XOR Cipher

XOR is one of the most interesting logical operation but it is definitive not made for encrypting. Even using the lowest of configurations in today’s computer it can be broken down easily. Nevertheless, breaking it programmatically is a very interesting thought process.

When you know the key length, it is a breeze! You just have to apply a brute force algorithm to find your plain text.

Lets first cut short the brute force method: There are 256 ASCII characters but only 32 to 127 are printable. So use a combination from the printable range only will decrease the iterations significantly.

But how to decide programmatically when we have successfully broken the cipher?

That is the real catch here. For this we will some use known statistics of English corpus. Then we will devise a scoring mechanism programmatically, scoring positively whenever after XOR operation the output is satisfying the statistics and negatively when it is not. Then the one with the maximum score will be the real output. Some of them are:

  • The digraphs cj, fq, gx, hx, jf, jq, jx, jz, qb, qc, qj, qk, qx, qz, sx, vf, vj, vq, vx, wx, xj, zx never occur in english words.
  • Punctuation makes up to 2%-3% of the text (for short messages up to 10%)
  • The letters E,T,A,O,I,N make up around 40% of the text (those are the most frequent letters in the english language)
  • ['the', 'and', 'have', 'that', 'for', 'you', 'with', 'say', 'this', 'they', 'but', 'his', 'from', hat', 'not', "n't", 'she', 'what', 'their', 'can', 'who', 'get', 'would', 'her', 'make', 'about', know', 'will', 'one', 'time', 'there', 'year', 'think', 'when', 'which', 'them', 'some', 'people', 'take', 'out', 'into','just', 'see', 'him', 'your', 'come', 'could', 'now', 'than', 'like', 'other', 'how', 'then', 'its', 'out', 'two', 'more ,these', 'want', 'way', 'look', 'first', 'also', 'new', 'because', 'day', 'more', 'use', 'man', 'find', 'here', 'thing', 'give', 'many'] are the most common words. Note that this methods will fails if the text size is significantly low.

My Code: https://github.com/Shubhankar-Nath/Cryptopals/blob/master/Set1/breakXor.py

Tags :
comments powered by Disqus

Related Posts

How to enjoy a poem?

How to enjoy a poem?

Open disclaimer at first - I am no expert at poetry.

Read More
Five things I learnt from: A History of the World

Five things I learnt from: A History of the World

I will admit; I was one of those who resented studying history, I found it to be in contempt of my time.

Read More
In the making of Gods

In the making of Gods

A ESOTERIC PEEK AT HISTORY OF RELIGION THAT SCULPTED THE HUMAN RACE IN TIME

Read More