Is Lab Manual

24
INFORMATION SECURITY Laboratory Manual INFORMATION SYSTEM Semester: VI

description

Anna University 6 semester

Transcript of Is Lab Manual

Page 1: Is Lab Manual

INFORMATION SECURITY

Laboratory Manual

INFORMATION SYSTEM

Semester: VI

Page 2: Is Lab Manual

INFORMATION SECURITY

PRACTICAL-LIST PRACTICAL-1

To implement Caesar Cipher Encryption - Decryption. PRACTICAL-2

To implement Mono-alphabetic Cipher Encryption - Decryption. PRACTICAL-3

To implement Hill Cipher Encryption .

PRACTICAL-4

To implement Poly-alphabetic Cipher (Vigener Cipher) Technique.

PRACTICAL-5

To implement Play-Fair Cipher Technique.

PRACTICAL-6

Write a program to implement Rail-Fence Encryption Technique

PRACTICAL-7

To implement S-DES algorithm for data encryption.

PRACTICAL-8

Write a program to implement RSA asymmetric (public key and private key)-

Encryption

PRACTICAL-9

Write a program to generate digital signature using Hash code.

PRACTICAL-10

Case Study on Kerberos.

LABWORK BEYOND CURRICULA

PRACTICAL-11

Study of MD5 hash function and implement the hash code using MD5

PRACTICAL-12

Study of SHA-1 hash function and implement the hash code using SHA-1

Page 3: Is Lab Manual

INFORMATION SECURITY

Sample Practical AIM: Implement Play Fair Cipher Encryption Procedure: By analyzing the problem I found required two basic steps for implementing the data

encryption using Play Fair cipher

1) Generate Key matrix

2) Encrypt the data using encryption rule and key matrix

1) Generating Key matrix

To Generate the key matrix take any random key of any length and form a 5X5 matrix.

Go on filling the rows of the matrix with the key characters ( if repeating character occurs

then ignore it). Fill the remaining matrix with alphabets from A to Z (except those

already occurred in the key).

For example for the key “monarchy” we have the matrix as follow

2) Encrypt the data using encryption rule and key matrix

To Encrypt the data take two characters at time from plain text file and encrypt it using

one of the following rules.

Encryption rules

1) Repeating plain text letters that would fall in the same pair are separated with filler

letter, such as x.( i.e. Balloon becomes Ba, lx, lo, on)

2) If both the characters are in the same raw then replace each with the character to its

right, with the last character followed by the first, in the matrix.

3) If both the characters are in the same column then replace each with the character

below it, with the bottom character followed by the top, in the matrix.

4) Otherwise each plain text letter is replaced by the letter that lies in its own row and the

column occupied by the other plain text letter

Example:

Using key as “monarchy” we have

- Encryption of AR as RM

- Encryption of MU as CM

- Encryption of BP as IM

3.2 Designing the Solution:

Solution implementation is given below:-

For this solution we have to implement the following functions given below.

1) Input function for key & Plain Text.

2) Matrix generation.

3) Encryption function for generating Cipher Text.

4) Print function for printing Cipher Text Output.

Page 4: Is Lab Manual

INFORMATION SECURITY

Source Code

//**************************************

// Play Fair Cipher Encryption

import java.awt.*;

import java.awt.event.*;

import java.lang.*;

import java.applet.Applet;

/*

<applet code="PlayFair" width=500 height=150>

</applet>

*/

public class PlayFair extends Applet implements ActionListener

