Smt. Radhikatai Pandav College of Engineering Nagpur
Smt. Radhikatai Pandav College of Engineering Nagpur
Smt. Radhikatai Pandav College of Engineering Nagpur
SMT. RADHIKATAI
PANDAV COLLEGE
OF ENGINEERING
NAGPUR
DEPARTMENT OF
COMPUTER ENGINEERING
SUBJECT: INFORMATION
ASSURANCE & NETWORK
SECURITY
SEMESTER :VII
YEAR: 2021-22
1
2
List of Practicals
2
3
Practical no.: 1
Aim: Write a program to perform encryption and decryption
using the Caesar Cipher.
ALGORITHMS:
Z = 25.
En(x) = (x + n) mod 26
Dn (x)=(x - n) mod26
3
4
PROGRAM:
CaesarCipher.java
class caesarCipher {
if (Character.isLetter(i)) {
if (Character.isUpperCase(i)) {
} else {
} else {
encoded.append(i);
return encoded.toString();
4
5
}
System.out.println(caesarCipher.encode(msg, 3));
System.out.println(caesarCipher.decode(caesarCipher.encode(msg, 3),
3));
OUTPUT:
------------------------
5
6
Encrypted Message : Dqqd Xqlyhuvlwb
RESULT:
Practical no: 4
6
7
Aim: Write a program to perform encryption and decryption using
the Rail Fence Cipher technique.
DESCRIPTION:
In the rail fence cipher, the plain text is written downwards and
diagonally on
When we reach the top rail, the message is written downwards again
until the whole plaintext
EXAMPLE:
ALGORITHM:
STEP-4: Arrange the characters of the keyword in sorted order and the
corresponding
7
8
STEP-5: Read the characters row wise or column wise in the former
order to get the
cipher text.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
int i,j,k,l;
char a[20],c[20],d[20];
clrscr();
gets(a);
l=strlen(a);
/*Ciphering*/
for(i=0,j=0;i<l;i++)
8
9
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';
printf("\n%s",c);
/*Deciphering*/
if(l%2==0)
k=l/2;
else
k=(l/2)+1;
for(i=0,j=0;i<k;i++)
9
10
d[j]=c[i];
j=j+2;
for(i=k,j=1;i<l;i++)
d[j]=c[i];
j=j+2;
d[l]='\0';
printf("%s",d);
getch();
Output:
10
11
RESULT:
Practical no: 5
11
12
Aim: Write a program to perform encryption and decryption using Columnar Transposition
Cipher technique.
LGORITHM:
1. Consider the plain text hello world, and let us apply the simple columnar
hell
owor
ld
2. The plain text characters are placed horizontally and the cipher text is
3. Now, the receiver has to use the same table to decrypt the cipher text to
plain text.
PROGRAM:
TransCipher.java
import java.util.*;
class TransCipher {
String pl = sc.nextLine();
sc.close();
String s = "";
12
13
int start = 0;
s = s + pl.substring(start, i);
start = i + 1;
s = s + pl.substring(start);
System.out.print(s);
System.out.println();
int k = s.length();
int l = 0;
int col = 4;
if (l < k) {
ch[i][j] = s.charAt(l);
l++;
} else {
13
14
ch[i][j] = '#';
// arranged in matrix
trans[j][i] = ch[i][j];
System.out.print(trans[i][j]);
// display
System.out.println();
OUTPUT:
14
15
Security Lab
SecurityLab
Sreictuy
RESULT:
Thus the java program for Row and Column Transposition Technique has
Practical No. 06
Aim :Write a program to perform encryption and decryption using data Encryption Standard
(DES) algorithm.
DESCRIPTION:
DES is a symmetric encryption system that uses 64-bit blocks, 8 bits of which are
used for parity checks. The key therefore has a "useful" length of 56 bits, which means that
only 56 bits are actually used in the algorithm. The algorithm involves carrying out
combinations, substitutions and permutations between the text to be encrypted and the key,
while making sure the operations can be performed in both directions. The key is ciphered on
64 bits and made of 16 blocks of 4 bits, generally denoted k1 to k16. Given that "only" 56 bits
are actually used for encrypting, there can be 256 different keys.
Breakdown of the blocks into two parts: left and right, named L and R
15
16
Re-joining of the left and right parts then inverse initial permutation
ALGORITHM:
STEP-2: Split it into two 32-bit blocks and store it in two different arrays.
STEP-4: The output obtained is stored as the second 32-bit sequence and the original
STEP-5: Thus the encrypted 64-bit cipher text is obtained in this way. Repeat the same
PROGRAM:
DES.java
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.util.Random ;
class DES {
String skeyString;
16
17
String inputMessage,encryptedData,decryptedMessage;
public DES()
try
generateSymmetricKey();
inputMessage=JOptionPane.showInputDialog(null,"Enter
message to encrypt");
JOptionPane.showMessageDialog(null,"Encrypted Data
"+"\n"+encryptedData);
System.out.println("Decrypted message
"+decryptedMessage);
JOptionPane.showMessageDialog(null,"Decrypted Data
"+"\n"+decryptedMessage);
catch(Exception e)
17
18
{
System.out.println(e);
void generateSymmetricKey() {
try {
skey=getRawKey(knumb);
catch(Exception e)
System.out.println(e);
18
19
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
sr.setSeed(seed);
kgen.init(56, sr);
raw = skey.getEncoded();
return raw;
Exception {
"DES");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
return encrypted;
throws Exception
"DES");
19
20
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
return decrypted;
OUTPUT:
20
21
RESULT:
Thus the data encryption standard algorithm had been implemented successfully
Practical No.07
is an asymmetric cryptographic algorithm. Asymmetric means that there are two different
keys. This is also called public key cryptography, because one of them can be given to
everyone. A basic principle behind RSA is the observation that it is practical to find three
very large positive integers e, d and n such that with modular exponentiation for all
integer m:
(me
= m (mod n)
The public key is represented by the integers n and e; and, the private key, by the
21
22
integer d. m represents the message. RSA involves a public key and a private key. The public
key can be known by everyone and is used for encrypting messages. The intention is that
messages encrypted with the public key can only be decrypted in a reasonable amount of
ALGORITHM:
* mod n.
PROGRAM: (RSA)
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
long int
p,q,n,t,flag,e[100],d[100],temp[100],j,m[100],en[100],i;
char msg[100];
22
23
int prime(long int);
void ce();
void encrypt();
void decrypt();
void main()
clrscr();
scanf("%d",&p);
flag=prime(p);
if(flag==0)
printf("\nWRONG INPUT\n");
getch();
scanf("%d",&q);
flag=prime(q);
if(flag==0||p==q)
printf("\nWRONG INPUT\n");
23
24
getch();
printf("\nENTER MESSAGE\n");
fflush(stdin);
scanf("%s",msg);
for(i=0;msg[i]!=NULL;i++)
m[i]=msg[i];
n=p*q;
t=(p-1)*(q-1);
ce();
for(i=0;i<j-1;i++)
printf("\n%ld\t%ld",e[i],d[i]);
encrypt();
decrypt();
getch();
int i;
j=sqrt(pr);
for(i=2;i<=j;i++)
24
25
{
if(pr%i==0)
return 0;
return 1;
void ce()
int k;
k=0;
for(i=2;i<t;i++)
if(t%i==0)
continue;
flag=prime(i);
if(flag==1&&i!=p&&i!=q)
e[k]=i;
flag=cd(e[k]);
if(flag>0)
d[k]=flag;
25
26
k++;
if(k==99)
break;
}}}
while(1)
k=k+t;
if(k%x==0)
return(k/x);
}}
void encrypt() {
i=0;
len=strlen(msg);
while(i!=len) {
pt=m[i];
pt=pt-96;
k=1;
26
27
for(j=0;j<key;j++)
{ k=k*pt;
k=k%n;
temp[i]=k;
ct=k+96;
en[i]=ct;
i++;
en[i]=-1;
for(i=0;en[i]!=-1;i++)
printf("%c",en[i]);
void decrypt()
i=0;
while(en[i]!=-1)
ct=temp[i];
k=1;
27
28
for(j=0;j<key;j++)
k=k*ct;
k=k%n;
pt=k+96;
m[i]=pt;
i++;
m[i]=-1;
for(i=0;m[i]!=-1;i++)
printf("%c",m[i]);
RESULT:
Thus the C program to implement RSA encryption technique had been implemented
successfully.
28
29
Practical No. 8
DESCRIPTION:
this algorithm works is that for a message of size < 264 bits it
computes a 160-bit condensed
29
30
such as SHA-1 is used to calculate an alphanumeric string that
serves as the cryptographic
EXAMPLE:
ALGORITHM:
STEP-5: The block A is shifted right by ‘s’ times and permuted with the result of step-4.
STEP-6: Then it is permuted with a weight value and then with some other key pair and
STEP-7: Block A is taken as the second block and the block B is shifted by ‘s’ times and
STEP-8: The blocks C and D are taken as the block D and E for the final output.
import java.security.*;
30
31
try {
MessageDigest md = MessageDigest.getInstance("SHA1");
md.update(input.getBytes());
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();
31
32
System.out.println("SHA1(\"" +input+"\") = "
+bytesToHex(output));
System.out.println(""); }
catch (Exception e) {
return buf.toString(); }
OUTPUT:
RESULT:
Practical No. 9
32
33
Aim: Write a program to implement Message Digest -5.
DESCRIPTION:
EXAMPLE:
ALGORITHM:
IMPLEMENTATION OF MD5
MD5 processes a variable-length message into a fixed-length output of 128 bits. The
the end of the message. This is followed by as many zeros as are required to bring the length
of the message up to 64 bits less than a multiple of 512. The remaining bits are filled up
64 bits representing the length of the original message, modulo 264.The main MD5 algorithm
initialized to certain fixed constants. The main algorithm then uses each 512
33
34
Divide into four blocks of 32-bits named as A, B, C and D.
padded s
34
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: