0% found this document useful (0 votes)
943 views35 pages

Information Security Lab Manual

Uploaded by

sneha reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
943 views35 pages

Information Security Lab Manual

Uploaded by

sneha reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

LABORATORY MANUAL

INFORMATION SECURITY LAB

IV B. Tech I semester (2005PC68)

Prepared by
Dr. Smita Khond Dr. N. Baskar
Associate Professor Associate Professor

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


MALLA REDDY ENGINEERING COLLEGE FOR WOMEN
Autonomous Institution, UGC, Govt. of India
Programmes Accredited by NBA
Accredited by NAAC with ‘A+’ Grade
Affiliated to JNTUH, Approved by AICTE, ISO 9001:2015 Certified Institute,
Maisammaguda(V), Dhulapally (Post), (Via) Kompally, Medchal Malkajgiri Dist T.S.500100

2024-2025
MALLA REDDY ENGINEERING COLLEGE FOR WOMEN
Autonomous Institution, UGC, Govt. of India
Programmes Accredited by NBA
Accredited by NAAC with ‘A+’ Grade
Affiliated to JNTUH, Approved by AICTE, ISO 9001:2015 Certified Institute

(2005PC68) INFORMATION SECURITY LAB

B.Tech. IV Year I Semester


LTP C
0 0 3 1.5

Course Objective: The student should be made to:

To learn different cipher techniques


To implement the algorithms DES, RSA, MD5, SHA-1
To use network security tools and vulnerability assessment tools
Course Outcomes: After the completion of the “Information Security” lab,

the student can able to:


Develop code for classical Encryption Techniques to solve the problems.
Build cryptosystems by applying symmetric and public key encryption algorithms. Construct code
for authentication algorithms.
Develop a signature scheme using Digital signature standard. Demonstrate the
network security system using open-source tools

LIST OF EXPERIMENTS:
1. Perform encryption, decryption using the following substitution techniques
i. Ceaser cipher
ii. Play fair cipher
2. Perform encryption and decryption using following transposition techniques Rail fence
3. Apply DES algorithm for practical applications.
4. Apply Blow Algorithm for Practical Applications
5. Implement RSA Algorithm using HTML and JavaScript
6. Implement the Diffie-Hellman Key Exchange algorithm for a given problem.
7. Calculate the message digest of a text using the SHA-1 algorithm
8. Implement the SIGNATURE SCHEME - Digital Signature Standard.
9. Demonstrate intrusion detection system (ids) using any tool eg. Snort or any other s/w
10. Automated Attack and Penetration Tools Exploring N-Stalker, a Vulnerability Assessment tool
11. Defeating Malware - Building Trojans, Rootkit Hunter

Text Book:
1) Cryptography and Network Security (principles and approaches) by William Stallings Pearson
Education, 4th Edition.

Reference Books:

1) Network Security Essentials (Applications and Standards) by William Stallings Pearson


Education.
2) Principles of Information Security, Whitman, Thomson.
Information Security Lab Department of CSE

EXPERIMENT 1
1. Encryption& Decryption using Substitution techniques
AIM: Write a Java program to perform encryption and decryption using the following
algorithms:
a) Ceaser Cipher
b) Playfair Cipher

PROGRAM:
a) Ceaser Cipher
import java.io.Buffered Reader;

