Information Security Lab Manual
Information Security Lab Manual
Prepared by
Dr. Smita Khond Dr. N. Baskar
Associate Professor Associate Professor
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
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:
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);
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 - 26;
}
else if (Character.isLowerCase(c))
{
c = c + (key % 26);
if (c > ‘z’)
c = c - 26;
}
encrypted += (char) c;
return encrypted;
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:
Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 3
Information Security Lab Department of CSE
b ) Playfair Cipher:
PROGRAM:
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]) {
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]) {
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
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
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
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;
Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 12
Information Security Lab Department of CSE
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);
cipher.init(Cipher.ENCRYPT_MODE, key);
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);
byte[] encryptedText =
base64decoder.decodeBuffer(encryptedString);
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:
Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 15
Information Security Lab Department of CSE
EXPERIMENT 4
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);
{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();
Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 17
Information Security Lab Department of CSE
EXPERIMENT 5
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);
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:
Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 19
Information Security Lab Department of CSE
EXPERIMENT 6
1. Diffie-Hellman
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 {
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);}
KeyPairkp = kpg.generateKeyPair();
Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 21
Information Security Lab Department of CSE
OUTPUT:
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.*;
Malla Reddy Engineering College for Women (Autonomous Institution, UGC, Govt. of India) 23
Information Security Lab Department of CSE
System.out.println("");}
char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
OUTPUT:
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
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
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<String> stack1 = new Stack<>();
Stack<String> stack2 = new Stack<>();
// Add elements to the stacks
stack1.push(“Element 1”);
stack1.push(“Element 2”);
stack2.push(“Element 3”);
Malla Reddy Engineering College for Women (Autonomous Institution-UGC, Govt. of India) Page 31
Information Security Lab Department of CSE
EXPERIMENT 11
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<String> 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<String> findRootkitFiles() {
List<String> rootkitFiles = new ArrayList<>();
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