Tuesday, 19 June 2012

Examples of ciphers

Agenda : Introduction of Cipher
              Substitution Cipher

              Ceaser Cipher
              Vigener Cipher
              Rotor machines
              DES & AES
             

Cipher is a pair of algorithms namely encryption denoted by E and decryption  denoted by D.

Encryption algorithm : 

Input : Plain Message  'M'
           Shared key 'K'
Output : Cipher text 'C' =: E(K,M)
Note : always write the key 'K'  first

Decryption algorithm : 

Input :  Cipher 'C'
           Shared key 'K'

Output : Plain message 'M' =: D(E(K,M))=: D(K,C)
Fact : Encryption and decryption algorithms use the same key 'K' .That is why it is called Symmetric Ciphers.

Example 1 : Substitution cipher

In this procedure, there would be a substitution table  which basically tells how to map messages (letters)
Let us assume the substitution table 

A->C
B->W
C->N
.
.
.
Z->A

Exercise:

Plain message : BCZA

Encryption of this message using this key here would be, is done by substituting one letter at a time. So b becomes w, c becomes n, z becomes a, and a becomes c. So the encryption of BCZA
is WNAC, and this defines the cypher text. Similarly we can view crypt ,the cypher text using the same key and of course we'll get back the original message.

Example 2 : Ceaser cipher

The ceaser cipher, actually, is not really a cipher at all. And the reason is that it doesn't
have a key. What a ceaser cipher is, basically a substitution cipher where the
substitution is fixed. Namely, it's a shift by three. So a becomes d b becomes
e, c becomes f and so on and so forth. It's a fixed substitution that's applied to all plain text messages.  So if an attacker knows how our encryption scheme works, he can easily decrypt the message. The key is not random, and therefore, decryption is very easy once you understand how the scheme actually works. 

Q) can't we break substitution cipher ?
A) Yes,possible even though substitution tables are chosen at random.
Q) How to break cipher ?
Facts to be known to understand : 
Random tables : 26 ! (since we have got 26 letters ,each letter is a table itself)
                      26 ! = pow(2,88), Key space = 88bits

Most frequent letter : E (appears 12.7 percent of the time in standard English texts)
                              T(appears 9.1 percent of the time in standard English texts) 
                              A(appears 8.1 percent of the time in standard English texts)
The remaining letters in English appear roughly same amount of time, other than some rare letters like q and x.

Procedure :

1) Using frequencies of english letters, count how many times every letter appears. Now
the most common letter in the cypher text is going to be the encryption of the
letter e with very high probability.so recovered one entry in the
key table. Now I know what the letter e knocks to. And the second most frequent letter is very likely to be the encryption of the letter t. So we have recovered a second entry in the key table. And we can continue this way. Therefore we have recovered three entries (E,T,A).

2)Use frequencies of pairs of letters, called diadems.Count how many times each pair of letters appears in the cipher text, ( The most common pairs of letters are things like, he, an, In,Th)Therefore it is likely to be the encryption of one of these four pairs. And so by trial and error we can sort of figure out more entry more elements in the key table and again by more trial and error I dissuade by looking at trigrams. I can actually figure out the entire key table. 

Bottom line:  Just given the cypher text the attack can recover the decryption key and therefore recover the original plaintext. So there's really no point in encrypting anything using the substitution cipher.

Example 3 : Vigenèr cipher

This cipher is well known because while it is easy to understand and implement
 
Table used for E & D
Procedure : 

It consists of the alphabet written out 26 times in different rows, each alphabet shifted cyclically to the left compared to the previous alphabet, corresponding to the 26 possible Caesar ciphers.

Example :   
Suppose that the plain text to be encrypted is:
ATTACKATDAWN
The person sending the message chooses a keyword and repeats it until it matches the length of the plaintext, for example, the keyword "LEMON": LEMONLEMONLE
First letter of the plaintext, A, is paired with L, the first letter of the key. So use row L and column A of the Vigenère square, namely L. Similarly, for the second letter of the plaintext, the second letter of the key is used; the letter at row E and column T is X. The rest of the plaintext is enciphered in a similar fashion:
Plain text: ATTACKATDAWN
Key: LEMONLEMONLE
Cipher text: LXFOPVEFRNHR
 
and in fact, decryption is just as easy encryption. Basically, the way you would decrypt is,
again, you would write the cipher text under the key. You would replicate the key
and then you would subtract.

Breaking the cipher : 
1) Assume the length of the key ( suppose say 5)
2) Break the cipher text into group of 5 letters.
3) Take first letter of each group -We know that every first letter in each group is encrypted using the same letter 'L' . So if we collect all these letters then the most common letter
among the set is likely to be the encryption of e, (E is the most common letter in English) and also every fifth letter is also the encrytpion of 'e'. So let's just suppose that in fact the most common letter every sixth letter happens to be the letter 'h'. Then we know that E plus the first letter of the key is equal to H. That says that the first letter of the key is equal to H minus E which is 'L' that is the first letter of the key.So on and so forth we can find all the letters in the key.


Note : The only caveat is that I had to assume ahead of time that we know the length of the key.If we don't know the key then assume key -1 ,2,3...until finally we get a message that is sensical.So once we recover, right length of the key, right key and then right message.

Example 3 : Rotor motors

People wanted to design ciphers that use electric motors. In particular, these ciphers are
called rotor machines because they use rotors. So an early example is called the
Hibber machine which uses a single motor.For more information about its working visit https://www.coursera.org 

This played an important role in world wars. After the war, there was an end of the mechanical
age and started the digital age where folks were using computers and as the world kind of migrated to using computers, the government wanted industry to use a good cypher With, so the government put out this request for proposals for a data encryption standard, federal data encryption standard.  



Facts about : DES (Data Encryption Standard)

** Introduced by IBM in 1974.
** The key space for DES is two to the 56, which is relatively small these days, but was large  enough back in 1974.
** It encrypts 64 bits at a time, unlike one character at a time followed in rotor machines.
** Because the  users use such a small key space these days it can be broken by a search which is insecure to use,in projects. Unfortunately, it is used in some legacy systems, but it definitely is on its way out and should not be used in new projects. Today there are new cyphers, things like the advanced encryption standard which uses 128 byte keys.

No comments:

Post a Comment