{

Label lb[]=new Label[3];

TextField txt1,txt2,txtkey;

Button b1;

char arrayplaintext[],arraycipher[];

String strcipher,strplain,key;

char matrix[][]=new char[5][5];

int row=0,col=0;

public void init()

{

setBackground(new Color(250,240,250));

setLayout(null);

lb[0]=new Label("Enter the message to be encrypetd");

lb[1]=new Label("This is the encrypetd message");

lb[2]=new Label("Enter the key");

txt1=new TextField("");

txtkey=new TextField("");

txt2=new TextField("");

b1=new Button("encrypt");

b1.addActionListener(this);

add(lb[0]);

add(lb[1]);

add(lb[2]);

add(txt1);

add(b1);

add(txt2);

add(txtkey);

lb[0].setBounds(10,10,200,20);

lb[2].setBounds(10,40,200,20);

lb[1].setBounds(10,70,200,20);

txt1.setBounds(300,10,200,20);

txt2.setBounds(300,40,200,20);

txtkey.setBounds(300,70,200,20);

Page 5: Is Lab Manual

INFORMATION SECURITY

b1.setBounds(200,100,100,20);

}

public void paint(Graphics g) { }

public void actionPerformed(ActionEvent a)

{

strplain=txt1.getText();

key=txtkey.getText();

arrayplaintext=strplain.toCharArray();

encrypt();

}

public void encrypt()

{

create_matrix(key);

do_encryption();

}

public void do_encryption()

{

int i=0,j=1,row_1=0,col_1=0,row_2=0,col_2=0,a,b;

char cur_1,cur_2;

arrayplaintext=strplain.toUpperCase().toCharArray();

arraycipher=new char[strplain.length()];

for(i=0;i<(strplain.length()-1); )

{

cur_1=arrayplaintext[i];

cur_2=arrayplaintext[j];

if(cur_1=='j')

cur_1='i';

if(cur_2=='j')

cur_2='i';

for(a=0;a<=4;a++)

{

for(b=0;b<=4;b++)

{

if(matrix[a][b]==cur_1)

{

row_1=a;

col_1=b;

}

if(matrix[a][b]==cur_2)

{

row_2=a;

col_2=b;

Page 6: Is Lab Manual

INFORMATION SECURITY

}

} }

if(row_1==row_2)

{

arraycipher[i]=matrix[row_1][(col_1+1)%5];

arraycipher[j]=matrix[row_2][(col_2+1)%5];

}

else if(col_1==col_2)

{

arraycipher[i]=matrix[(row_1+1)%5][col_1];

arraycipher[j]=matrix[(row_2+1)%5][col_2];

}

else

{

arraycipher[i]=matrix[row_1][col_2];

arraycipher[j]=matrix[row_2][col_1];

}

i=i+2;

j=j+2;

}

strcipher=new String(arraycipher);

txtkey.setText(strcipher);

}

public void create_matrix(String key)

{

key=key.toUpperCase();

char key_array[]=key.toCharArray();

int i=0,j;

boolean flag=true;

for(i=0;i<key.length();i++)

{

flag=true;

for(j=0;j<i;j++)

{

if(key_array[i]==key_array[j])

flag=false;

}

if(flag==true)

{

matrix[row][col]=key_array[i];

col++;

if(col==5)

{

row=row+1;

col=0;

Page 7: Is Lab Manual

INFORMATION SECURITY

} }

}

for(i=0;i<26;i++)

{

flag=true;

for(j=0;j<key.length();j++)

{

if((int)key_array[j]==i+65)

{

flag=false;

}

}

if(flag==true && i!=9)

{

matrix[row][col]=(char)(i+65);

col++;

if(col==5)

col=0;

if(row<4)

row=row+1;

}

}

}

}

OUTPUT:-

Page 8: Is Lab Manual

INFORMATION SECURITY

Compilation /Running and Debugging the Solution

- Open the file Playfair.java.

- Compile using javac.

- Run using java filename

Testing the Solution

By testing the program we get the following output.

Conclusions

By this PRACTICAL; we can conclude that basic working of play fair cipher encryption

methodology is working properly.

Page 9: Is Lab Manual

INFORMATION SECURITY

PRACTICAL NO : 1

AIM: To implement Caesar Cipher Encryption - Decryption.

THEORY:

In cryptography, a Caesar cipher, also known as a Caesar's cipher, the shift cipher,

Caesar's code or Caesar shift, is one of the simplest and most widely known encryption

techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a

letter some fixed number of positions down the alphabet. For example, with a shift of 3, A would

be replaced by D, B would become E, and so on. The method is named after Julius Caesar, who

used it to communicate with his generals. If anyone wishes to decipher these, and get at their

meaning, he must substitute the fourth letter of the alphabet, namely D, for A, and so with the

others.

The action of a Caesar cipher is to replace each plaintext letter with one fixed number of places

down the alphabet. This example is with a shift of three, so that a B in the plaintext becomes E in

the ciphertext.

Plain: ABCDEFGHIJKLMNOPQRSTUVWXYZ

Cipher: DEFGHIJKLMNOPQRSTUVWXYZABC

Ciphertext: WKH TXLFN EURZQ IRA MXPSV RYHU WKH ODCB GRJ

Plaintext: the quick brown fox jumps over the lazy dog

The encryption can also be represented using modular arithmetic by first transforming the letters

into numbers, according to the scheme, A = 0, B = 1,..., Z = 25.[1]

Encryption of a letter x by a

shift n can be described mathematically as,[2]

Decryption is performed similarly,

Page 10: Is Lab Manual

INFORMATION SECURITY

PRACTICAL NO : 2

AIM: To implement Monoalphabetic Cipher Encryption.

