0% found this document useful (0 votes)
11 views

software-defined-networks-ccs365

The document outlines a laboratory course on security techniques, specifically focusing on various encryption and decryption methods including Caesar, Playfair, Hill, and Vigenere ciphers, as well as DES, AES, RSA, and Diffie-Hellman algorithms. It includes detailed algorithms and sample C programs for implementing these techniques. Additionally, it covers the calculation of message digests using SHA-1 and the demonstration of intrusion detection systems.

Uploaded by

sathishkbv
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)
11 views

software-defined-networks-ccs365

The document outlines a laboratory course on security techniques, specifically focusing on various encryption and decryption methods including Caesar, Playfair, Hill, and Vigenere ciphers, as well as DES, AES, RSA, and Diffie-Hellman algorithms. It includes detailed algorithms and sample C programs for implementing these techniques. Additionally, it covers the calculation of message digests using SHA-1 and the demonstration of intrusion detection systems.

Uploaded by

sathishkbv
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
You are on page 1/ 41

lOMoARcPSD|37882674

Software Defined Networks (CCS365)

Software Defined Networks (Anna University)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)
lOMoARcPSD|37882674

NELLAI COLLEGE OF ENGINEERING


DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
SUBJECT CODE / SUBJECT NAME:IT8761-SECURITY LABORATORY
YEAR / SEM:IV / VII REGULATION:2017

LIST OF LAB EXPERIMENTS


1. Encryption and decryption using substitution techniques
(i) Ceaser cipher
(ii) playfair cipher
(iii) Hill Cipher
(iv) Vigenere cipher

2. Encryption and decryption using transposition technique:


Rail fence - row & Column Transformation

3. Implementation of DES algorithm

4. Implementation of AES algorithm

5. Implementation of RSA Algorithm

6. Implementation of the Diffie-Hellman Key Exchange algorithm .


.
7. Calculation of the message digest of a text using the SHA-1 algorithm.

8. Implementation of the SIGNATURE SCHEME - Digital Signature Standard.

9. Demonstration of intrusion detection system (ids) .

10. Defeating Malware – Rootkit Hunter

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

EX NO : 1 i) Encryption and Decryption Using Substitution Cipher- Caesar Cipher


AIM : Write a C program for Substitution ciphers using Caesar Cipher.
ALGORITHM :
1. Enter the plaintext to be encrypted and enter the key value.
2. Function encrypt ( ) will be invoked for encryption.
a) Take the ascii value of each plain text char and add it with the value of key % 26
b) Take the equivalent char value for the resultant value of sub-step(a)
c) Return the cipher text.
3. Function decrypt ( ) will be invoked for decryption.
a) Take the ascii value of each cipher text char and subtract the value of key % 26
from it
b) Take the equivalent char value for the resultant value of sub-step(a)
c) Return the plain text.
#include <stdio.h>
#include <ctype.h>
#define MAXSIZE 1024
void encrypt(char*);
void decrypt(char*);
int menu();
int main(void)
{
char c,
choice[2],
s[MAXSIZE];
while(1)
{
menu();
gets(choice);
if((choice[0]=='e')||(choice[0]=='E'))
{
puts("Input text to encrypt->");
gets(s);
encrypt(s);
}
else if((choice[0]=='d')||(choice[0]=='D'))
{
puts("Input text to decrypt->");
gets(s);
decrypt(s);
}
else
break;
}
return 0;
}
void encrypt(char*str)
{
int n=0;
char *p=str,
q[MAXSIZE];
while(*p)
{
if(islower(*p))
{
if((*p>='a')&&(*p<'x'))

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

q[n]=toupper(*p + (char)3);
else if(*p=='x')
q[n]='A';
else if(*p=='y')
q[n]='B';
else
q[n]='C';
}
else
{
q[n]=*p;
}
n++; p++;
}
q[n++]='\0';
puts(q);
}
void decrypt(char*str)
{
int n=0;
char *p=str,
q[MAXSIZE];
while(*p)
{
if(isupper(*p))
{
if((*p>='D')&&(*p<='Z'))
q[n]=tolower(*p - (char)3);
else if(*p=='A')
q[n]='x';
else if(*p=='B')
q[n]='y';
else
q[n]='z';
}
else
{
q[n]=*p;
}
n++; p++;
}
q[n++]='\0';
puts(q);
}
int menu()
{
puts("To encrypt, input e or E\n");
puts("To decrypt, input d or D\n");
puts("To exit, input any other letter\n");
puts("Your choice:->\n");
return 0;
}
Output:
Encrypt -----e or E
Decrypt------d or D

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

To exit :any other letter


Choice:e
Enter the text
Hello
KHOOR
Choice:a
Exit
Result:Thus ceasar cipher was executed successfully.

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

EX NO : 1. ii) Encryption and Decryption Using Substitution Cipher-- Playfair Cipher