import java.io.IOException;
importjava.io.InputStreamReader;
import java.util.Scanner;
public class CeaserCipher {
static Scanner sc=new Scanner(System.in);

static Buffered Reader br=new BufferedReader(newInputStreamReader(System.in));


public static void main(String[] args) throws IOException{

// TODO code application logic here


System.out.print("Enter any String:");
String str =br.readLine();
System.out.print("\nEntertheKey:"); int
key =sc.nextInt();

String encrypted = encrypt(str, key);


System.out.println("\nEncryptedString is:"+encrypted);

String decrypted = decrypt(encrypted, key);


System.out.println("\nDecryptedString is:"+decrypted);

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 1
Information Security Lab Department of CSE

System.out.println("\n");

}
Public static String encrypt(Stringstr,int key)
{
String encrypted ="";
for(int i = 0; i < str.length(); i++)

int c=str.charAt(i);
if (Character.isUpperCase(c)) {

c = c + (key % 26);if (c > 'Z')

c = c - 26;

}
else if (Character.isLowerCase(c))
{
c = c + (key % 26);
if (c > ‘z’)

c = c - 26;

}
encrypted += (char) c;

return encrypted;

Public static String decrypt(Stringstr,intkey){


String decrypted ="";
for(inti = 0; i<str.length(); i++)

int c = str.charAt(i);

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 2
Information Security Lab Department of CSE

if (Character.isUpperCase(c)) {
c = c - (key % 26);
if (c < 'A')

}
c = c + 26;
else if (Character.isLowerCase(c))
{
c = c - (key % 26);
if(c<a)
}
C= c+26;
decrypted += (char) c;
}
return decrypted;
}
}
Output:

Enter any String:


Hello World Enter the
Key: 5
Encrypted String is: jqqt
Btwqi Decrypted String is:
Hello world

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 3
Information Security Lab Department of CSE

b ) Playfair Cipher:
PROGRAM:

public class PlayfairCipher {


private char[][] keyTable;
private static final int grid_dimension = 5;
private static final char APPEND = 'X';
public PlayfairCipher(String key) {
keyTable = generateKeyTable(key);
}
private char[][] generateKeyTable(String key) {
// Initialize the key table with all ' ' characters
char[][] table = new char[grid_dimension][grid_dimension];
for (int i = 0; i < grid_dimension; i++) {
for (int j = 0; j < grid_dimension; j++) {
table[i][j] = ' ';
}
}
// Fill the key table with the letters of the key
int row = 0;
int col = 0;
boolean[] used = new boolean[26];
for (int i = 0; i < key.length(); i++) {
char ch = Character.toUpperCase(key.charAt(i));
if (ch == 'J') {
ch = 'I';
}
if (!used[ch - 'A']) {
table[row][col] = ch;
used[ch - 'A'] = true;
col++;

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 4
Information Security Lab Department of CSE

if (col == grid_dimension) {
row++;
col = 0;
}
}
}
// Fill the remaining cells of the key table with the remaining letters of the alphabet
for (int i = 0; i < 26; i++) {
char ch = (char) ('A' + i);
if (ch == 'J') {
continue;
}
if (!used[i]) {
table[row][col] = ch;
col++;
if (col == grid_dimension) {
row++;
col = 0;
}
}
}
return table;
}
public String encrypt(String plaintext) {
plaintext = preprocess(plaintext);
StringBuilder ciphertext = new StringBuilder();
for (int i = 0; i < plaintext.length(); i += 2) {
char ch1 = plaintext.charAt(i);
char ch2 = plaintext.charAt(i + 1);
int[] position1 = findPosition(ch1);
int[] position2 = findPosition(ch2);

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 5
Information Security Lab Department of CSE

if (position1[0] == position2[0]) {
// When letters exist in same row
int newCol1 = (position1[1] + 1) % grid_dimension;
int newCol2 = (position2[1] + 1) % grid_dimension;
ciphertext.append(keyTable[position1[0]][newCol1]);
ciphertext.append(keyTable[position2[0]][newCol2]);
} else if (position1[1] == position2[1]) {
// When letters exist in same column
int newRow1 = (position1[0] + 1) % grid_dimension;
int newRow2 = (position2[0] + 1) % grid_dimension;
ciphertext.append(keyTable[newRow1][position1[1]]);
ciphertext.append(keyTable[newRow2][position2[1]]);
} else {
// When letters are not in the same column or in the same row
ciphertext.append(keyTable[position1[0]][position2[1]]);
ciphertext.append(keyTable[position2[0]][position1[1]]);
}
}
return ciphertext.toString();
}
public String decrypt(String ciphertext) {
StringBuilder plaintext = new StringBuilder();
for (int i = 0; i < ciphertext.length(); i += 2) {
char ch1 = ciphertext.charAt(i);
char ch2 = ciphertext.charAt(i + 1);
int[] position1 = findPosition(ch1);
int[] position2 = findPosition(ch2);
if (position1[0] == position2[0]) {

int newCol1 = (position1[1] + grid_dimension - 1) % grid_dimension;


int newCol2 = (position2[1] + grid_dimension - 1) % grid_dimension;

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 6
Information Security Lab Department of CSE

plaintext.append(keyTable[position1[0]][newCol1]);
plaintext.append(keyTable[position2[0]][newCol2]);
} else if (position1[1] == position2[1]) {

int newRow1 = (position1[0] + grid_dimension - 1) % grid_dimension;


int newRow2 = (position2[0] + grid_dimension - 1) % grid_dimension;
plaintext.append(keyTable[newRow1][position1[1]]);
plaintext.append(keyTable[newRow2][position2[1]]);
} else {

plaintext.append(keyTable[position1[0]][position2[1]]);
plaintext.append(keyTable[position2[0]][position1[1]]);
}
}
return postprocess(plaintext.toString());
}
private String preprocess(String text) {
// Replace J with I and add padding if needed
StringBuilder sb = new StringBuilder(text.toUpperCase().replaceAll("[^A-Z]", ""));
for (int i = 1; i < sb.length(); i += 2) {
if (sb.charAt(i) == sb.charAt(i - 1)) {
sb.insert(i, APPEND);
}
}
if (sb.length() % 2 != 0) {
sb.append(APPEND);
}
return sb.toString();
}
private String postprocess(String text) {
// Remove padding and replace X with the original character

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 7
Information Security Lab Department of CSE

StringBuilder sb = new StringBuilder(text);


for (int i = 1; i < sb.length(); i += 2) {
if (sb.charAt(i) == APPEND) {
sb.deleteCharAt(i);
}
}
return sb.toString().replace(APPEND, ' ');
}
private int[] findPosition(char ch) {
int[] pos = new int[2];
for (int i = 0; i < grid_dimension; i++) {
for (int j = 0; j < grid_dimension; j++) {
if (keyTable[i][j] == ch) {
pos[0] = i;
pos[1] = j;
return pos;
}
}
}
return null;
}

public static void main(String[] args) {


String plaintext = "MOSQUE";
String key = "MONARCHY";
PlayfairCipher cipher = new PlayfairCipher(key);
String ciphertext = cipher.encrypt(plaintext);
System.out.println("Plaintext: " + plaintext);
System.out.println("Ciphertext: " + ciphertext);
System.out.println("Decrypted text: " + cipher.decrypt(ciphertext));
}

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 8
Information Security Lab Department of CSE

OUTPUT:
Plaintext: MOSQUE
Ciphertext: ONTSML
Decrypted text: MOSQUE

EXPERIMENT 2

2. Encryption& Decryption using Transposition techniques

AIM: Write a Java program to perform encryption and decryption using the
following algorithm Rail fence-row & column Transformation

PROGRAM:

import java.util.*;
class RailFenceBasic{
int depth;
String Encryption(String plainText,int depth)throws Exception
{
int r=depth,len=plainText.length();
int c=len/depth;
char mat[][]=new char[r][c];
int k=0;
String cipherText="";
for(int i=0;i< c;i++)
{
for(int j=0;j< r;j++)
{
if(k!=len)
mat[j][i]=plainText.charAt(k++);
else

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 9
Information Security Lab Department of CSE

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];

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 10
Information Security Lab Department of CSE

}
}
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); }
}

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 11
Information Security Lab Department of CSE

EXPERIMENT 3