THEORY:

The ciphers in this substitution section replace each letter with another letter according to the

cipher alphabet. Ciphers in which the cipher alphabet remains unchanged throughout the

message are called Monoalphabetic Substitution Ciphers.

If we permit the cipher alphabet to be any rearrangement of the plain alphabet, then we can

generate an enormous number of distinct modes of encryption. There are over

400,000,000,000,000,000,000,000,000 such rearrangements, which gives rise to an equivalent

number of distinct cipher alphabets. Each cipher alphabet is known as a key.

Start by creating a key that maps each letter of the alphabet to a (possibly the same) letter of

the alphabet. A sample key might be:

Plaintext letter a b c d e f g h i j k l m n o p q r s t u v w x y z

Ciphertext letter y n l k x b s h m i w d p j r o q v f e a u g t z c

To encrypt the message "meet me at nine", start by taking the first letter of the message, 'm', and

look up the corresponding ciphertext letter 'p'. Repeat by looking up the next plaintext letter 'e',

and noting it becomes 'x'. Continue this process for the rest of the message. Typically spaces,

numbers, and punctuation are left alone. In this case "meet me at nine." would become "pxxe px

ye jmjx."

Decryption is similar. Start with the first ciphertext letter 'p', and look at the table to find the

corresponding plaintext letter 'm'. Continue with the next letter 'x', and find it maps to 'e.

Page 11: Is Lab Manual

INFORMATION SECURITY

Page 12: Is Lab Manual

INFORMATION SECURITY

PRACTICAL NO : 3

AIM: To implement Hill Cipher Encryption.

THEORY:

In classical cryptography, the Hill cipher is a polygraphic substitution cipher based on linear

algebra. Invented by Lester S. Hill in 1929.

A block of n letters is then considered as a vector of n dimensions, and multiplied by an n × n

matrix, modulo 26. (If one uses a larger number than 26 for the modular base, then a different

number scheme can be used to encode the letters, and spaces or punctuation can also be used.)

The whole matrix is considered the cipher key, and should be random provided that the matrix is

invertible in (to ensure decryption is possible). A Hill cipher is another way of working out

the equation of a matrix.

Consider the message 'ACT', and the key below (or GYBNQKURP in letters):

Since 'A' is 0, 'C' is 2 and 'T' is 19, the message is the vector:

Thus the enciphered vector is given by:

which corresponds to a ciphertext of 'POH'. Now, suppose that our message is instead 'CAT', or:

This time, the enciphered vector is given by:

Page 13: Is Lab Manual

INFORMATION SECURITY

which corresponds to a ciphertext of 'FIN'. Every letter has changed. The Hill cipher has

achieved Shannon's diffusion, and an n-dimensional Hill cipher can diffuse fully across n

symbols at once.

Decryption

In order to decrypt, we turn the ciphertext back into a vector, then simply multiply by the inverse

matrix of the key matrix (IFKVIVVMI in letters). (There are standard methods to calculate the

inverse matrix; see matrix inversion for details.) We find that in the inverse matrix of the

one in the previous example is:

Taking the previous example ciphertext of 'POH', we get:

which gets us back to 'ACT', just as we hoped.

For our example key matrix:

So, modulo 26, the determinant is 25. Since this has no common factors with 26, this matrix can

be used for the Hill cipher.

The risk of the determinant having common factors with the modulus can be eliminated by

making the modulus prime. Consequently a useful variant of the Hill cipher adds 3 extra symbols

(such as a space, a period and a question mark) to increase the modulus to 29.

Page 14: Is Lab Manual

INFORMATION SECURITY

Page 15: Is Lab Manual

INFORMATION SECURITY

PRACTICAL NO : 4 AIM: To implement Polyalphabetic Cipher Encryption.

THEORY:

A polyalphabetic cipher is any cipher based on substitution, using multiple substitution

alphabets. The Vigenère cipher is probably the best-known example of a polyalphabetic cipher,

though it is a simplified special case.

In a polyalphabetic cipher, multiple cipher alphabets are used. To facilitate encryption, all the

alphabets are usually written out in a large table, traditionally called a tableau. The tableau is

usually 26×26, so that 26 full ciphertext alphabets are available. The method of filling the

tableau, and of choosing which alphabet to use next, defines the particular polyalphabetic cipher.

The Polyalphabetic Cipher (often referred to as a Vigenère) uses a KEY which determines which

letter in a cipher alphabet is used to create the ciphertext message. Normally, the cipher alphabet

is 26 letters arranged alphabetically (a-z). This program can use a cipher alphabet of up to 39