AIM: To write a C program to implement Play Fair Cipher technique.
ALGORITHM :
1) Generate Key matrix
a) Take any random key of any length and form a 5 X 5 matrix.
b) Fill the rows of the matrix with the key characters and ignore repeating character.
c) Fill the remaining matrix with alphabets from A to Z (except those already occurred
in the key).
2) Encrypt the data using encryption rule and key matrix
a) To Encrypt the data take two characters at time from plain text file and encrypt it
using one of the following rules.
b) Repeating plain text letters that would fall in the same pair are separated with filler
letter,
c) 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.
d) 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.
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
3) To decrypt, use the inverse of encryption rules.
4) Display the cipher text after encryption and plain text after decryption.
Program:
#include<stdio.h>
#include<string.h>
void cipher(int i,int c);
int 昀椀ndMin();
void makeArray(int,int);
char arr[22][22],darr[22][22],emessage[111],retmessage[111],key[55];
char temp[55],temp2[55];
int k=0;
int main() {
char *message,*dmessage;
int i,j,klen,emlen,昀氀ag=0;
int r,c,index,min,rows;
clrscr();
prin琀昀("Enter the key\n");
昀툀ush(stdin);
gets(key);
prin琀昀("\nEnter message to be ciphered\n");
昀툀ush(stdin);
gets(message);
strcpy(temp,key);
klen=strlen(key);
k=0;
for (i=0; ;i++) {
if(昀氀ag==1)
break;
for (j=0;key[j]!=NULL;j++) {
if(message[k]==NULL) {
昀氀ag=1;
arr[i][j]='-';

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

} else {
arr[i][j]=message[k++];
}
}
}
r=i;
c=j;
for (i=0;i<r;i++) {
for (j=0;j<c;j++) {
prin琀昀("%c ",arr[i][j]);
}
prin琀昀("\n");
}
k=0;
for (i=0;i<klen;i++) {
index=昀椀ndMin();
cipher(index,r);
}
emessage[k]='\0';
prin琀昀("\nEncrypted message is\n");
for (i=0;emessage[i]!=NULL;i++)
prin琀昀("%c",emessage[i]);
prin琀昀("\n\n");
//deciphering
emlen=strlen(emessage);
//emlen is length of encrypted message
strcpy(temp,key);
rows=emlen/klen;
//rows is no of row of the array to made from ciphered message
j=0;
for (i=0,k=1;emessage[i]!=NULL;i++,k++) {
//prin琀昀("\nEmlen=%d",emlen);
temp2[j++]=emessage[i];
if((k%rows)==0) {
temp2[j]='\0';
index=昀椀ndMin();
makeArray(index,rows);
j=0;
}
}
prin琀昀("\nArray Retrieved is\n");
k=0;
for (i=0;i<r;i++) {
for (j=0;j<c;j++) {
prin琀昀("%c ",darr[i][j]);
//retrieving message
retmessage[k++]=darr[i][j];
}
prin琀昀("\n");
}
retmessage[k]='\0';

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

prin琀昀("\nMessage retrieved is\n");


for (i=0;retmessage[i]!=NULL;i++)
prin琀昀("%c",retmessage[i]);
getch();
return(0);
}
void cipher(int i,int r) {
int j;
for (j=0;j<r;j++) { {
emessage[k++]=arr[j][i];
}
}
// emessage[k]='\0';
}
void makeArray(int col,int row) {
int i,j;
for (i=0;i<row;i++) {
darr[i][col]=temp2[i];
}
}
int 昀椀ndMin() {
int i,j,min,index;
min=temp[0];
index=0;
for (j=0;temp[j]!=NULL;j++) {
if(temp[j]<min) {
min=temp[j];
index=j;
}
}
temp[index]=123;
return(index);
}
Output:

Result:Thus play fair cipher was executed successfully.

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

EX NO : 1 . iii) Encryption and Decryption Using Substitution Cipher - Hill Cipher