3.Java program for DES algorithm Logic

AIM: Write a Java program to implement the DES algorithm logic.

PROGRAM:

import java.util.*;

import java.io.BufferedReader;
import
java.io.InputSStreamReader;
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
KeySpecmyKeySpec;

private SecretKeyFactory mySecretKeyFactory;


private Cipher cipher;
byte[] keyAsBytes;

private String myEncryptionKey;

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 12
Information Security Lab Department of CSE

private String myEncryptionScheme;


SecretKey key;

staticBufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
public DES() throws Exception{
// TODO code application logic here myEncryptionKey =
"ThisIsSecretEncryptionKey";

myEncryptionScheme = DESEDE_ENCRYPTION_SCHEME;

keyAsBytes = myEncryptionKey.getBytes(UNICODE_FORMAT);
myKeySpec = new DESedeKeySpec(keyAsBytes);
mySecretKeyFactory = SecretKeyFactory.getInstance(myEncryptionScheme);

key = mySecretKeyFactory.generateSecret(myKeySpec);

Public String encrypt(String unencrypted String){


String encryptedString =null;
try {

cipher.init(Cipher.ENCRYPT_MODE, key);

byte[] plainText = unencryptedString.getBytes(UNICODE_FORMAT);

byte[] encryptedText = cipher.doFinal(plainText);


BASE64Encoderbase64encoder=newBASE64Encoder();
encryptedString = base64encoder.encode(encryptedText);}
catch (Exception e) {
e.printStackTrace(); }
return encrypted String;
}
public String decrypt(String encryptedString){
StringdecryptedText=null;
try {

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 13
Information Security Lab Department of CSE

cipher.init(Cipher.DECRYPT_MODE, key);

BASE64Decoder base64decoder = new BASE64Decoder();

byte[] encryptedText =

base64decoder.decodeBuffer(encryptedString);

byte[] plainText = cipher.doFinal(encryptedText);

decryptedText= bytes2String(plainText); }

catch (Exception e) {
e.printStackTrace(); }
return decryptedText;
}
private static String bytes2String(byte[]bytes){
StringBufferstringBuffer = new StringBuffer();
for (inti = 0; i<bytes.length; i++)
{
stringBuffer.append((char) bytes[i]); } return
stringBuffer.toString();}
Cipher.getInstance(myEncryptionScheme);
Public static void main(Stringargs[])throwsException{
System.out.print("Enter the string:");
DES myEncryptor= new DES();
String stringToEncrypt = br.readLine();
String encrypted = myEncryptor.encrypt(string SToEncrypt);
String decrypted = myEncryptor.decrypt(encrypted);
System.out.println("\nStringToEncrypt:"+stringToEncrypt);
System.out.println("\nEncrypted Value : " +encrypted);
System.out.println("\nDecrypted Value : " +decrypted);
System.out.println("");
}

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 14
Information Security Lab Department of CSE

OUTPUT:

Enter the string: Welcome


String To Encrypt:
Welcome
EncryptedValue:BPQMwc0wKvg=
Decrypted Value :Welcome

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 15
Information Security Lab Department of CSE

EXPERIMENT 4

4 .Program to implement BlowFish algorithm logic

AIM: Write a C/JAVA program to implement the BlowFish algorithm logic. PROGRAM:
import java.io.*;

importjava.io.FileInputStream;

import java.io.FileOutputStream;

import java.security.Key;

import javax.crypto.Cipher;

import javax.crypto.CipherOutputStream;

import javax.crypto.KeyGenerator;

import sun.misc.BASE64Encoder;

public class BlowFish { public static void main(String[] args) throws Exception {// TODO
code application logic here KeyGeneratorkeyGenerator =
KeyGenerator.getInstance("Blowfish"); keyGenerator.init(128);

Key secretKey = keyGenerator.generateKey();

Cipher cipherOut = Cipher.getInstance("Blowfish/CFB/NoPadding");


cipherOut.init(Cipher.ENCRYPT_MODE, secretKey);

BASE64Encoder encoder = new BASE64Encoder();

byte iv[] = cipherOut.getIV(); if (iv != null) {


System.out.println("InitializationVectoroftheCipher:"+encoder.encode(iv));} FileInputStream
fin = newFileInputStream("inputFile.txt");

FileOutputStreamfout = new FileOutputStream("outputFile.txt");


CipherOutputStreamcout=newCipherOutputStream(fout,cipherOut);

int input =0;

while ((input = fin.read()) != -1)

{cout.write(input);

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 16
Information Security Lab Department of CSE

fin.close();cout.close();

OUTPUT: Initialization Vector of the Cipher:

dI1MXzW97oQ= Contents of inputFile.txt:

Hello World Contents of outputFile.txt: ùJÖ˜ NåI“

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 17
Information Security Lab Department of CSE

EXPERIMENT 5

5. Write a Java program to implement RSA Algorithm


AIM: Write a Java program to implement RSA Algorithm.

PROGRAM:

Import java.io.Buffere0dReader;

import java.io.InputStreamReader;
import java.math.*;
import java.util.Random;
import java.util.Scanner;
public class RSA {
staticScanner sc=new Scanner(System.in);
public static void main(String[] args){
System.out.print("EnteraPrimenumber:");
BigInteger p=sc.nextBigInteger();//Here'soneprimenumber..
System.out.print("Enter another prime number:");
BigInteger q=sc.nextBigInteger();//..andanother.
BigInteger n =p.multiply(q);
BigInteger n2 = p.subtract(BigInteger.ONE).multiply(q.subtract(BigInteger.ONE));
BigInteger e = generateE(n2); BigInteger
d=e.modInverse(n2);//Here'sthemultiplicativeinverse
System.out.println("Encryption keys are: " + e + ", " + n);

System.out.println("Decryption keys are:"+d+","+n);


}
Public static BigInteger generateE(BigInteger fiofn)
{
int y,int GCD;

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 18
Information Security Lab Department of CSE

BigInteger e;
BigInteger gcd;
Random x = new Random();

do {
y = x.nextInt(fiofn.intValue()-1); StrSstring z = Integer.toString(y);
e = new
BigInteger(z);
gcd=fiofn.gcd(e);

intGCD = gcd.intValue();

}
while(y <= 2 || intGCD !=
1);return e;
}
}
OUTPUT:

Enter a Prime number: 5


Enteranotherprimenumber:
11 Encryption keys are:
33,55
Decryption keys are:17,55

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 19
Information Security Lab Department of CSE

EXPERIMENT 6

1. Diffie-Hellman

AIM: Implement the Diffie-Hellman Key Exchange mechanism using HTML


and JavaScript.Consider the end user asoneoftheparties(Alice)andtheJavaScript
application as other party(bob).

PROGRAM:

import java.math.BigInteger;
import
java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import javax.crypto.spec.DHParameterSpec;
import
javax.crypto.spec.DHPublicKeySpec; public
class DiffeHellman {
public final static int pValue = 47;
public final static int gValue = 71;
public final static int XaValue = 9;
public final static intXbValue=14;
public static void main(String[] args) throws Exception {

// TODO code application logic here

BigInteger p = new BigInteger(Integer.toString(pValue));


BigInteger g = new BigInteger(Integer.toString(gValue));
BigInteger Xa=new BigInteger(Integer.toString(XaValue));
BigIntegerXb=new
BigInteger(Integer.toString(XbValue)); createKey();
Int bitLength = 512; // 512 bits

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 20
Information Security Lab Department of CSE

SecureRandom rnd=newSecureRandom();
p=BigInteger.probablePrime(bitLength,rnd);

g=BigInteger.probablePrime(bitLength,rnd);
createSpecificKey(p, g);}

public static void createKey() throws Exception {

KeyPairGenerator kpg = KeyPairGenerator.getInstance("DiffieHellman");


kpg.initialize(512);
KeyPair kp = kpg.generateKeyPair();

KeyFactory kfactory = KeyFactory.getInstance("DiffieHellman");


DHPublicKeySpeckspec=(DHPublicKeySpec)kfactory.getKeySpec(kp.getPublic(),
DHPublicKeySpec.class);
System.out.println("Public key is: " +kspec);

Public static void create SpecificKey(BigIntegerp,BigIntegerg)throwsException{


KeyPairGenerator kpg = KeyPairGenerator.getInstance("DiffieHellman");
DHParameterSpec param = new DHParameterSpec(p,g);
kpg.initialize(param);

KeyPairkp = kpg.generateKeyPair();

KeyFactory kfactory = KeyFactory.getInstance("DiffieHellman");


DHPublicKeySpeck
spec=(DHPublicKeySpec)kfactory.getKeySpec(kp.getPublic(),
DHPublicKeySpec.class);
System.out.println("\nPublic key is : " +kspec);

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 21
Information Security Lab Department of CSE

OUTPUT:

Public key is:


javax.crypto.spec.DHPublicKeySpec@5afd29Public key is:
javax.crypto.spec.DHPublicKeySpec@9971ad

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 22
Information Security Lab Department of CSE

EXPERIMENT 7

7. SHA-1

AIM: Calculate the message digest of a text using the SHA-1 algorithm in JAVA.

PROGRAM:

Import java.security.*;

public class SHA1 {


publicstaticvoidmain(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));

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 23
Information Security Lab Department of CSE

System.out.println("");}

catch (Exception e) { system.out.println("Exception:"+e);}


}

public static String bytes ToHex(byte[] b) {

char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

StringBufferbuf = 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 = SHA1
Provider = SUN version
1.6
ToString = SHA1 Message Digest from SUN,

<initialized>SHA1("") =
DA39A3EE5E6B4B0D3255BFEF95601890AFD80709
SHA1("abc") = A9993E364706816ABA3E25717850C26C9CD0D89D

SHA1("abcdefghijklmnopqrstuvwxyz")=32D10C7B8CF96570CA04CE37F2A19D842
4 0D3A89

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 24
Information Security Lab Department of CSE

EXPERIMENT 8

AIM: Implement the SIGNATURE SCHEME - Digital Signature Standard.


PROGRAM:

import java.security.*;
public class DigitalSignatureExample {
public static void main(String[] args) {
try {
// Generate key pair
KeyPairGenerator keyGen = KeyPairGenerator.getInstance(“DSA”);
SecureRandom random = new SecureRandom();
keyGen.initialize(1024, random);
KeyPair keyPair = keyGen.generateKeyPair();
// Get private and public keys
PrivateKey privateKey = keyPair.getPrivate();
PublicKey publicKey = keyPair.getPublic();
// Create a signature object
Signature signature = Signature.getInstance(“SHA256withDSA”);
// Sign the data
String data = “Hello, world!”; byte[]
dataBytes = data.getBytes();
signature.initSign(privateKey);
signature.update(dataBytes);
byte[] digitalSignature = signature.sign();
// Verify the signature
signature.initVerify(publicKey);
signature.update(dataBytes);
boolean verified = signature.verify(digitalSignature);s
// Print the result
if (verified)

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 25
Information Security Lab Department of CSE

{
System.out.println(“Signature verified.”);
} else {
System.out.println(“Signature verification failed.”);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Output:
Signature verified.

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 26
Information Security Lab Department of CSE

EXPERIMENT 9

9. Demonstrate intrusion detection system using any tool eg: snort or


any other software

AIM : Demonstrate intrusion detection system using any tool

PROGRAM:
import java.util.Scanner;
public class IntrusionDetectionSystem {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print(“Enter network data: “); String
networkData = scanner.nextLine();
boolean intrusionDetected = detectIntrusion(networkData);
if (intrusionDetected) { System.out.println(“Intrusion
detected!”);
} else
{
System.out.println(“No intrusion detected.”);
}
}
public static boolean detectIntrusion(String data) {
// Define the intrusion pattern
String intrusionPattern = “malware”;
// Perform pattern matching
if (data.contains(intrusionPattern)) {
return true;
} else
{
return false;
}

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 27
Information Security Lab Department of CSE

}
}
Output:
Enter network data: The system is infected with malware and unauthorized access
attempts are detected.
Intrusion detected!
Output2:
Enter network data: The system is functioning normally without any security threats.
No intrusion detected.

Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 28
Information Security Lab Department of CSE

EXPERIMENT 10

10. Automated attack and penetration tools exploring N- stacks assessment tool

AIM: Automated attack and penetration tools exploring N- stacks a vulnerability assessment
tool

PROGRAM:
import java.util.Stack;
public class VulnerabilityAssessmentTool {
public static void main(String[] args) {
// Create multiple stacks for exploration
Stack&lt;String&gt; stack1 = new Stack&lt;&gt;();
Stack&lt;String&gt; stack2 = new Stack&lt;&gt;();
// Add elements to the stacks
stack1.push(“Element 1”);
stack1.push(“Element 2”);
stack2.push(“Element 3”);

// Perform vulnerability assessment on each stack


exploreStack(stack1);
exploreStack(stack2);
}

public static void exploreStack(Stack&lt;String&gt; stack) {


// Check for vulnerabilities in the stack
if (stack.isEmpty()) {
System.out.println(“The stack is empty. Vulnerability detected!”);
} else {
System.out.println(“The stack contains elements. No vulnerability detected.”);
Malla Reddy Engineering College for Women (Autonomous Institution-UGC, Govt. of India) Page 30
Information Security Lab Department of CSE

// Add more vulnerability assessment logic here

// Clear the stack after assessment


stack.clear();
}
}
Output:
The stack contains elements. No vulnerability detected.
The stack contains elements. No vulnerability detected.

Malla Reddy Engineering College for Women (Autonomous Institution-UGC, Govt. of India) Page 31
Information Security Lab Department of CSE

EXPERIMENT 11

11. Defeating malware-building trojans rootkit hunter


AIM: To defeating malware-building trojans rootkit hunter

PROGRAM:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class RootkitHunter {
private static final String[] ROOTKIT_FILE_PATHS = { “/usr/bin/ldd”, //
Example rootkit file path “/usr/local/bin/ls”, // Example rootkit file path
// Add more rootkit file paths here
};
public static void main(String[] args) {
List&lt;String&gt; rootkitFiles = findRootkitFiles();
if (rootkitFiles.isEmpty()) { System.out.println(“No
rootkits found.”);
} else {
System.out.println(“Rootkits found:”); for (String
rootkitFile : rootkitFiles) {
System.out.println(rootkitFile);
}
}
}
private static List&lt;String&gt; findRootkitFiles() {
List&lt;String&gt; rootkitFiles = new ArrayList&lt;&gt;();
for (String filePath : ROOTKIT_FILE_PATHS) {

Malla Reddy Engineering College for Women (Autonomous Institution-UGC, Govt. of India) Page 32
Information Security Lab Department of CSE

if (isFileHidden(filePath)) {
rootkitFiles.add(filePath);
}
}
return rootkitFiles;
}
private static boolean isFileHidden(String filePath) {
try {
Process process = Runtime.getRuntime().exec(“lsattr -R “ + filePath);
BufferedReader reader = new BufferedReader(new
InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
if (line.contains(“H”)) { return true;
}
}
reader.close();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
}

Output:
Rootkits found:
/usr/bin/ldd
/usr/local/bin/ls

Malla Reddy Engineering College for Women (Autonomous Institution-UGC, Govt. of India) Page 33

You might also like