characters and they can be arranged in any sequence desired. There is no limit to the number of

characters in the KEY. It also allows a ‘codemaker’ to create a polyalphabetic cipher system of

his own design and has a crib dragging function for cracking polyalphabetic ciphertext. The

PolyAlphabetic Crypto Program is extremely flexible and a very useful crypto tool.

Page 16: Is Lab Manual

INFORMATION SECURITY

Below is the Vigenere table.

Page 17: Is Lab Manual

INFORMATION SECURITY

PRACTICAL NO : 5

AIM: To implement Play-Fair Cipher Encryption.

THEORY:

The Playfair cipher or Playfair square is a manual symmetric encryption technique and was

the first literal digraph substitution cipher. The scheme was invented in 1854 by Charles

Wheatstone, but bears the name of Lord Playfair who promoted the use of the cipher.

The Playfair cipher uses a 5 by 5 table containing a key word or phrase. Memorization of the

keyword and 4 simple rules was all that was required to create the 5 by 5 table and use the

cipher.

To generate the key table, one would first fill in the spaces in the table with the letters of the

keyword (dropping any duplicate letters), then fill the remaining spaces with the rest of the

letters of the alphabet in order (usually omitting "Q" to reduce the alphabet to fit, other versions

put both "I" and "J" in the same space). The key can be written in the top rows of the table, from

left to right, or in some other pattern, such as a spiral beginning in the upper-left-hand corner and

ending in the center. The keyword together with the conventions for filling in the 5 by 5 table

constitute the cipher key.

Plaintext is encrypted two letters at a time, according to the following rules:

1. If both letters are the same (or only one letter is left), add an "X" after the first letter.

Encrypt the new pair and continue. Some variants of Playfair use "Q" instead of "X", but

any uncommon monograph will do.

2. If the letters appear on the same row of your table, replace them with the letters to their

immediate right respectively (wrapping around to the left side of the row if a letter in the

original pair was on the right side of the row).

3. If the letters appear on the same column of your table, replace them with the letters

immediately below respectively (wrapping around to the top side of the column if a letter

in the original pair was on the bottom side of the column).

4. If the letters are not on the same row or column, replace them with the letters on the same

row respectively but at the other pair of corners of the rectangle defined by the original

pair. The order is important – the first letter of the encrypted pair is the one that lies on

the same row as the first letter of the plaintext pair.

Example

Using "playfair example" as the key, (assuming I and J are interchangeable) the table becomes:

Page 18: Is Lab Manual

INFORMATION SECURITY

Encrypting the message "Hide the gold in the tree stump":

HI DE TH EG OL DI NT HE TR EX ES TU MP

1. The pair HI forms a rectangle, replace it with BM

The pair DE is in a column, replace it with OD

The pair TH forms a rectangle, replace it with ZB

The pair EG forms a rectangle,replace it with

XD

The pair OL forms a rectangle, replace it with

NA

The pair DI forms a rectangle, replace it with

BE

Page 19: Is Lab Manual

INFORMATION SECURITY

The pair NT forms a rectangle, replace it with U

The pair HE forms a rectangle,replace it withDM

The pair TR forms a rectangle, replace it with UI

The pair EX (X inserted to split EE) is in a row,

replace it with XM

The pair ES forms a rectangle, replace it with MO

The pair TU is in a row, replace it with UV

The pair MP forms a rectangle, replace it with IF

BM OD ZB XD NA BE KU DM UI XM MO UV IF

Thus the message "Hide the gold in the tree stump" becomes

"BMODZBXDNABEKUDMUIXMMOUVIF".

Page 20: Is Lab Manual

INFORMATION SECURITY

PRACTICAL NO : 6

AIM: Write a program to implement Rail-Fence Encryption Technique.

THEORY:

In cryptography, a transposition cipher is a method of encryption by which the positions held

by units of plaintext (which are commonly characters or groups of characters) are shifted

according to a regular system, so that the ciphertext constitutes a permutation of the plaintext.

That is, the order of the units is changed. Mathematically a bijective function is used on the

characters' positions to encrypt and an inverse function to decrypt.

Page 21: Is Lab Manual

INFORMATION SECURITY

PRACTICAL NO : 7 AIM: To implement S-DES algorithm for data encryption.

Page 22: Is Lab Manual

INFORMATION SECURITY

Page 23: Is Lab Manual

INFORMATION SECURITY

PRACTICAL NO : 8 AIM: To implement RSA asymmetric (public key and private key)-Encryption

Page 24: Is Lab Manual

INFORMATION SECURITY

PRACTICAL NO : 9

AIM: Generate Digital Signature