AIM : To write a C program to implement Hill Cipher Technique.
ALGORITHM :
1. Enter the plain text.
2, Enter the matrix, named key matrix for encryption. The elements of the matrix will be
randomly chosen and of modulo 26.
3. Plain text characters are multiplied by the encryption matrix.
4. Display the cipher text.
5. Find the inverse of the key matrix.
6. For decryption, multiply the characters of cipher text by key matrix to get plaintext and
display it.
Program:
#include<stdio.h>
#include<math.h>
float encrypt[3][1], decrypt[3][1], a[3][3], b[3][3], mes[3][1], c[3][3];
void encryption(); //encrypts the message
void decryption(); //decrypts the message
void getKeyMessage(); //gets key and message from user
void inverse(); //finds inverse of key matrix
void main() {
getKeyMessage();
encryption();
decryption();
}
void encryption() {
int i, j, k;
for(i = 0; i < 3; i++)
for(j = 0; j < 1; j++)
for(k = 0; k < 3; k++)
encrypt[i][j] = encrypt[i][j] + a[i][k] * mes[k][j];
printf("\nEncrypted string is: ");
for(i = 0; i < 3; i++)
printf("%c", (char)(fmod(encrypt[i][0], 26) + 97));
}
void decryption() {
int i, j, k;
inverse();
for(i = 0; i < 3; i++)
for(j = 0; j < 1; j++)
for(k = 0; k < 3; k++)
decrypt[i][j] = decrypt[i][j] + b[i][k] * encrypt[k][j];
printf("\nDecrypted string is: ");
for(i = 0; i < 3; i++)
printf("%c", (char)(fmod(decrypt[i][0], 26) + 97));
printf("\n");
}
void getKeyMessage() {
int i, j;
char msg[3];
printf("Enter 3x3 matrix for key (It should be inversible):\n");
for(i = 0; i < 3; i++)

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

for(j = 0; j < 3; j++) {


scanf("%f", &a[i][j]);
c[i][j] = a[i][j];
}
printf("\nEnter a 3 letter string: ");
scanf("%s", msg);

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


mes[i][0] = msg[i] - 97;
}
void inverse() {
int i, j, k;
float p, q;
for(i = 0; i < 3; i++)
for(j = 0; j < 3; j++) {
if(i == j)
b[i][j]=1;
else
b[i][j]=0;
}
for(k = 0; k < 3; k++) {
for(i = 0; i < 3; i++) {
p = c[i][k];
q = c[k][k];
for(j = 0; j < 3; j++) {
if(i != k) {
c[i][j] = c[i][j]*q - p*c[k][j];
b[i][j] = b[i][j]*q - p*b[k][j];
}
}
}
}
for(i = 0; i < 3; i++)
for(j = 0; j < 3; j++)
b[i][j] = b[i][j] / c[i][i];
printf("\n\nInverse Matrix is:\n");
for(i = 0; i < 3; i++) {
for(j = 0; j < 3; j++)
printf("%d ", b[i][j]);
printf("\n");
}
}
Output:

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

Result:Thus hill cipher was executed successfully.

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

EX NO : 1 . iv) Encryption and Decryption Using Substitution Cipher - Vigenere Cipher


AIM : To write a C program to implement Vigenere Cipher technique.
ALGORITHM :
1. Enter the plain text for encryption.
2. Enter the encryption key pharse.
3. Cipher text is obtained by modular addition of a key pharse and plain text.
4. For decryption to get the plaintext again the key pharse is modularly subtracted from the
cipher text.
5. Display the cipher text and plaintext.
Program:
#include<stdio.h>
char arr[26][26];
char message[22],key[22],emessage[22],retMessage[22];
int 昀椀ndRow(char);
int 昀椀ndColumn(char);
int 昀椀ndDecRow(char,int);
int main()
{
int i=0,j,k,r,c;
clrscr();
k=96;
for(i=0;i<26;i++)
{
k++;
for(j=0;j<26;j++)
{
arr[i][j]=k++;
if(k==123)
k=97;
}
}
prin琀昀("\nEnter message\n");
gets(message);
prin琀昀("\nEnter the key\n");
gets(key);
// Encryp琀椀on
for(i=0;key[i]!=NULL;i++)
{
c=昀椀ndRow(key[i]);
r=昀椀ndColumn(message[i]);
emessage[i]=arr[r][c];
}
emessage[i]='\0';
prin琀昀("\n Encrypted message is:\n\n");
for(i=0;emessage[i]!=NULL;i++)
prin琀昀("%c",emessage[i]);
//decryp琀椀on
for(i=0;key[i]!=NULL;i++)

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

{
c=昀椀ndColumn(key[i]);
r=昀椀ndDecRow(emessage[i],c);
retMessage[i]=arr[r][0];
}
retMessage[i]='\0';
prin琀昀("\n\nMessage Retrieved is:\n\n");
for(i=0;retMessage[i]!=NULL;i++)
prin琀昀("%c",retMessage[i]);
getch();
return(0);
}
int 昀椀ndRow(char c)
{
int i;
for(i=0;i<26;i++)
{
if(arr[0][i]==c)
return(i);
}
}
int 昀椀ndColumn(char c)
{
int i;
for(i=0;i<26;i++)
{
if(arr[i][0]==c)
return(i);
}
}
int 昀椀ndDecRow(char c,int j)
{
int i;
for(i=0;i<26;i++)
{
if(arr[i][j]==c)
return(i);
}
}
Output:

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

Result:Thus vignere cipher was executed successfully.

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

EX NO : 2 Encryption and Decryption Using Transposition Technique:Rail fence – row and


