INS File 2
INS File 2
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;
message[i] = ch;
}
else if(ch >= 'A' && ch <= 'Z'){
ch = ch + key;
message[i] = ch;
}
}
return 0;
}
Decryption:
#include<stdio.h>
int main()
{
char message[100], ch;
int i, key;
message[i] = ch;
}
else if(ch >= 'A' && ch <= 'Z'){
ch = ch - key;
message[i] = ch;
}
}
return 0;
}
Output:
char arr[5][5]={"MONAR","CHYBD","EFGIK","LPQST","UVWXZ"};
char pt[10];
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();
Conclusion:
Thus we have learn how to implement Polyalphabetic cipher encryption and decryption.
Based on substitution, using multiple substitution Alphabets.
Practical 5
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};
//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]); }
//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>
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);
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();
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;
// 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));
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.
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;
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:
Implementation:
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.
So, when we press the encrypt button, we will get the Ciphertext – “ONARMDYB”.
Playfair Encryption
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”.
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”.
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”.
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.