CO 405 Information and Network Security Practical File

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 47

CO 405

Information and Network Security


Practical File

Delhi Technological University

Submitted to: Submitted by:


Mr. Rahul Gupta Avneesh Saraswat
Assistant Professor 2k17/Co/084
S.no Practical Date Signature

1 To implement Caesar cipher encryption. Encryption: 2/09/2020


Replace each plain text letter with one a fixed number of
places down the alphabet. Decryption: Replace each cipher
text letter with one a fixed number of places up the alphabet.
2 To implement Monoalphabetic decryption. 9/09/2020

3 To implement Play fair cipher encryption-decryption 16/09/2020

4 To implement Polyalphabetic cipher encryption decryption. 23/09/2020


5 To implement Hill- cipher encryption decryption 30/09/2020

6 To implement S-DES sub key Generation 7/10/2020

7 To implement Diffie-Hallman key exchange algorithm. 14/10/2020


8 To implement RSA encryption and decryption. 21/10/2020
9 Write a program to generate SHA-1 hash. 28/10/2020
10 To implement the Digital Signature Algorithm. 04/11/2020
11 11/11/2020
Perform various encryption-decryption techniques with
Cryptool

12 Study and use the Wireshark for the various network 18/11/2020
protocols.
Practical 1

Aim: To implement Caesar cipher encryption. Encryption: Replace each plain text letter with
one a fixed number of places down the alphabet. Decryption: Replace each cipher text letter
with one a fixed number of places up the alphabet.
Introduction: The Caesar Cipher technique is one of the earliest and simplest method of
encryption technique. It’s simply a type of substitution cipher, i.e., each letter of a given text
is replaced by a letter some fixed number of positions down the alphabet. For example with a
shift of 1, A would be replaced by B, B would become C, and so on. The method is
apparently named after Julius Caesar, who apparently used it to communicate with his
officials.
Thus to cipher a given text we need an integer value, known as shift which indicates the
number of position each letter of the text has been moved down.
The encryption can be represented using modular arithmetic by first transforming the letters
into numbers, according to the scheme, A = 0, B = 1… Z = 25.
Implementation:
Encryption:
#include<stdio.h>
int main()
{
char message[100], ch;
int i, key;

printf("Enter a message to encrypt: ");


gets(message);
printf("Enter key: ");
scanf("%d", &key);

for(i = 0; message[i] != '\0'; ++i){


ch = message[i];

if(ch >= 'a' && ch <= 'z'){


ch = ch + key;

if(ch > 'z'){


ch = ch - 'z' + 'a' - 1;
}

message[i] = ch;
}
else if(ch >= 'A' && ch <= 'Z'){
ch = ch + key;

if(ch > 'Z'){


ch = ch - 'Z' + 'A' - 1;
}

message[i] = ch;
}
}

printf("Encrypted message: %s", message);

return 0;
}
Decryption:
#include<stdio.h>
 
int main()
{
char message[100], ch;
int i, key;

printf("Enter a message to decrypt: ");


gets(message);
printf("Enter key: ");
scanf("%d", &key);

for(i = 0; message[i] != '\0'; ++i){


ch = message[i];

if(ch >= 'a' && ch <= 'z'){


ch = ch - key;
if(ch < 'a'){
ch = ch + 'z' - 'a' + 1;
}

message[i] = ch;
}
else if(ch >= 'A' && ch <= 'Z'){
ch = ch - key;

if(ch < 'A'){


ch = ch + 'Z' - 'A' + 1;
}

message[i] = ch;
}
}

printf("Decrypted message: %s", message);

return 0;
}

Output:

Conclusion/ learning Outcome:


Thus we have learn how to successfully implement Caesar cipher encryption in C language.
Practical 2
Aim: To implement Monoalphabetic decryption.
Introduction: Encrypting and Decrypting works exactly the same for all monoalphabetic
ciphers. Encryption/Decryption: Every letter in the alphabet is represented by exactly one
other letter in the key.
A monoalphabetic cipher is any cipher in which the letters of the plain text are mapped to
cipher text letters based on a single alphabetic key. Examples of monoalphabetic ciphers
would include the Caesar-shift cipher, where each letter is shifted based on a numeric key,
and the atbash cipher, where each letter is mapped to the letter symmetric to it about the
center of the alphabet.
Implementation:
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char pt[52]={'A','B','C','D','E','F','G','H','I','J','K',
'L','M','N','O','P','Q','R','S','T','U','V',
'W','X','Y','Z','a','b','c','d','e','f','g','h',
'i','j','k','l','m','n','o','p','q','r','s','t',
'u','v','w','x','y','z'};
char ct[52]={'Z','Y','X','W','V','U','T','S','R','Q','P','O',
'N','M','L','K','J','I','H','G','F','E','D','C',
'B','A','z','y','x','w','v','u','t','s','r','q','p','o',
'n','m','l','k','j','i','h','g','f','e','d','c','b','a'};
char p[20]={'\0'},c[20]={'\0'},r[20]={'\0'};
int i,j;
printf("\n enter the plain text:");
gets(p);
for(i=0;i<strlen(p);i++)
{
for(j=0;j<52;j++)
{
if(pt[j]==p[i])
{
c[i]=ct[j];
}
}
}
printf("\n cipher text is: %s",c);
for(i=0;i<strlen(c);i++)
{
for(j=0;j<52;j++)
{
if(ct[j]==c[i])
{
r[i]=pt[j];
}
}
}
printf("\n \n plain text is: %s",r);
}
Output:

Conclusion and Learning:


Thus we have finally learnt how to successfully implement Monoalphabetic Decryption.
Practical 3
Aim: To implement Play fair cipher encryption-decryption.
Introduction: Play fair is one of the popular cryptographic software security
algorithms. This technique encrypts pairs of letters at a time and generates more secure
encrypted text compare to the simple substitution cipher like Caesar.
The Play fair cipher was the first practical digraph substitution cipher. The scheme was
invented in 1854 by Charles Wheatstone but was named after Lord Play fair who promoted
the use of the cipher. In playfair cipher unlike traditional cipher we encrypt a pair of
alphabets (digraphs) instead of a single alphabet.
It was used for tactical purposes by British forces in the Second Boer War and in World War
I and for the same purpose by the Australians during World War II. This was because Play
fair is reasonably fast to use and requires no special equipment.
Implementation:
Encryption:
#include<stdio.h>
int main(){

  char arr[5][5]={"MONAR","CHYBD","EFGIK","LPQST","UVWXZ"};
  char pt[10];

  int i, j, r1=0, r2=0, c1=0, c2=0;


  printf("Playfair Keymatrix\n==================\n");
  for(i=0; i<5; i++)
 {
  for(j=0; j<5; j++)
printf("%c ", arr[i][j]);
  printf("\n");
 }

  printf("Enter your plain text:");


  scanf("%s",pt);
  printf("Your plain text = %s", pt);

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


 {
  for(j=0; j<5; j++)
  {
    if(arr[i][j] == pt[0])
{
r1=i; c1=j;
}
if(arr[i][j] == pt[1])
{
r2=i; c2=j;
}
  }
 }
  if(r1==r2) //when both characters in same row
 {
  if(c2==4) //for char in last column
printf("Ciphertext = %c%c \n", arr[r1][c1+1], arr[r2][0]); 
  else
printf("Ciphertext = %c%c \n", arr[r1][c1+1], arr[r2][c2+1]);
 }
  if(c1==c2)//when both characters in same column
 {
  if(r2==4) //for char in last row
printf("Ciphertext = %c%c \n", arr[r1+1][c1], arr[0][c2]); 
  else
printf("Ciphertext = %c%c \n", arr[r1+1][c1], arr[r2+1][c2]); 
 }
  //when characters are not in a same row and column
  if(r1 != r2 && c1 != c2) 
 {
  printf("\nCiphertext = %c%c \n", arr[r1][c2], arr[r2][c1]); 
 }
  return 0;
}
Decryption:
#include<stdio.h>
int main()
{ char arr[5][5]={"MONAR","CHYBD","EFGIK","LPQST","UVWXZ"};
char ct[10];
int i, j, r1=0, r2=0, c1=0, c2=0;
printf("Plaifair Keymatrix\n=================\n");
for(i=0; i<5; i++)
{
for(j=0; j<5; j++)
printf("%c ", arr[i][j]);
printf("\n");
}
printf("Enter your cipher text:");
scanf("%s",ct);
printf("Your cipher text is %s\n", ct);
for(i=0; i<5; i++)
{
for(j=0; j<5; j++)
{
if(arr[i][j] == ct[0])
{
r1=i; c1=j;
}
if(arr[i][j] == ct[1])
{
r2=i; c2=j;
}
}
}
if(r1==r2) //Rule2-when both characters in same row
{
if(c2==0) //for char in last column
printf("Plaintext = %c%c \n", arr[r1][c1-1], arr[r2][4]);
else
printf("Plaintext = %c%c \n", arr[r1][c1-1], arr[r2][c2-1]);
}
if(c1==c2)//Rule3- when both characters in same column
{
if(r2==0) //for char in last row
printf("Plaintext = %c%c \n", arr[r1-1][c1], arr[4][c2]);
else
printf("Plaintext = %c%c \n", arr[r1-1][c1], arr[r2-1][c2]);
}
//Rule4 when characters are not in a same row and column
if(r1 != r2 && c1 != c2)
{
printf("Plaintext = %c%c \n", arr[r1][c2], arr[r2][c1]);
}
return 0;
}
Output:
Encryption:

Decryption:
Conclusion / learning and finding:
Thus we have learn how to successfully implement Play Fair cipher encryption and
decryption.
Practical 4
Aim: To implement Polyalphabetic cipher encryption decryption.
Introduction: A polyalphabetic cipher is any cipher based on substitution, using multiple
substitution alphabets. The Vigenère cipher is probably the best-known example of a
polyalphabetic cipher, though it is a simplified special case. The Enigma machine is more
complex but is still fundamentally a polyalphabetic substitution cipher.
Implementation:
Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char msg[30],key[30],k[20],ct[20],pt[20];
int lenm,lenk,i,j;
clrscr();

printf("Enter Message : ");


gets(msg);
printf("Enter Key : ");
gets(key);
lenm=strlen(msg);
lenk=strlen(key);
for(i=0;i<lenm;i++,j++)
{
if(j==lenk)
{
j=0;
}
k[i]=key[j];
}
for(i=0;i<lenm;i++)
{
ct[i]=((msg[i]+k[i])%26)+'A';
}
ct[i]='\0';
for(i=0;i<lenm;i++)
{
pt[i]=(((ct[i]-k[i])+26)%26)+'A';
}
pt[i]='\0';
printf("\nEncrypted Message : %s", ct);
printf("\nDecrypted Message : %s", pt);
getch();
}
Output:

Conclusion:
Thus we have learn how to implement Polyalphabetic cipher encryption and decryption.
Based on substitution, using multiple substitution Alphabets.
Practical 5
Aim: To implement Hill- cipher encryption decryption.
Introduction: Hill cipher is a polygraphic substitution cipher based on linear algebra.Each
letter is represented by a number modulo 26. Often the simple scheme A = 0, B = 1….. Z =
25 is used, but this is not an essential feature of the cipher. To encrypt a message, each block
of n letters (considered as an n-component vector) is multiplied by an invertible n × n matrix,
against modulus 26. To decrypt the message, each block is multiplied by the inverse of the
matrix used for encryption.
Implementation:
Code:
#include<iostream>
#include<math.h>
using namespace std;
float en[3][1], de[3][1], a[3][3], b[3][3], msg[3][1], m[3][3];
void getKeyMatrix() { //get key and message from user
int i, j;
char mes[3];
cout<<"Enter 3x3 matrix for key (should have inverse):\n";
for(i = 0; i < 3; i++)
for(j = 0; j < 3; j++) {
cin>>a[i][j];
m[i][j] = a[i][j];
}
cout<<"\nEnter a string of 3 letter(use A through Z): ";
cin>>mes;
for(i = 0; i < 3; i++)
msg[i][0] = mes[i] - 65;
}
void encrypt() { //encrypts the message
int i, j, k;
for(i = 0; i < 3; i++)
for(j = 0; j < 1; j++)
for(k = 0; k < 3; k++)
en[i][j] = en[i][j] + a[i][k] * msg[k][j];
cout<<"\nEncrypted string is: ";
for(i = 0; i < 3; i++)
cout<<(char)(fmod(en[i][0], 26) + 65);
}
void inversematrix() {
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 = m[i][k];
q = m[k][k];
for(j = 0; j < 3; j++) {
if(i != k) {
m[i][j] = m[i][j]*q - p*m[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] / m[i][i];
cout<<"\n\nInverse Matrix is:\n";
for(i = 0; i < 3; i++) {
for(j = 0; j < 3; j++)
cout<<b[i][j]<<" ";
cout<<"\n";
}
}
void decrypt()
{ int i, j, k;
inversematrix();
for(i = 0; i < 3; i++)
for(j = 0; j < 1; j++)
for(k = 0; k < 3; k++)
de[i][j] = de[i][j] + b[i][k] * en[k][j];
cout<<"\nDecrypted string is: ";
for(i = 0; i < 3; i++)
cout<<(char)(fmod(de[i][0], 26) + 65);
cout<<"\n";
}
int main() {
getKeyMatrix();
encrypt();
decrypt();
}
Output:

Learning and Finding: We have learn how to successfully implement hill cipher encryption
and decryption.
Practical 6
Aim: To implement S-DES sub key Generation
Introduction: DES is a block cipher, and encrypts data in blocks of size of 64 bit each,
means 64 bits of plain text goes as the input to DES, which produces 64 bits of cipher text.
The same algorithm and key are used for encryption and decryption, with minor differences.
The key length is 56 bits. The basic idea is show in figure.
DES is based on the two fundamental attributes of cryptography: substitution (also called as
confusion) and transposition (also called as diffusion). DES consists of 16 steps, each of
which is called as a round. Each round performs the steps of substitution and transposition.
Let us now discuss the broad-level steps in DES.
Implementation:
Code:
#include<stdio.h>
int main()
{
int i, cnt=0, p8[8]={6,7,8,9,1,2,3,4};
int p10[10]={6,7,8,9,10,1,2,3,4,5};

char input[11], k1[10], k2[10], temp[11];


char LS1[5], LS2[5];
//k1, k2 are for storing interim keys
//p8 and p10 are for storing permutation key

//Read 10 bits from user...


printf("Enter 10 bits input:");
scanf("%s",input);
input[10]='\0';

//Applying p10...
for(i=0; i<10; i++)
{
cnt = p10[i];
temp[i] = input[cnt-1];
}
temp[i]='\0';
printf("\nYour p10 key is    :");
for(i=0; i<10; i++)
{ printf("%d,",p10[i]); }

printf("\nBits after p10     :");


puts(temp);
//Performing LS-1 on first half of temp
for(i=0; i<5; i++)
{
if(i==4)
temp[i]=temp[0];
else
temp[i]=temp[i+1];
}
//Performing LS-1 on second half of temp
for(i=5; i<10; i++)
{
if(i==9)
temp[i]=temp[5];
else
temp[i]=temp[i+1];
}
printf("Output after LS-1  :");
puts(temp);

printf("\nYour p8 key is     :");


for(i=0; i<8; i++)
{ printf("%d,",p8[i]); }

//Applying p8...
for(i=0; i<8; i++)
{
cnt = p8[i];
k1[i] = temp[cnt-1];
}
printf("\nYour key k1 is     :");
puts(k1);
}
Output:

Finding and Learning: Thus we have learn how to successfully implement S-DES subkey
generation in C.
Practical 7
Aim: To implement Diffie-Hallman key exchange algorithm.
Introduction: The Diffie-Hellman algorithm is being used to establish a shared secret that
can be used for secret communications while exchanging data over a public network using
the elliptic curve to generate points and get the secret key using the parameters. 
 
 For the sake of simplicity and practical implementation of the algorithm, we will
consider only 4 variables one prime P and G (a primitive root of P) and two private
values a and b.
 P and G are both publicly available numbers. Users (say Alice and Bob) pick private
values a and b and they generate a key and exchange it publicly, the opposite person
received the key and from that generates a secret key after which they have the same
secret key to encrypt.
Implementation:
Code:
#include<stdio.h>
#include<math.h>

// Power function to return value of a ^ b mod P


long long int power(long long int a, long long int b,
long long int P)
{
if (b == 1)
return a;

else
return (((long long int)pow(a, b)) % P);
}

//Driver program
int main()
{
long long int P, G, x, a, y, b, ka, kb;
// Both the persons will be agreed upon the
// public keys G and P
P = 23; // A prime number P is taken
printf("The value of P : %lld\n", P);

G = 9; // A primitve root for P, G is taken


printf("The value of G : %lld\n\n", G);

// Alice will choose the private key a


a = 4; // a is the chosen private key
printf("The private key a for Alice : %lld\n", a);
x = power(G, a, P); // gets the generated key

// Bob will choose the private key b


b = 3; // b is the chosen private key
printf("The private key b for Bob : %lld\n\n", b);
y = power(G, b, P); // gets the generated key

// Generating the secret key after the exchange


// of keys
ka = power(y, a, P); // Secret key for Alice
kb = power(x, b, P); // Secret key for Bob

printf("Secret key for the Alice is : %lld\n", ka);


printf("Secret Key for the Bob is : %lld\n", kb);

return 0;
}
Output:

Finding and learning: Thus we have learn how to successfully implement Diffie-Hallman
key exchange algorithm.
Practical 8
Aim: To implement RSA encryption and decryption.
Introduction: Under RSA encryption, messages are encrypted with a code called a public
key, which can be shared openly. Due to some distinct mathematical properties of the RSA
algorithm, once a message has been encrypted with the public key, it can only be decrypted
by another key, known as the private key. Each RSA user has a key pair consisting of their
public and private keys. As the name suggests, the private key must be kept secret.
Public key encryption schemes differ from symmetric-key encryption, where both the
encryption and decryption process use the same private key. These differences make public
key encryption like RSA useful for communicating in situations where there has been no
opportunity to safely distribute keys beforehand.
Symmetric-key algorithms have their own applications, such as encrypting data for personal
use, or for when there are secure channels that the private keys can be shared over.
Implementation:
Code:
#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];
int prime(long int);
void ce();
long int cd(long int);
void encrypt();
void decrypt();
void main()
{ clrscr();

printf("\nENTER FIRST PRIME NUMBER\n");


scanf("%d",&p);
flag=prime(p);
if(flag==0) {
printf("\nWRONG INPUT\n");
getch();
exit(1);
}
printf("\nENTER ANOTHER PRIME NUMBER\n");
scanf("%d",&q);
flag=prime(q);
if(flag==0||p==q) {
printf("\nWRONG INPUT\n");
getch();
exit(1);
}
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();
printf("\nPOSSIBLE VALUES OF e AND d ARE\n");
for (i=0;i<j-1;i++)
printf("\n%ld\t%ld",e[i],d[i]);
encrypt();
decrypt();
getch();
}
int prime(long int pr) {
int i;
j=sqrt(pr);
for (i=2;i<=j;i++) {
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;
k++;
}
if(k==99)
break;
}
}
}
long int cd(long int x) {
long int k=1;
while(1) {
k=k+t;
if(k%x==0)
return(k/x);
}
}
void encrypt() {
long int pt,ct,key=e[0],k,len;
i=0;
len=strlen(msg);
while(i!=len) {
pt=m[i];
pt=pt-96;
k=1;
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;
printf("\nTHE ENCRYPTED MESSAGE IS\n");
for (i=0;en[i]!=-1;i++)
printf("%c",en[i]);
}
void decrypt() {
long int pt,ct,key=d[0],k;
i=0;
while(en[i]!=-1) {
ct=temp[i];
k=1;
for (j=0;j<key;j++) {
k=k*ct;
k=k%n;
}
pt=k+96;
m[i]=pt;
i++;
}
m[i]=-1;
printf("\nTHE DECRYPTED MESSAGE IS\n");
for (i=0;m[i]!=-1;i++)
printf("%c",m[i]);
}
Output:

Finding and learning: thus we have learn how to successfully implement RSA encryption
and decryption algorithm.
Practical 9
Aim: Write a program to generate SHA-1 hash.
Introduction: SHA-1 or Secure Hash Algorithm 1 is a cryptographic hash function which
takes an input and produces a 160-bit (20-byte) hash value. This hash value is known as a
message digest. This message digest is usually then rendered as a hexadecimal number which
is 40 digits long. It is a U.S. Federal Information Processing Standard and was designed by
the United States National Security Agency. In cryptography, SHA-1 (Secure Hash
Algorithm 1) is a cryptographic hash function which takes an input and produces a 160-bit
(20-byte) hash value known as a message digest – typically rendered as a hexadecimal
number, 40 digits long. It was designed by the United States National Security Agency, and is
a U.S. Federal Information Processing Standard.
Since 2005, SHA-1 has not been considered secure against well-funded opponents; as of
2010 many organizations have recommended its replacement. NIST formally deprecated use
of SHA-1 in 2011 and disallowed its use for digital signatures in 2013. As of 2020, chosen-
prefix attacks against SHA-1 are practical. As such, it is recommended to remove SHA-1
from products as soon as possible and instead use SHA-2 or SHA-3. Replacing SHA-1 is
urgent where it is used for digital signatures.

All major web browser vendors ceased acceptance of SHA-1 SSL certificates in 2017. In
February 2017, CWI Amsterdam and Google announced they had performed a collision
attack against SHA-1, publishing two dissimilar PDF files which produced the same SHA-1
hash. But SHA-1 is still secure for HMAC.
Implementation:
Code:
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class GFG {


public static String encryptThisString(String input)
{
try {
// getInstance() method is called with algorithm SHA-1
MessageDigest md = MessageDigest.getInstance("SHA-1");

// digest() method is called


// to calculate message digest of the input string
// returned as array of byte
byte[] messageDigest = md.digest(input.getBytes());

// Convert byte array into signum representation


BigInteger no = new BigInteger(1, messageDigest);

// Convert message digest into hex value


String hashtext = no.toString(16);

// Add preceding 0s to make it 32 bit


while (hashtext.length() < 32) {
hashtext = "0" + hashtext;
}

// return the HashText


return hashtext;
}

// For specifying wrong message digest algorithms


catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}

// Driver code
public static void main(String args[]) throws

NoSuchAlgorithmException
{
System.out.println("HashCode Generated by SHA-1 for: ");

String s1 = "Avneesh";
System.out.println("\n" + s1 + " : " + encryptThisString(s1));

String s2 = "Information and Network Security";


System.out.println("\n" + s2 + " : " + encryptThisString(s2));
}
}
Output:

Finding and learning: Thus we have learn how to successfully write a program to generate
SHA-1 Hash.
Practical 10
Aim: To implement the Digital Signature Algorithm.

Introduction: Digital Signature Algorithm (DSA) is one of the Federal Information


Processing Standard for making digital signatures depends on the mathematical concept or
we can say the formulas of modular exponentiation and the discrete logarithm problem to
cryptograph the signature digitally in this algorithm.

It is Digital signatures are the public-key primitives of message authentication in


cryptography. In fact, in the physical world, it is common to use handwritten signatures on
handwritten or typed messages at this time. Mainly, they are used to bind signatory to the
message to secure the message.

Therefore, a digital signature is a technique that binds a person or entity to the digital data of
the signature. Now, this will binding can be independently verified by the receiver as well as
any third party to access that data.

Here, Digital signature is a cryptographic value that is calculated from the data and a secret
key known only by the signer or the person whose signature is that.

In fact, in the real world, the receiver of message needs assurance that the message belongs to
the sender and he should not be able to hack the origination of that message for misuse or
anything. Their requirement is very crucial in business applications or any other things since
the likelihood of a dispute over exchanged data is very high to secure that data.

Implementation:
Code:
package java_cryptography;
// Imports
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Signature;
import java.util.Scanner;

import javax.xml.bind.DatatypeConverter;

public class Digital_Signature {


// Signing Algorithm
private static final String
SIGNING_ALGORITHM
= "SHA256withRSA";
private static final String RSA = "RSA";
private static Scanner sc;

// Function to implement Digital signature


// using SHA256 and RSA algorithm
// by passing private key.
public static byte[] Create_Digital_Signature(
byte[] input,
PrivateKey Key)
throws Exception
{
Signature signature
= Signature.getInstance(
SIGNING_ALGORITHM);
signature.initSign(Key);
signature.update(input);
return signature.sign();
}

// Generating the asymmetric key pair


// using SecureRandom class
// functions and RSA algorithm.
public static KeyPair Generate_RSA_KeyPair()
throws Exception
{
SecureRandom secureRandom
= new SecureRandom();
KeyPairGenerator keyPairGenerator
= KeyPairGenerator
.getInstance(RSA);
keyPairGenerator
.initialize(
2048, secureRandom);
return keyPairGenerator
.generateKeyPair();
}

// Function for Verification of the


// digital signature by using the public key
public static boolean
Verify_Digital_Signature(
byte[] input,
byte[] signatureToVerify,
PublicKey key)
throws Exception
{
Signature signature
= Signature.getInstance(
SIGNING_ALGORITHM);
signature.initVerify(key);
signature.update(input);
return signature
.verify(signatureToVerify);
}
// Driver Code
public static void main(String args[])
throws Exception
{

String input
= "Avneesh";
KeyPair keyPair
= Generate_RSA_KeyPair();

// Function Call
byte[] signature
= Create_Digital_Signature(
input.getBytes(),
keyPair.getPrivate());

System.out.println(
"Signature Value:\n "
+ DatatypeConverter
.printHexBinary(signature));

System.out.println(
"Verification: "
+ Verify_Digital_Signature(
input.getBytes(),
signature, keyPair.getPublic()));
}
}
Output:
Finding and learning: Thus we have learn how to successfully implement DSA (Digital
Signature Algorithm).
Practical 11
Aim: Perform various encryption-decryption techniques with Cryptool.

Introduction: Cryptool is an open-source and freeware program that can be used in various
aspects of cryptographic and cryptanalytic concepts. There are no other programs like it
available over the internet where you can analyze the encryption and decryption of various
algorithms. This tools provides graphical interface, better documentation to achieve the
encryption and decryption, bundles of analytic tools, and several algorithms. Here are some
features of cryptool:

 A freeware program with graphical user interface (GUI).


 A tool for applying and analyzing cryptographic algorithms.
 With extensive online help, it's understandable without deep crypto knowledge.
 Contains nearly all state-of-the-art crypto algorithms.
 “Playful” introduction to modern and classical cryptography.
 Not a “hacker" tool.

 Implementation:

Encryption and Decryption of Caesar Cipher


Here, we will implement an encryption and decryption of Caesar Cipher, which is actually a
substitution method of cryptography. The Caesar Cipher involves replacing each letter of the
alphabet with a letter – placed down or up according to the key given.

To start with the process you have to move to the Encrypt/Decrypt tab of the program. There,
you will find Symmetric (Classic) tab - Choose Caesar Cipher. For further information, you
can get guided by the image below.

Encrypt/Decrypt of Cryptool

In encryption, we are replacing the plaintext letter with the 3rd letter of the alphabet that is if
“A” is our plaintext character, then the Cipher text will be “D”.
Caesar Cipher

So, if I give “Monarchy” as plaintext in Caesar Cipher, it will show me the encryption, as
shown in the below image.

Caesar Cipher Encryption

Encryption and Decryption of Playfair


Again, we have to move to Encrypt/Decrypt - Symmetric - Playfair Cipher and perform the
encryption part. We are putting the same plaintext – MONARCHY.
Playfair Cipher

So, when we press the encrypt button, we will get the Ciphertext  – “ONARMDYB”.

Playfair Encryption

Encryption and Decryption of Hill Cipher

Again, we have to move to Encrypt/Decrypt - Symmetric - Hill Cipher and perform the
encryption part. We are putting the plaintext as – DRGREERROCKS and assuming that the
program gives us the Ciphertext as – FZIFTOTBXGPO.
Hill Cipher

So, when we press the encrypt button, we will get the Ciphertext – “FZIFTOTBXGPO”.

Hill Cipher Encryption

Encryption and Decryption of Vigener Cipher

Again, we have to move to Encrypt/Decrypt - Symmetric - Vigener Cipher and perform the
encryption part. We are putting the plaintext as –
MICHIGANTECHNOLOGICALUNIVERSITY and assuming that the program gives us the
Ciphertext as – TWWNPZOAAS…..,with the help of key as – HOUGHTON.
Vigener Cipher

So, when we press the encrypt button, we will get the Ciphertext somewhat like –
“TWWNPZOAASWNUHZBNWWGSNBVCSLYPMM”.

Vigener Cipher Encryption

Encryption and Decryption of Railfence Cipher

Again, we have to move to Encrypt/Decrypt - Symmetric - Railfence Cipher and perform the
encryption part. We are putting the plaintext as – UNBREAKABLE and assuming that the
program gives us the Ciphertext as – UEBNRAALBKE…..,with the help of key as – 3.
Railfence Cipher

So, when we press the encrypt button, we will get the Ciphertext like – “UEBNRAALBKE”.

Railfence Cipher Encryption

Learning and Finding: Thus we have studied different techniques for implementing different
encryption and decryption in Cryptool.
Practical 12
Aim: Study and use the Wireshark for the various network protocols.

Introduction: Wireshark lets the user put network interface controllers into promiscuous
Mode (if supported by the network interface controller), so they can see all the traffic visible on that
interface including unicast traffic not sent to that network interface controller's MAC address.
However, when capturing with a packet analyzer in promiscuous mode on a port on a network
switch, not all traffic through the switch is necessarily sent to the port where the capture is done, so
capturing in promiscuous mode is not necessarily sufficient to see all network traffic. Port mirroring
or various network taps extend capture to any point on the network. Simple passive taps are
extremely resistant to tampering.

On GNU/Linux, BSD, and macOS, with libpcap 1.0.0 or later, Wiresha rk 1.4 and later can also put
wireless network interface controllers into monitor mode.

If a remote machine captures packets and sends the captured packets to a machine running
Wireshark using the TZSP protocol or the protocol used by
Omni Peek, Wireshark dissects those packets, so it can analyze packets captured on a remote
machine at the time that they are captured.
Wireshark:
Learning: Explored the Wireshark tool for networking purposes.

You might also like