column Transformation
AIM : To write a C program to Implement Rail fence row & column transformation.
ALGORITHM :
1. Enter the plain text for encryption.
2. Enter the depth in integer (number of rows)
3. In the rail fence cipher, the plaintext is written downwards and diagonally on successive
"rails" of an imaginary fence, then moving up when we reach the bottom rail.
4. When we reach the top rail, the message is written downwards again until the whole
plaintext is written out.
5. The message is then read off in rows. Thus, the cipher text is generated.
Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i,j,k,l;
char a[20],c[20],d[20];
clrscr();
prin琀昀("\nEnter the input string : ");
gets(a);
l=strlen(a);
/*Ciphering*/
for(i=0,j=0;i<l;i++)
{
if(i%2==0)
c[j++]=a[i];
}
for(i=0;i<l;i++)
{
if(i%2==1)
c[j++]=a[i];
}
c[j]='\0';
prin琀昀("\nCipher text a昀琀er applying rail fence :");
prin琀昀("\n%s",c);
/*Deciphering*/
if(l%2==0)
k=l/2;
else
k=(l/2)+1;
for(i=0,j=0;i<k;i++)
{
d[j]=c[i];
j=j+2;
}
for(i=k,j=1;i<l;i++)

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

{
d[j]=c[i];
j=j+2;
}
d[l]='\0';
prin琀昀("\nText a昀琀er decryp琀椀on : ");
prin琀昀("%s",d);
getch();
}
Output

Result:Thus rail fence transforma琀椀on was executed successfully.

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

EX NO : 3 Implementation of Data Encryption Standard(DES)


AIM : To write a java program to implement DES Cipher Encryption and decryption
technique.
ALGORITHM :
1. Enter the plain text and key
2. Initial permutation (IP) will be done for the plain text and key.
3. 16 rounds of a complex key dependent calculation f
Function f is
L(i) = R(i-1)
R(i) = L(i-1) Å P(S( E(R(i-1)) Å K(i) ))
4. A final permutation, being the inverse of IP will be done to get cipher text.
5. The above steps 4, 3, 2 are repeated in reverse order to get decrypted text.
Program

import javax.swing.*;

import java.security.SecureRandom;

import javax.crypto.Cipher;

import javax.crypto.KeyGenerator;

import javax.crypto.SecretKey;

import javax.crypto.spec.SecretKeySpec;

import java.u琀椀l.Random ;

