Sunday, July 25, 2010

CRYPTOGRAPHY WITH MATLAB

"CRYPTOGRAPHY" Its origination is from Greek word 'kryptos' means 'hidden','secret' and 'grapho' means 'writting'
In modern society we generally use DES (Data Encryption Standard) algorithm for cryptography.
The process is divided into several step for encryption and decryption in matlab.

Lets start DES using MATLAB

DES uses a 64 bit plain text(the main data to encrypt) and a 64 bit key..we will provide string of characters of length 8(characters) as input for both plain text and key.
So,the first step is to take 8 character input and convert it into its binary form and of course our input plain text need not be of only 8 characters however we can bound the key to have only 8 characters. In that case if the plain text is a sentence or greater or less than 8 characters , we have to make it of 8 character by breaking it and adding 'space' at the end if it is less than 8 characters.

FIRST STEP :
1. sentencebreak(text)

sentencebreak
  This program will create a function used for dividing a sentence in equal parts of length 8( characters). It is for the plain text only.




2.iniplntext(tt)
3.inikey(key)
Now our second job is to code the 8 charcters into binary of 64 bits .. that is each character to 8-bit
and also it is permuted i.e. the position of bits are changed according to a permutation table used in
iniplntxt
program.

The input here is taken a 8 character word and the output is permuted 64 bits array.


The same is done with the key also but the difference is only the permutation table and the output which is only 56 bits.  

full prorgam
-->
Here is the final program where different functions are used which are not in matlab but we have to create
those are
1. sentencebreak(text);
2. iniplntxt(tt);
3. inikey(key)
4. keygenerate(c0,d0,i)
5. roundmy(l,r,kr)
6. dekeygenerate(c0,d0,i)
7. deroundmy(l,r,kr)

The top most three functions are already discussed above and rest will be discussed... after that we will see
the result obtained after simulation of this program....(note that the names of function are just my thinking , you can use any name for that)

4.keygenerate(c0,d0,i)
   Here c0 and d0 are nothing but the left half bits and right half bits resp. of the 56 bit key obtained by
keygenerate
    permutation...

In DES we require 16 different keys which are generated by the key provided by us..
Now if we provide 'i' = 4, then we will get the 4th round key



roundmy 

5. roundmy(l,r,kr)
Here is the same as c0 and d0..' l 'and 'r' gives the left and right half of the 64 bits plain text i.e each of 32 bits.
And 'kr' is the output of 'keygenerate' function which is also of 48 bits.

Here a new function 'cipher(r,kr)' is used which will be expalined below...(next)




.....to be continued....