Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
LAB MATERIAL
CS6711 SECURITY LABORATORY
Prepared By
M.AZHAGIRI & P.KRISHNAMOORTHY
Assistant Professor
Department of Computer Science Engineering
Kingston Engineering College
2016
CS6711
SECURITY LABORATORY
LTPC
0032
LIST OF EXPERIMENTS:
1. Implement the following SUBSTITUTION & TRANSPOSITION TECHNIQUES
concepts:
a) Caesar Cipher
b) Playfair Cipher
c) Hill Cipher
d) Vigenere Cipher
e) Rail fence row & Column Transformation
2. Implement the following algorithms
a) DES
b) RSA Algorithm
c) Diffiee-Hellman
d) MD5
e) SHA-1
3. Implement the SIGNATURE SCHEME - Digital Signature Standard
4. Demonstrate how to provide secure data storage, secure data transmission and for creating
digital signatures (GnuPG).
5. Setup a honey pot and monitor the honeypot on network (KF Sensor)
6. Installation of root kits and study about the variety of options
7. Perform wireless audit on an access point or a router and decrypt WEP and WPA.( Net
Stumbler)
8. Demonstrate intrusion detection system (ids) using any tool (snort or any other s/w)
TOTAL: 45 PERIODS
OUTCOMES: At the end of the course, the student should be able to
Implement the cipher techniques
Develop the various security algorithms
Use different open source tools for network security and analysis
LIST OF EQUIPMENT FOR A BATCH OF 30 STUDENTS:
SOFTWARE: C / C++ / Java or equivalent compiler GnuPG, KF Sensor or Equivalent,
Snort, Net Stumbler or Equivalent
HARDWARE: Standalone desktops - 30 Nos. (or) Server supporting 30 terminals or more.
LIST OF EXPERIMENTS
1. Write a program to implement the Caesar Cipher
2. Write a program to implement the Playfair Cipher
3. Write a program to implement the Hill Cipher
4. Write a program to implement the Vigenere Cipher
5. Write a program to implement the Rail fence row & Column Transformation
6. Write a program to implement the DES algorithms
7. Write a program to implement the RSA Algorithm
8. Write a program to implement the Diffiee-Hellman algorithms
9. Write a program to implement the MD5 algorithms
10. Write a program to implement the SHA-1 algorithms
11. Implement the SIGNATURE SCHEME Digital Signature Standard
12. Demonstrate how to provide secure data storage, secure data transmission and for
creating digital signatures Using GnuPG.
13. Setup a honey pot and monitor the honeypot on network using KF Sensor
14. Installation of root kits and study about the variety of options
15. Perform wireless audit on an access point or a router and decrypt WEP and WPA
using Net Stumbler
16. Demonstrate intrusion detection system (ids) using any tool using snort
Ex.No: 1
AIM
To write a Java Program for implementing Caesar Cipher.
ALGORITHM
Step 1: Start the program.
Step 2: Define a class Caesar Cipher.
Step 3: Declare a string ALPHABET.
Step 4: Define a function encrypt () to produce a cipher text and decrypt () to
reproduce the plain text.
Step 5: Define a main (), get the string and call encrypt() to encrypt the string and
decrypt() to reproduce the plain text and display it.
Step 6: Stop the program.
PROGRAM //file name CeaserCipher.java
import java.util.*;
class basic{
String allChar="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int indexOfChar(char c)
{
for(int i=0;i< allChar.length();i++)
{
if(allChar.charAt(i)==c)
return i;
}
return -1;
}
char charAtIndex(int pos)
{
return allChar.charAt(pos);
}
}
class Ceaser{
basic b=new basic();
String Encrypt(String plainText,int key)
{
plainText=plainText.toUpperCase();
String cipherText=" ";
for(int i=0;i< plainText.length();i++)
{
int index=b.indexOfChar(plainText.charAt(i));
if(index==-1)
{
cipherText+=plainText.charAt(i);
continue;
}
if((index+key)%26==0)
{
cipherText+=b.charAtIndex(index+key);
}
else
{
cipherText+=b.charAtIndex((index+key)%26);
}
}
return cipherText;
}
String Decrypt(String cipherText,int key)
{
cipherText=cipherText.toUpperCase();
String decryptedText="";
for(int i=0;i< cipherText.length();i++)
{
int index=b.indexOfChar(cipherText.charAt(i));
if(index==-1)
{
decryptedText+=cipherText.charAt(i);
continue;
}
if((index-key)>=0)
{
decryptedText+=b.charAtIndex(index-key);
}
else
{
decryptedText+=b.charAtIndex((index-key)+26);
} }
return decryptedText;
}
void bruteForce(String cipherText)
{
cipherText=cipherText.toUpperCase();
for(int k=0;k< 26;k++)
{
String decryptedText="";
int key=k;
for(int i=0;i< cipherText.length();i++)
{
int index=b.indexOfChar(cipherText.charAt(i));
if(index==-1)
{
decryptedText+=cipherText.charAt(i);
continue;
}
if((index-key)>=0)
{
decryptedText+=b.charAtIndex(index-key);
}
else
{
decryptedText+=b.charAtIndex((index-key)+26);
}
} }}
class CeaserCipher{
public static void main(String args[])throws Exception
{
Scanner scn=new Scanner(System.in);
String plainText,cipherText;
int key;
System.out.println("Enter Plaintext message:");
plainText=scn.nextLine();
System.out.println("Enter key for Encryption:");
key=scn.nextInt();
Ceaser cipher=new Ceaser();
cipherText=cipher.Encrypt(plainText,key);
System.out.println("Encrypted Ciphertext is:"+cipherText);
String decryptedText=cipher.Decrypt(cipherText,key);
System.out.println("Decrypted Ciphertext is:"+decryptedText);
System.out.println("Do you want to apply brute force on Ciphertext ?press 1 otherwise press
anykey");
int choice=scn.nextInt();
if(choice==1)
cipher.bruteForce(cipherText);
}
}
OUTPUT
Enter Plaintext message:
HELLO
Enter key for Encryption: 5
Encrypted Ciphertext is: MJQQT
Decrypted Ciphertext is: HELLO
Do you want to apply brute force on Ciphertext ? press 1 otherwise press any key: 1
RESULT
Thus java program to implement Caesar Cipher was written, executed and output is verified
successfully.
Ex.No: 2
AIM
To write a Java program for implementing Playfair Cipher.
ALGORITHM
Step 1: Start the program.
Step 2: Define a class Basic to find the index of a char.
Step 3: Define a class PlayFair to define the key matrix, find the row position, column
position, encrypt the text and decrypt the text.
Step 4: Define a class PlayFairCipher, to get the plain text and then to encrypt and
decrypt the text.
Step 5: Display the encrypted text and decrypted text.
Step 6: Stop the program.
import java.util.*;
class Basic{
String allChar="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
boolean indexOfChar(char c)
{
for(int i=0;i < allChar.length();i++)
{
if(allChar.charAt(i)==c)
return true;
}
return false;
}
}
class PlayFair{
Basic b=new Basic();
char keyMatrix[][]=new char[5][5];
boolean repeat(char c)
{
if(!b.indexOfChar(c))
{
return true;
}
for(int i=0;i < keyMatrix.length;i++)
{
for(int j=0;j < keyMatrix[i].length;j++)
{
if(keyMatrix[i][j]==c || c=='J')
return true;
}
}
return false;
}
void insertKey(String key)
{
key=key.toUpperCase();
key=key.replaceAll("J", "I");
key=key.replaceAll(" ", "");
int a=0,b=0;
for(int k=0;k < key.length();k++)
{
if(!repeat(key.charAt(k)))
{
keyMatrix[a][b++]=key.charAt(k);
if(b>4)
{
b=0;
a++;
}
}
}
char p='A';
while(a < 5)
{
while(b < 5)
{
if(!repeat(p))
{
keyMatrix[a][b++]=p;
}
p++;
}
b=0;
a++;
}
System.out.print("-------------------------Key Matrix-------------------");
for(int i=0;i < 5;i++)
{
System.out.println();
for(int j=0;j < 5;j++)
{
System.out.print("\t"+keyMatrix[i][j]);
}
}
System.out.println("\n---------------------------------------------------------");
}
int rowPos(char c)
{
for(int i=0;i < keyMatrix.length;i++)
{
for(int j=0;j < keyMatrix[i].length;j++)
{
if(keyMatrix[i][j]==c)
return i;
}
}
return -1;
}
int columnPos(char c)
{
for(int i=0;i < keyMatrix.length;i++)
{
for(int j=0;j < keyMatrix[i].length;j++)
{
if(keyMatrix[i][j]==c)
return j;
}
}
return -1;
}
}
else if(r1==r2)
{
++c1;
++c2;
if(c1>4)
c1=0;
if(c2>4)
c2=0;
cipherChar+=keyMatrix[r1][c1];
cipherChar+=keyMatrix[r2][c2];
}
else{
cipherChar+=keyMatrix[r1][c2];
cipherChar+=keyMatrix[r2][c1];
}
return cipherChar;
}
String Encrypt(String plainText,String key)
{
insertKey(key);
String cipherText="";
plainText=plainText.replaceAll("j", "i");
plainText=plainText.replaceAll(" ", "");
plainText=plainText.toUpperCase();
int len=plainText.length();
// System.out.println(plainText.substring(1,2+1));
if(len/2!=0)
{
plainText+="X";
++len;
}
for(int i=0;i < len-1;i=i+2)
{
cipherText+=encryptChar(plainText.substring(i,i+2));
cipherText+=" ";
}
return cipherText;
}
String decryptChar(String cipher)
{
cipher=cipher.toUpperCase();
char a=cipher.charAt(0),b=cipher.charAt(1);
String plainChar="";
int r1,c1,r2,c2;
r1=rowPos(a);
c1=columnPos(a);
r2=rowPos(b);
c2=columnPos(b);
if(c1==c2)
{
--r1;
--r2;
if(r1 < 0)
r1=4;
if(r2 < 0)
r2=4;
plainChar+=keyMatrix[r1][c2];
plainChar+=keyMatrix[r2][c1];
}
else if(r1==r2)
{
--c1;
--c2;
if(c1 < 0)
c1=4;
if(c2 < 0)
c2=4;
plainChar+=keyMatrix[r1][c1];
plainChar+=keyMatrix[r2][c2];
}
else{
plainChar+=keyMatrix[r1][c2];
plainChar+=keyMatrix[r2][c1];
}
return plainChar;
}
String Decrypt(String cipherText,String key)
{
String plainText="";
cipherText=cipherText.replaceAll("j", "i");
cipherText=cipherText.replaceAll(" ", "");
cipherText=cipherText.toUpperCase();
int len=cipherText.length();
for(int i=0;i < len-1;i=i+2)
{
plainText+=decryptChar(cipherText.substring(i,i+2));
plainText+=" ";
}
return plainText;
}
}
class PlayFairCipher{
public static void main(String args[])throws Exception
{
PlayFair p=new PlayFair();
Scanner scn=new Scanner(System.in);
String key,cipherText,plainText;
System.out.println("Enter plaintext:");
plainText=scn.nextLine();
System.out.println("Enter Key:");
key=scn.nextLine();
cipherText=p.Encrypt(plainText,key);
System.out.println("Encrypted text:");
System.out.println("---------------------------\n"+cipherText);
System.out.println("-------------------------------");
String encryptedText=p.Decrypt(cipherText, key);
System.out.println("Decrypted text:" );
System.out.println("------------------------\n"+encryptedText);
System.out.println("----------------------");
}
}
OUTPUT
Enter plaintext:
PLAYCIPHERISONEOFGOODCIPHER
Enter Key:
SECRETKEY
-------------------------Key Matrix------------------S
T
D
L
--------------------------------------------------------Encrypted text:
--------------------------------------------------------QI BA RH OI CT FR PO CN GH WW AT PX GC BR
--------------------------------------------------------Decrypted text:
--------------------------------------------------------PL AY CI PH ER IS ON EO FG OO DC IP HE RX
---------------------------------------------------------
RESULT
Thus java program to implement PlayFair Cipher was written, executed and output is verified
successfully.
Ex.No: 3
AIM:
To write a Java Program for implementing Hill Cipher.
ALGORITHM
Step 1: Start the program.
Step 2: Define a class HillCipher, in that declare 2 array one for key, other for inverse
key and define a string key.
Step 3: In this class, define a main(), get the choice to encrypt or decrypt.
Step 4: Based on the choice call encrypt() and decrypt() to find cipher and plain text.
Step 5: Display the result.
Step 6: Stop the program.
// File name:HillCipher.java
import java.util.*;
class Basic{
String allChar="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int indexOfChar(char c)
{
for(int i=0;i < allChar.length();i++)
{
if(allChar.charAt(i)==c)
return i;
}
return -1;
}
char charAtIndex(int pos)
{
return allChar.charAt(pos);
}
}
class Hill{
Hill(int block)
{
this.block=block;
}
Basic b1=new Basic();
int block=2;
int key[][]=new int[block][block];
void keyInsert()throws Exception
{
Scanner scn=new Scanner(System.in);
System.out.println("Enter key Matrix");
for(int i=0;i < block;i++)
{
for(int j=0;j < block;j++)
{
key[i][j]=scn.nextInt();
}
}
}
void KeyInverseInsert()throws Exception
{
Scanner scn=new Scanner(System.in);
System.out.println("Enter key Inverse Matrix:");
for(int i=0;i < block;i++)
{
for(int j=0;j < block;j++)
{
key[i][j]=scn.nextInt();
}
}
}
String encryptBlock(String plain)throws Exception
{
plain=plain.toUpperCase();
plainText+="X";
System.out.println(len);
len=plainText.length();
}
for(int i=0;i < len-1;i=i+block)
{
cipherText+=encryptBlock(plainText.substring(i,i+block));
cipherText+=" ";
}
return cipherText;
}
String decryptBlock(String cipher)throws Exception
{
cipher=cipher.toUpperCase();
int a[][]=new int[block][1],sum=0;
int plainMatrix[][]=new int[block][1];
String plain="";
for(int i=0;i < block;i++)
{
a[i][0]=b1.indexOfChar(cipher.charAt(i));
}
for(int i=0;i < block;i++)
{
for(int j=0;j < 1;j++)
{
for(int k=0;k < block;k++)
{
sum=sum+key[i][k]*a[k][j];
}
while(sum < 0)
{
sum+=26;
}
plainMatrix[i][j] = sum;
sum = 0;
}
}
for(int i=0;i < block;i++)
{
plain+=b1.charAtIndex(plainMatrix[i][0]);
}
return plain;
}
String Decrypt(String cipherText)throws Exception
{
String plainText="";
KeyInverseInsert();
cipherText=cipherText.replaceAll(" ", "");
cipherText=cipherText.toUpperCase();
int len=cipherText.length();
for(int i=0;i < len-1;i=i+block)
{
plainText+=decryptBlock(cipherText.substring(i,i+block));
plainText+=" ";
}
return plainText;
}
}
class HillCipher{
public static void main(String args[])throws Exception
{
String plainText,cipherText;
int block;
Scanner scn=new Scanner(System.in);
System.out.println("Enter plain-text:");
plainText=scn.nextLine();
System.out.println("Enter block size of matrix:");
block=scn.nextInt();
RESULT
Thus java program to implement Hill Cipher was written, executed and output is verified
successfully.
Ex.No: 4
AIM
To write a Java Program for implementing Vigenere Cipher.
ALGORITHM
Step 1: Start the program.
Step 2: Define a class VC1, in that define encipher() to produce a cipher text.
Step 3: Define decipher() to reproduce the plain text.
Step 4: Define a shift() to shift the values.
Step 5: In main(), define the text and key values and call the encipher() to encrypt and
decipher() to decrypt the encrypted text.
Step 6: Display the results.
Step 7: Stop the program.
vigenerecipher
import java.io.*;
public class vigenerecipher
{
public String encrypt(String keyword, String line)
{
String result=" ";
int offset;
int j=0,shift;
for(int i=0;i<line.length();i++)
{
shift=((int)keyword.charAt(j))-97;
j++;
j%=keyword.length();
offset=((int)line.charAt(i)+shift)%256;
result+=(char)(offset);
}
return result;
}
public String decrypt(String keyword, String line)
{
String result="";
int offset;
int j=0,shift;
for(int i=0;i<line.length();i++)
{
shift=((int)keyword.charAt(j))-97;
j++;
j%=keyword.length();
offset=((int)line.charAt(i)-shift)%256;
if(offset<0)
offset+=256;
result+=(char)(offset);
}
return result;
}
public static void main(String args[])throws IOException
{
vigenerecipher obj=new vigenerecipher();
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
int choice;
System.out.println("Menu:\n1: Encryption\n2: Decryption");
choice=Integer.parseInt(in.readLine());
System.out.println("Enter the keyword: ");
String keyword=in.readLine();
System.out.println("Enter the line: ");
String line=in.readLine();
System.out.println("Result:");
switch(choice)
{
case 1:System.out.println(obj.encrypt(keyword,line));
break;
case 2:System.out.println(obj.decrypt(keyword,line));
break;
default:
System.out.println("Invalid input!");
break;
}
}
}
Output
Menu
1.Encryption
2.Decryption
1(Encryption)
Enter the Keyword : HELLO
Enter the Line Number:1
Result :8
2(Decryption)
Enter the Keyword : HELLO
Enter the Line Number:8
Result :1
RESULT
Thus java program to implement Vigenere Cipher was written, executed and output is
verified successfully.
Ex.No: 5
TRANSFORMATION
AIM
To write a Java Program for implementing Rail Fence Row & Column
Transformation.
ALGORITHM
Step 1: Start the program.
Step 2: Define a class railfencebasic, in that define Encryption() to produce cipher
text.
Step 3: Define Decryption() to produce decipher text.
Step 4: Define a class railfencecipher, in that define main() and input the text to cipher
and decipher it.
Step 5: Display the results.
Step 6: Stop the program.
mat[j][i]='X';
}
}
for(int i=0;i< r;i++)
{
for(int j=0;j< c;j++)
{
cipherText+=mat[i][j];
}
}
return cipherText;
}
String Decryption(String cipherText,int depth)throws Exception
{
int r=depth,len=cipherText.length();
int c=len/depth;
char mat[][]=new char[r][c];
int k=0;
String plainText="";
for(int i=0;i< r;i++)
{
for(int j=0;j< c;j++)
{
mat[i][j]=cipherText.charAt(k++);
}
}
for(int i=0;i< c;i++)
{
for(int j=0;j< r;j++)
{
plainText+=mat[j][i];
}
}
return plainText;
}
}
class RailFence{
public static void main(String args[])throws Exception
{
RailFenceBasic rf=new RailFenceBasic();
Scanner scn=new Scanner(System.in);
int depth;
String plainText,cipherText,decryptedText;
System.out.println("Enter plain text:");
plainText=scn.nextLine();
System.out.println("Enter depth for Encryption:");
depth=scn.nextInt();
cipherText=rf.Encryption(plainText,depth);
System.out.println("Encrypted text is:\n"+cipherText);
decryptedText=rf.Decryption(cipherText, depth);
System.out.println("Decrypted text is:\n"+decryptedText);
}
}
OUTPUT
Enter plain text:
railfencecipher
Enter depth for Encryption:
3
Encrypted text is:
rlnchafcieieepr
Decrypted text is:
railfencecipher
RESULT
Thus java program to implement Rail Fence Row & Column Transformation was written,
executed and output is verified successfully.
Ex.No:6
IMPLEMENTATION OF DES
AIM
To write a Java Program for implementing DES.
ALGORITHM
Step 1: Start the program.
Step 2: Define a class DES, in that define a constructor to display the encrypted and
decrypted message.
Step 3: Define generateSymmetricKey(), to generate the key.
Step 4: Define encrypt() to encrypt the plain text.
Step 5: Define decrypt() to decrypt the ciphered text.
Step 6: Define main() to declare object for the class.
Step 7: Stop the program.
PROGRAM /*DES.JAVA*/
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.security.spec.KeySpec;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESedeKeySpec;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class DES {
private static final String UNICODE_FORMAT = "UTF8";
public static final String DESEDE_ENCRYPTION_SCHEME = "DESede";
private KeySpec myKeySpec;
private SecretKeyFactory mySecretKeyFactory;
private Cipher cipher;
byte[] keyAsBytes;
private String myEncryptionKey;
private String myEncryptionScheme;
SecretKey key;
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
RESULT
Thus java program to implement DES was written, executed and output is verified
successfully.
Ex.No: 7
IMPLEMENTATION OF RSA
AIM
ALGORITHM
Step 1: Start the program.
Step 2: Define a default constructor RSA to compare 2 prime numbers.
Step 3: Define a parameterized constructor to assign values.
Step 4: Define bytetostring() to convert byte to string.
Step 5: Define encrypt() to encrypt the text and decrypt() to reproduce the plain text.
Step 6: Define main() to call the encrypt() and decrypt() to perform respective
operations and display the results.
Step 7: Stop the program.
PROGRAM: /*RSA.Java*/
import java.io.*;
import java.util.*;
class RSA
{
public static void main(String args[])
{
Scanner ip=new Scanner(System.in);
int p,q,n,e=1,j;
int d=1,i1;
int t1,t2;
int pt[]= new int[10];
int ct[]= new int[10];
int rt[]= new int[10];
String i=new String();
System.out.println("Enter the two prime numbers:");
p=ip.nextInt();
q=ip.nextInt();
System.out.println("Enter the message to be sent");
i=ip.next();
i1=i.length();
for(j=0;j<i1;j++)
{
pt[j]=(i.charAt(j))-96;
}
n=p*q;
t1=p-1;
t2=q-1;
while((t1*t2)%e==0)
{
e++;
}
for(j=0;j<i1;j++)
{
ct[j]=((int)Math.pow(pt[j],e))%n;
}
System.out.println("Sender Side:");
System.out.println("----------------------");
System.out.println("Public Key(e)= "+e);
for(j=0;j<i1;j++)
{
System.out.println("Cipher Text= "+ct[j]);
}
System.out.println("Receiver Side:");
System.out.println("----------------------");
while((d*e)%(t1*t2)!=1)
{
d++;
}
System.out.println("Private Key(d)= "+d);
for(j=0;j<i1;j++)
{
rt[j]=((int)Math.pow(ct[j],d))%n;
System.out.println("Plain Text= "+rt[j]);
}
System.out.print("Decrypted Message:");
for(j=0;j<i1;j++)
{
rt[j]=rt[j]+96;
System.out.print((char)rt[j]);
} }}
OUTPUT
Enter the Two prime numbers: 5
Ex.No:8
AIM
To write a Java Program for implementing Diffiee - Hellman.
ALGORITHM
Step 1: Start the program.
Step 2: Define class DiffeHellman BigInt, in that main() get the details and pass the
secret key.
Step 3: Enter prime number q
Step 4: Enter primitive root element
Step 5: Enter value for x and y for private key and calculate public key
Step 6: Calculate the keys and display it.
Step 7: Stop the program.
PROGRAM /* Diffie.java*/
import java.io.*;
import java.math.BigInteger;
class Diffie
{
public static void main(String[]args)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter prime number:");
BigInteger p=new BigInteger(br.readLine());
System.out.print("Enter primitive root of "+p+":");
BigInteger g=new BigInteger(br.readLine());
System.out.println("Enter value for x less than "+p+":");
BigInteger x=new BigInteger(br.readLine());
BigInteger R1=g.modPow(x,p);
System.out.println("R1="+R1);
System.out.print("Enter value for y less than "+p+":");
BigInteger y=new BigInteger(br.readLine());
BigInteger R2=g.modPow(y,p);
System.out.println("R2="+R2);
BigInteger k1=R2.modPow(x,p);
System.out.println("Key calculated at Alice's side:"+k1);
BigInteger k2=R1.modPow(y,p);
System.out.println("Key calculated at Bob's side:"+k2);
System.out.println("deffie hellman secret key Encryption has Taken");
}
}
OUTPUT
RESULT
Thus java program to implement Diffiee Hellman was written, executed and output is verified
successfully.
Ex.No: 9
IMPLEMENTATION OF MD5
AIM
To write a Java Program for implementing MD5.
ALGORITHM
Step 1: Start the program.
Step 2: Define a class JavaMD5Hash, in that define a function MD5 to find the hash
values of three different inputs.
Step 3: Display the hash values.
Step 4: Stop the program.
PROGRAM /*MD5.java*/
import java.security.*;
public class MD5 {
public static void main(String[] a) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
System.out.println("Message digest object info: ");
System.out.println(" Algorithm = " +md.getAlgorithm());
System.out.println(" Provider = " +md.getProvider());
System.out.println(" ToString = " +md.toString());
String input = "";
md.update(input.getBytes());
byte[] output = md.digest();
System.out.println();
System.out.println("MD5(\""+input+"\") = " +bytesToHex(output));
input = "abc";
md.update(input.getBytes());
output = md.digest();
System.out.println();
System.out.println("MD5(\""+input+"\") = " +bytesToHex(output));
input = "abcdefghijklmnopqrstuvwxyz";
md.update(input.getBytes());
output = md.digest();
System.out.println();
System.out.println("MD5(\"" +input+"\") = " +bytesToHex(output));
System.out.println("");
}
catch (Exception e) {
System.out.println("Exception: " +e); }
}
public static String bytesToHex(byte[] b) {
char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
StringBuffer buf = new StringBuffer();
for (int j=0; j<b.length; j++) {
buf.append(hexDigit[(b[j] >> 4) & 0x0f]);
buf.append(hexDigit[b[j] & 0x0f]); }
return buf.toString(); } }
OUTPUT:
MESSAGE DIGEST OBJECT INFO:
ALGORITHM = MD5
PROVIDER = SUN VERSION 1.8
TOSTRING= MD5 MESSAGE DIGEST FROM SUN<INITIALIZED>
MD5< > = D41D8CD98F00B204E9800998ECEF8427E
MD5<ABC> = 900150983CD24FB0D6963F7D28E17F72
MD5< ABCDEFGHIJKLMNOPQRSTUVWXYZ > =
C3FCDD76192E4007DFB496CCA67E13B
RESULT
Thus java program to implement MD5 was written, executed and output is verified
successfully.
Ex.No: 10
IMPLEMENTATION OF SHA-1
AIM
To write a Java Program for implementing SHA-1.
ALGORITHM
Step 1: Start the program.
Step 2: Define a class HashTextTest, in that main() call sha1() to display secured hash
value.
Step 3: Define sha1(), in that define the instances and generate the hash value.
Step 4: Stop the program.
PROGRAM /*SHA1.java*/
import java.security.*;
public class SHA1 {
public static void main(String[] a) {
try {
MessageDigest md = MessageDigest.getInstance("SHA1");
System.out.println("Message digest object info: ");
System.out.println(" Algorithm = " +md.getAlgorithm());
System.out.println(" Provider = " +md.getProvider());
System.out.println(" ToString = " +md.toString());
String input = "";
md.update(input.getBytes());
byte[] output = md.digest();
System.out.println();
System.out.println("SHA1(\""+input+"\") = " +bytesToHex(output));
input = "abc";
md.update(input.getBytes());
output = md.digest();
System.out.println();
System.out.println("SHA1(\""+input+"\") = " +bytesToHex(output));
input = "abcdefghijklmnopqrstuvwxyz";
md.update(input.getBytes());
output = md.digest();
System.out.println();
System.out.println("SHA1(\"" +input+"\") = " +bytesToHex(output));
System.out.println(""); }
catch (Exception e) {
System.out.println("Exception: " +e);
}
}
public static String bytesToHex(byte[] b) {
char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
StringBuffer buf = new StringBuffer();
for (int j=0; j<b.length; j++) {
buf.append(hexDigit[(b[j] >> 4) & 0x0f]);
buf.append(hexDigit[b[j] & 0x0f]); }
return buf.toString(); }
}
OUTPUT
ABCDEFGHIJKLMNOPQRSTUVWXYZ>=
32D10C7B8CF96570CA04CE37F2A19D84240D3A89
RESULT
Thus java program to implement SHA was written, executed and output is verified
successfully.
ALGORITHM
Step 1: Start the program.
Step 2: Define a class DSS, in that define a main().
Step 3: Create instance for KeypairGenerator class.
Step 4: Generate Key Pair using KeyPair Class.
Step 5: Send the data to encrypt and sign.
Step 6: Sign the data using Signature class.
Step 7: Display the signature and verification status.
Step 8: Stop the program.
PROGRAM /* DSAKeyGen.java*/
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
public class DSAKeyGen {
public static void main(String[] argv) throws Exception {
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
keyGen.initialize(1024);
KeyPair keypair = keyGen.genKeyPair();
PrivateKey privateKey = keypair.getPrivate();
System.out.println(privateKey);
PublicKey publicKey = keypair.getPublic();
System.out.println(publicKey);
}
}
OUTPUT
RESULT
Thus java program to implement Signature Scheme of Digital Signature Standard was
written, executed and output is verified successfully.
Ex.No: 12
AIM
To create Digital Signature, secure Data Storage & transmission using GnuPG.
PROCEDURE
GENERATING KEYPAIR
Step 1: Open up Kleopatra.
Step 2: Go to File, then New Certificate
Step 3: The Certificate Creation Wizard should pop up, click on Create a personal OpenPGP
key pair
Step 4: Now youll enter your details. Use your marketplace username as Name, and fill out
the rest with whatever you want. You dont need to use a real email. Check the picture for an
example on how it should look.
Step 5: Click Advanced Settings, and another window should appear. Under Key
Material, make sure RSA is checked. In the drop down menu beside it, and select 4,096
bits. Check the picture to confirm you have everything set correctly, then click Ok
Step 6: Confirm you filled out all of your info correctly, then click Create Key
Step 7: Another window will pop up asking to enter a passphrase. Do so, then click Ok
Step 8: It will now generate your key. It will need you to do random things to create entropy.
Mash keys, wiggle the mouse, watch porn, download torrents, whatever
Step 2: Browse where you want to save, give it a name, then click Save
Step 3: Open your favourite text editor, browse to where the file is saved. You may have to
select All files from the dropdown menu. Click the file you saved, then open
Step 2: Select where you want it saved, give it a name, check ASCII armor, and click Ok
Step 3: In your task bar, right click on the Kleopatra icon, go to Clipboard, then click
Certificate Import
Step 4: If it worked, you should see a window pop up, click Ok.
Step 2: Browse to where your private key is, select it, then click Open
Step 3: It will import your private key, and pop up a window to confirm. Click Ok
Step 4: You should now see your key information under the My Certificates tab
ENCRYPTING A MESSAGE
Step 1: Open up your text editor of choice.
Step 2: Type out your message, select it all, and copy it.
Step 3: In your task bar, right click on the Kleopatra icon, go to Clipboard, then click
Encrypt
Step 5: Another window will appear. Click the Other Certificates tab, then select who you
want to send your message to, then click Ok.
Step 6: You should be back at the previous window with the recipient listed. Click Next
Step 7: If all went well, you should see this window. Click Ok
Step 8: Your encrypted message will be in your clipboard, all you need to do is paste it into
the message box and send
DECRYPTING A MESSAGE
Step 2: In your task bar, right click on the Kleopatra icon, go to Clipboard, then click
Decrypt/Verify
Step 3: A window will pop up asking for your passphrase, enter that then click Ok.
RESULT
Thus creation of Digital Signature, secure data storage and transmission was done using
Kleopatra Tool using GnuPG was done and output is verified successfully.
Ex.No: 13
AIM
To setup a honey pot and monitor the honey pot on network using KF Sensor.
PROCEDURE
Honey Pot is a device placed on Computer Network specifically designed to capture
malicious network traffic.
KF Sensor is the tool to setup as honeypot when KF Sensor is running it places a siren icon in
the windows system tray in the bottom right of the screen. If there are no alerts then green
icon is displayed.
RESULT
Thus honey pot was set up and monitored on network using KF Sensor done successfully.
AIM
To install rootkits and study about the variety of options.
PROCEDURE
Rootkit is a stealth type of malicious software designed to hide the existence of certain
process from normal methods of detection and enables continued privileged access to a
computer.
Step 1: Download Rootkit Tool from GMER website. www.gmer.net
Step 2: This displays the Processes, Modules, Services, Files, Registry,
RootKit/Malwares, Autostart, CMD of local host.
Step 3: Select Processes menu and kill any unwanted process if any.
Step 4: Modules menu displays the various system files like .sys, .dll
Step 5: Services menu displays the complete services running with Autostart, Enable,
Disable, System, Boot.
Step 6: Files menu displays full files on Hard-Disk volumes.
Step 7: Registry displays Hkey_Current_user and Hkey_Local_Machine.
Step 8: Rootkits/Malawares scans the local drives selected.
Step 9: Autostart displays the registry base Autostart applications.
Step 10: CMD allows the user to interact with command line utilities or Registry.
RESULT
Thus Rootkit was installed and various options were studied successfully.
Ex.No:15
AIM
To perform wireless audit on an access point or a router and decrypt WEP and WPA using
Net Stumbler.
PROCEDURE
NetStumbler (Network Stumbler) is one of the Wi-Fi hacking tool which only compatible
with windows, this tool also a freeware. With this program, we can search for wireless
network which open and infiltrate the network. Its having some compatibility and network
adapter issues.
This will open the decryption key management window. As shown in the window you can
select between three decryption modes: None, Wire shark, and Driver:
RESULT
Thus wireless audit on an access point or a router was performed and decrypted WEP and
WPA using Net Stumbler done successfully.
Ex.No: 16
AIM
To demonstrate intrusion detection system (ids) using snort.
PROCEDURE
SNORT can be configured to run in three modes:
1. Sniffer mode
2. Packet Logger mode
3. Network Intrusion Detection System mode
Sniffer modesnort v Print out the TCP/IP packets header on the screen
Snort vd show the TCP/IP ICMP header with application data in transit.
Packet Logger modesnort dev l c:\log [create this directory in the C drive] and snort will
automatically know to go into packet logger mode, it collects every packet it sees and places
it in log directory. snort dev l c:\log h ipaddress/24 This rule tells snort that you want to
print out the data link and TCP/IP headers as well as application data into the log directory.
snort l c:\log b This is binary mode logs everything into a single file.
Network Intrusion Detection System modesnort d c:\log h ipaddress/24 c snort.conf This is a configuration file applies rule to each packet to decide it an action based upon the
rule type in the file. Snort d h ipaddress/24 l c:\log c snort.conf - This will configure
snort to run in its most basic NIDS form, logging packets that trigger rules specifies in the
snort.conf.
C:\Snort\bin>Snort - v
C:\Snort\bin>Snort vd
RESULT
Thus Intrusion Detection System was demonstrated using Snort tool successfully.
AIM
To implement Message Authentication Codes using Java.
ALGORITHM
Step 1: Start the program.
Step 2: Define a class SimpleMacExample, in that define GetPlainText() to get the
original text.
Step 3: Define main() to generate MAC code for the text.
Step 4: display the MAC code.
Step 5: Stop the program.
PROGRAM
package javaapplication1;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.crypto.*;
public class SimpleMacExample
{
public static String getPlainText()
{
System.out.print("Enter plaintext:");
String plaintext = "";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try
{
plaintext = br.readLine();
}
catch (IOException ioe)
{
System.out.println("IO error trying to read plaintext!");
System.exit(1);
}
// catch
return plaintext;
}
// getPlainText()
// if
// for i
System.out.println();
}
}
// main
// class SimpleMacExample
RESULT
Thus MAC was implemented using java and output is verified successfully.
IMPLMENTATION OF AES
ALGORITHM
Step 1: Start the program.
Step 2: Define a class AES, in that assign values to plaintext, IV and key variables.
Step 3: Define main() to display the encrypted and decrypted text of plain text.
Step 4: Define encrypt() to generated cipher text and decrypt() to generate plain text.
Step 5: Stop the program.
PROGRAM
package javaapplication1;
import java.security.MessageDigest;
import java.util.Arrays;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
RESULT
Thus AES was implemented using java and output is verified successfully.