class DES {

byte[] skey = new byte[1000];

String skeyString;

sta琀椀c byte[] raw;

String inputMessage,encryptedData,decryptedMessage;

public DES() {

try {

generateSymmetricKey();

inputMessage=JOp琀椀onPane.showInputDialog(null,"Enter message to encrypt");

byte[] ibyte = inputMessage.getBytes();

byte[] ebyte=encrypt(raw, ibyte);

String encryptedData = new String(ebyte);

System.out.println("Encrypted message "+encryptedData);

JOp琀椀onPane.showMessageDialog(null,"Encrypted Data "+"\n"+encryptedData);

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

byte[] dbyte= decrypt(raw,ebyte);

String decryptedMessage = new String(dbyte);

System.out.println("Decrypted message "+decryptedMessage);

JOp琀椀onPane.showMessageDialog(null,"Decrypted Data "+"\n"+decryptedMessage);

catch(Excep琀椀on e) {

System.out.println(e);

void generateSymmetricKey() {

try {

Random r = new Random();

int num = r.nextInt(10000);

String knum = String.valueOf(num);

byte[] knumb = knum.getBytes();

skey=getRawKey(knumb);

skeyString = new String(skey);

System.out.println("DES Symmetric key = "+skeyString);

catch(Excep琀椀on e) {

System.out.println(e);

private sta琀椀c byte[] getRawKey(byte[] seed) throws Excep琀椀on {

KeyGenerator kgen = KeyGenerator.getInstance("DES");

SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");

sr.setSeed(seed);

kgen.init(56, sr);

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

SecretKey skey = kgen.generateKey();

raw = skey.getEncoded();

return raw;

private sta琀椀c byte[] encrypt(byte[] raw, byte[] clear) throws Excep琀椀on {

SecretKeySpec skeySpec = new SecretKeySpec(raw, "DES");

Cipher cipher = Cipher.getInstance("DES");

cipher.init(Cipher.ENCRYPT_MODE, skeySpec);

byte[] encrypted = cipher.doFinal(clear);

return encrypted;

private sta琀椀c byte[] decrypt(byte[] raw, byte[] encrypted) throws Excep琀椀on {

SecretKeySpec skeySpec = new SecretKeySpec(raw, "DES");

Cipher cipher = Cipher.getInstance("DES");

cipher.init(Cipher.DECRYPT_MODE, skeySpec);

byte[] decrypted = cipher.doFinal(encrypted);

return decrypted;

public sta琀椀c void main(String args[]) {

DES des = new DES();

Output:

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

Result: Thus DES algorithm was executed successfully.

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

EX NO : 4 Implementation of Advanced Encryption Standard(AES)


AIM : To write a java program to implement AES Cipher Encryption and decryption
technique.
ALGORITHM :
1. Enter the plain text and key for encryption.
2. It undergoes 10 rounds.
3. Each rounds consists of four steps:Substitute Bytes,Shift Rows,Mix Columns,Add Round
Key.
4. Each steps undergoes two types of transformations:one is forward and the other is
inverse..
5. Encryption starts with a Add Round Key and Ends with Add Round Key to produce
cipher text in encryption.
3. 10 th round consist of only three steps: Substitute Bytes,Shift Rows,Mix Columns.
4. In decryption both the cipher text and key undergoes 10 rounds to produce a plain text..
5. It also consists of four steps but in reverse order.
6. Each steps undergoes two types of transformations:one is forward and the other is
inverse..
7. Decryption starts with a Add Round Key and Ends with Add Round Key to produce Plain
Text .

Program

import java.io.UnsupportedEncodingExcep琀椀on;

import java.security.MessageDigest;

import java.security.NoSuchAlgorithmExcep琀椀on;

import java.u琀椀l.Arrays;

import java.u琀椀l.Base64;

import javax.crypto.Cipher;

import javax.crypto.spec.SecretKeySpec;

public class AES {

private sta琀椀c SecretKeySpecsecretKey;

private sta琀椀c byte[] key;

public sta琀椀c void setKey(String myKey)

MessageDigestsha = null;

try {

key = myKey.getBytes("UTF-8");

sha = MessageDigest.getInstance("SHA-1");

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

key = sha.digest(key);

key = Arrays.copyOf(key, 16);

secretKey = new SecretKeySpec(key, "AES");

catch (NoSuchAlgorithmExcep琀椀on e) {

e.printStackTrace();

catch (UnsupportedEncodingExcep琀椀on e) {

e.printStackTrace();

public sta琀椀c String encrypt(String strToEncrypt, String secret)

try

setKey(secret);

Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");

cipher.init(Cipher.ENCRYPT_MODE, secretKey);

return Base64.getEncoder().encodeToString(cipher.doFinal(strToEncrypt.getBytes("UTF-8")));

catch (Excep琀椀on e)

System.out.println("Error while encryp琀椀ng: " + e.toString());

return null;

public sta琀椀c String decrypt(String strToDecrypt, String secret)

try

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

setKey(secret);

Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");

cipher.init(Cipher.DECRYPT_MODE, secretKey);

return new String(cipher.doFinal(Base64.getDecoder().decode(strToDecrypt)));

catch (Excep琀椀on e)

System.out.println("Error while decryp琀椀ng: " + e.toString());

return null;

public sta琀椀c void main(String[] args)

昀椀nal String secretKey = "ssshhhhhhhhhhh!!!!";

String originalString = "howtodoinjava.com";

String encryptedString = AES.encrypt(originalString, secretKey) ;

String decryptedString = AES.decrypt(encryptedString, secretKey) ;

System.out.println(originalString);

System.out.println(encryptedString);

System.out.println(decryptedString);

Output:

Plain Text:howtodoinjava.com

Cipher Text: Tg2Nn7wUZOQ6Xc+1lenkZTQ9ZDf9a2/RBRiqJBCIX6o=

howtodoinjava.com

Result:Thus AES algorithm was executed and output was verified successfully.

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

EX NO : 5 Implementation of RSA Algorithm

AIM : To implement Encryption and decryption using RSA Algorithm..

ALGORITHM :
Key generation:
1. Select random prime numbers p and q , and check that p != q
2. Compute modulus n = pq
3. Compute phi, ¢ = (p - 1)(q - 1)
4. Select public exponent e , 1 < e < ¢ . such that gcd(e, ¢ ) = 1
5. Compute private exponent d =e-1 mod ¢
6. Public key is {n, e}, private key is d
Encryption & Decryption
7. Encryption: c = memod n ,
9. Decryption: m = cdmod n
10. Display the cipher text and plain text.
Program

<html>

<head>

<琀椀tle>JavaScript RSA Encryp琀椀on</琀椀tle>

</head>

<body>

<h1>Lab 8 Demo 1: JavaScript RSA test</h1>

Enter a plaintext: <input id="plaintext" name="plaintext" type="text">

<br/><br/>

RSA encryp琀椀on key is de昀椀ned in the Code!

<br/><br/>

<bu琀琀on type="bu琀琀on" onclick="RSA_encryp琀椀on()">Encrypt the Message</bu琀琀on>

<h3>Encrypted value</h3>

<p id="encrypted"></p>

<br/><br/>

RSA decryp琀椀on key is de昀椀ned in the Code!

<br/><br/>

<bu琀琀on type="bu琀琀on" onclick="RSA_decryp琀椀on()">Decrypt the "Encrypted value"</bu琀琀on>

<h3>Decrypted value</h3>

<p id="decrypted"></p>

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

<script src="rsa.js"></script>

<script type="text/javascript">

func琀椀on RSA_encryp琀椀on(){

var plaintext = document.getElementById("plaintext").value;

varpubilc_key = "-----BEGIN PUBLIC KEY-----


MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzdxaei6bt/xIAhYsdFdW62CGTpRX+GXoZkzq
vbf5oOxw4wKENjFX7LsqZXxdFfoRxEwH90zZHLHgsNFzXe3JqiRabIDcNZmKS2F0A7+Mwrx6K2fZ5b7E2f
SLFbC7FsvL22mN0KNAp35tdADpl4lKqNFuF7NT22ZBp/X3ncod8cDvMb9tl0hiQ1hJv0H8My/
31w+F+Cdat/9Ja5d1ztOOYIx1mZ2FD2m2M33/BgGY/
BusUKqSk9W91Eh99+tHS5oTvE8CI8g7pvhQteqmVgBbJOa73eQhZfOQJ0aWQ5m2i0NUPcmwvGDzUR
XTKW+72UKDz671bE7YAch2H+U7UQeawwIDAQAB-----END PUBLIC KEY-----";

// Encrypt with the public key...

var encrypt = new JSEncrypt();

encrypt.setPublicKey(pubilc_key);

var encrypted = encrypt.encrypt(plaintext);

document.getElementById("encrypted").innerHTML = encrypted;

func琀椀on RSA_decryp琀椀on(){

var encrypted = document.getElementById("encrypted").innerHTML;

varprivate_key = "-----BEGIN PRIVATE KEY-----


MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDN3Fp6Lpu3/
EgCFix0V1brYIZOlFf4ZehmTOq9t/
mg7HDjAoQ2MVfsuyplfF0V+hHETAf3TNkcseCw0XNd7cmqJFpsgNw1mYpLYXQDv4zCvHorZ9nlvsTZ9Is
VsLsWy8vbaY3Qo0Cnfm10AOmXiUqo0W4Xs1PbZkGn9fedyh3xwO8xv22XSGJDWEm/QfwzL/
fXD4X4J1q3/0lrl3XO045gjHWZnYUPabYz昀昀8GAZj8G6xQqpKT1b3USH3360dLmhO8TwIjyDum+FC16qZ
WAFsk5rvd5CFl85AnRpZDmbaLQ1Q9ybC8YPNRFdMpb7vZQoPPrvVsTtgByHYf5TtRB5rDAgMBAAECgg
EAUDPieCnCd1rtvwpehXElpwxzJxg6ccdaVMjwx7tuoRidHoRzeB2fUNbWvLVIGvDTjTPGAr5I9BoFHT5t
ARJMeGIzbISDxsosDBRKu88cCx6dRl3ukcjSLsxMh8XUDhyWLsSgAMIpxVfHUuOsHmLZ2I3Ho6o1KIxdV
g/JSgtdwTqjz3w8jmGQ/NXgc7Ym/ys1fLG9L2nYdMzK/mRJf/BnXiCNE6/
SYlZYO716oC688UJBWS3BqB9jaJyNpigX//
ynJvU6xw8FhHt4fRStUmCCYAYhCQu3XgbtmxKisDGhdBVASG+DM+vVTh+sSvxkNrjJjF+m2tSg578A8C8
Ls0r3uQKBgQDpO9e178NR0HHmvWbZR9+uPugf4UT9+U2/
dEfJBHAOp2GRsIvXkFwbPHuSHkc0iEPwz+U8gPC8jInSslKOUDtaGtUaVzzWrxxh7DggWx4pYs3I0Ki8C+
CRTTdOY9GAFa9jhIyRmf6v9QoAH/
loGNV2qYFbb+HweD0PnxlWha1txQKBgQDh9IBBltW7T96foUmHOn+x6xlF5MNDHxLBY6bngxKvMTZo
i5C6wmmCmasF45LWbkvUiMAsovYN5z4cJnKXWmRmCS8NXUucmUgdvsmCbiB62BmZvHaO昀昀mnIdhc
AjBebT/
Bn5qMvKCNy3fQFSfuEw1eRRO2IofB4o7z7m794vo25wKBgEPowrQcrZhCwwdWGn4laUGI23l80+PHF
RYru0MSYbZCkiwjZXRMeiUMBUbUPhNTocSaI7rsKCweF3sbpOH/

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

BmkD6wySXgp8Th1M9EKnhS6zsAtKh昀戀K1oY4H2RZuAQ9TCYD0BIM7pU5GcJTjQD8ShsU269N8lFcERt
dTbldjtOpAoGAF4YkADAa6lhjXg0loY2Gk9hdFji913QZuMaOLtYnkNO3zWSSWc85ut4Svxc1R1vOSz89e
qgwo7vqbHXYQken4jOckXCgGZq昀琀nERe6HJgeCTsby8PxOAdVUBuHqF3J7VH2xlY7eTo4+GVsSNFq0nH
CRm6/
RmW9ohdeXh6k7CLAsCgYBZe3RLWu昀昀Kxg+lZmv9tJDOO813QPLFeixrBYhKjGDcwjVYcCugGNDmyStM
0/++uWddgMKavNALjpamu8KolDNivrjL1qaFHX9Bpi108T+dDn2WpX+vUP6hjA/
U2wtTvUbJle1SsbZxRrV9gf5PAJqTrQY4u28ezjR3PCV+R4kdw==-----END PRIVATE KEY-----";

// Decrypt with the private key...

var decrypt = new JSEncrypt();

decrypt.setPrivateKey(private_key);

var decrypted = decrypt.decrypt(encrypted);

document.getElementById("decrypted").innerHTML = decrypted;

</script>

</body>

</html>

Website Link
h琀琀p://琀椀tan.csit.rmit.edu.au/~e23700/Lab8/demo1/test_rsa.html

Result Thus RSA Algorithm was implemented successfully.

EX NO : 6 Implementation of Diffie Hellman Key Exchange Algorithm

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

AIM : To write a C++ program to Implement Diffie Hellman key exchange Algorithm.

ALGORITHM :
1. Enter the value of n and g, both are prime numbers.
2. Enter x and y and these are private chosen by the users alice and bob respectively.
3. Alice calculates g x mod n and Bob calculates g y mod n
4. Bob sends the value g y mod n to Alice and alice sends the value g x mod n to Bob.
5. Alice will calculate the shared secret by (g y mod n )x mod n and bob by
(g x mod n )y mod n.
6 . Display the shared secret key.
Program:
#include<conio.h>
#include<iostream.h>
#include<math.h>
int alice(int,int,int);
int bob(int,int,int);
void main()
{
long int g,x,y,a,b,k1,k2,n;
clrscr();
cout<<"\n\t Enter value of n & g";
cin>>n>>g;
cout<<"\n\t Enter value of x & y";
cin>>x>>y;
a=alice(n,g,x);
cout<<"\n\t alice end value:"<<a;
b=bob(n,g,y);
cout<<"\n\t bob end value:"<<b;
k1=alice(n,b,x);
cout<<"\n\t valueof k1 :"<<k1;

k2=alice(n,a,y);
cout<<"\n\t valueof k2 :"<<k2;
getch();
}
int alice(int n,int g,int x)
{

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

long int a,a1;


a1=pow(g,x);
a=a1%n;
return(a);
}
int bob(int n,int g,int y)
{
long int b,b1,k2,t2;
b1=pow(g,y);
b=b1%n;
return(b);
}
Output:

Result:Thus diffie hellman keyexchange was implemented successfully.

Ex No : 7 Calculation of Message Digest of A Text Using SHA-1 Algorithm


AIM: To write a java program to calculate the message digest of a text using the SHA-1
algorithm

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

ALGORITHM :
1. Input the plain text
2. Append padding bits
3. Append length
4. Initialize buffer.
5. Process message in 512-bit (16word)blocks
6. Encrypted in hexa decimal format
7. Display the encrypted text.
Program
import java.security.*;
class JceSha1Test {
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+"\") =");
System.out.println(" "+bytesToHex(output));

input = "abc";
md.update(input.getBytes());
output = md.digest();
System.out.println();
System.out.println("SHA1(\""+input+"\") =");
System.out.println(" "+bytesToHex(output));

input = "abcdefghijklmnopqrstuvwxyz";
md.update(input.getBytes());
output = md.digest();
System.out.println();
System.out.println("SHA1(\""+input+"\") =");
System.out.println(" "+bytesToHex(output));

} 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++) {

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

buf.append(hexDigit[(b[j] >> 4) & 0x0f]);


buf.append(hexDigit[b[j] & 0x0f]);
}
return buf.toString();
}
}

OUTPUT

Result:Thus the SHA-1 algorithm was executed successfully.

Ex No : 8 Implementation of the SIGNATURE SCHEME - Digital Signature


Standard
Aim: To write a java program to implement the Digital Signature Standard.
Algorithm:
1. Input the plain text
2. Calculate the hash value.

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

3. Create the signature with components private key and global public key.
4. Send the msg along with signature.
5. Verify the signature by calculating hash value and public key and global public key.
6. If If the hash value matches signature is verified.
Program:
import java.security.KeyPairGenerator;
import java.security.KeyPair;
import java.security.PublicKey;
import java.security.PrivateKey;
import java.security.Signature;
import java.io.*;
//import java.util;
public class SignatureTest {
private static byte[] sign(String datafile, PrivateKey prvKey, String sigAlg) throws Exception {
Signature sig = Signature.getInstance(sigAlg);
sig.initSign(prvKey);
FileInputStream fis = new FileInputStream(datafile);
byte[] dataBytes = new byte[1024];
int nread = fis.read(dataBytes);
while (nread > 0) {
sig.update(dataBytes, 0, nread);
nread = fis.read(dataBytes);
};
return sig.sign();
}

private static boolean verify(String datafile, PublicKey pubKey, String sigAlg, byte[] sigbytes)
throws Exception {
Signature sig = Signature.getInstance(sigAlg);
sig.initVerify(pubKey);
FileInputStream fis = new FileInputStream(datafile);
byte[] dataBytes = new byte[1024];
int nread = fis.read(dataBytes);
while (nread > 0) {
sig.update(dataBytes, 0, nread);
nread = fis.read(dataBytes);
};
return sig.verify(sigbytes);
}

public static void main(String[] unused) throws Exception {


// Generate a key-pair
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(512); // 512 is the keysize.
KeyPair kp = kpg.generateKeyPair();
PublicKey pubk = kp.getPublic();
PrivateKey prvk = kp.getPrivate();
String datafile = "SignatureTest.java";
byte[] sigbytes = sign(datafile, prvk, "MD5withRSA");
//System.out.println("Signature(in hex):: " + Util.byteArray2Hex(sigbytes));
boolean result = verify(datafile, pubk, "MD5withRSA", sigbytes);
System.out.println("Signature Verification Result = " + result);
//write generated keypair to file
String filename = "keypair";
FileOutputStream fos = null;
ObjectOutputStream out = null;

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

try {
fos = new FileOutputStream(filename);
out = new ObjectOutputStream(fos);
out.writeObject(kp);
out.close();
}
catch(IOException ex) {
ex.printStackTrace();
}
//now try to recover it from the file
FileInputStream fis = null;
ObjectInputStream in = null;
KeyPair newkp = null;
try
{
fis = new FileInputStream(filename);
in = new ObjectInputStream(fis);
newkp = (KeyPair)in.readObject();
in.close();
}
catch(Exception ex) {
ex.printStackTrace();
}

PrivateKey newprvk = newkp.getPrivate();

System.out.println(prvk.toString());
System.out.println(newprvk.toString());
}}
Output:

Result:Thus the DSA algorithm was executed successfully.

EX NO: 9 Demonstration of intrusion detection system (ids)

AIM: To demonstrate intrusion detection system using Snort

INSTALLATION PROCEDURE
1. Download SNORT from snort.org

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

2. Install snort with or without database support.


3. Select all the components and Click Next.
4. Install and Close.
5. Skip the WinPcap driver installation
6. Add the path variable in windows environment variable by selecting new classpath.
7. Create a path variable and point it at snort.exe variable namepath and variable
valuec:\snort\bin.
8. Click OK button and then close all dialog boxes.
9. Open command prompt and type the commands.

STEPS
SNORT can be configured to run in three modes:
1. Sniffer mode 2. Packet Logger mode 3. Network Intrusion Detection System mode
Sniffer mode
i. snort –v Print out the TCP/IP packets header on the screen
ii. snort –vd Show the TCP/IP ICMP header with application data in transit.
Packet Logger mode
i. snort –dev –l c:\log  snort will automatically know to go into packet logger mode, it
collects every packet it sees and places it in log directory.
ii. 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.
iii. snort –l c:\log –b This is binary mode logs everything into a single file.
Network Intrusion Detection System mode
i. snort –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.
ii. 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

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

C:\Snort\bin\ snort –dev –l c:\log

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

C:\Snort\bin\snort –dev –l c:\log –h ipaddress/24

C:\Snort\bin\snort –l c:\log –b

snort –d –h ipaddress/24 –l c:\log –c snort.conf

Result:Thus intrusion detection system was studied using snort.

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

EX. NO: 10 Defeating Malware: Rootkit Hunter


AIM:
To study the installation of rootkits .
STEPS
1. 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.
2. Download Rootkit Tool from GMER website. (www.gmer.net)
3. This displays the Processes, Modules, Services, Files, Registry, RootKit/Malwares,
Autostart, CMD of local host.
4. Select Processes menu and kill any unwanted process if any.
5. Modules menu displays the various system files like .sys, .dll
6. Services menu displays the complete services running with Autostart, Enable,
Disable, System, Boot.
7. Files menu displays full files on Hard-Disk volumes.
8. Registry displays Hkey_Current_user and Hkey_Local_Machine.
9. Rootkits/Malawares scans the local drives selected.
10. Autostart displays the registry base Autostart applications.
11. CMD allows the user to interact with command line utilities or Registry.

EXECUTION

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

Result:Thus root kit hunter installation and its variety of operations were studied
successfully.

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)


lOMoARcPSD|37882674

Downloaded by Sathishkumar Vishwanathan (sathishkbv@gmail.com)

You might also like