Ins Lab Manual
Ins Lab Manual
for(i=0;text[i]!='\0';++i)
{
c=text[i];
if(c>='a'&&c<= 'z')
{
c=c+key;
if(c>'z')
{
c=c-'z'+'a'-1;
text[i]=c;
}
}
printf("\nEncrypted Message : %s", text);
getch();
}
Output:
Decryption:
#included<stdio.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
void main()
{
int i, key;
char text[100],c;
clrscr();
OUTPUT:
Disadvantages:
1. It can be easily hacked. It means the message encrypted by this method can be easily
decrypted.
2. It provides very little security.
3. By looking at the pattern of letters in it, the entire message can be decrypted.
Advantages:
1. Simple to understand and implement
2. we have 26! (26*25*24*23*...*1) possible keys. so brute-force attack won't work here.
It initially creates a key-table of 5*5 matrix. The matrix contains alphabets that act as the key
for encryption of the plaintext. Note that any alphabet should not be repeated. Another point to
note that there are 26 alphabets and we have only 25 blocks to put a letter inside it. Therefore,
one letter is excess so, a letter will be omitted (usually J) from the matrix. Nevertheless, the
plaintext contains J, then J is replaced by I. It means treat I and J as the same letter, accordingly.
Since Playfair cipher encrypts the message digraph by digraph. Therefore, the Playfair cipher
is an example of a digraph substitution cipher.
Code:
#include<stdio.h>
int check(char table[5][5], char k) {
int i, j;
for (i = 0; i < 5; ++i)
for (j = 0; j < 5; ++j) {
if (table[i][j] == k)
return 0;
}
return 1;
}
void main() {
int i, j, key_len;
char table[5][5];
for (i = 0; i < 5; ++i)
for (j = 0; j < 5; ++j)
table[i][j] = '0';
printf("**********Playfair Cipher************\n\n");
char key[key_len];
int flag;
int count = 0;
int l = 0;
count = 0;
for (i = -1; i < l; ++i) {
if (p[i] == p[i + 1])
count = count + 1;
}
int length = 0;
if ((l + count) % 2 != 0)
length = (l + count + 1);
char bogus;
if ((l + count) % 2 != 0) {
if (p1[length - 1] == 'x')
p1[length] = 'z';
else
p1[length] = 'x';
}
char cipher_text[length];
int r1, r2, c1, c2;
int k1;
if (r1 == r2) {
cipher_text[k1] = table[r1][(c1 + 1) % 5];
cipher_text[k1 + 1] = table[r1][(c2 + 1) % 5];
}
k1 = k1 + 1;
}//end of for with k1
}
OUTPUT:
1. Diverse ciphertext if we scrutinize the Algorithm, we can notice at every Stage we are
getting diverse ciphertext, thus more trouble to cryptanalyst.
2. Brute force attack does not affect it.
3. Cryptanalyze (the process of decoding cipher without knowing key) is not possible.
4. Overcomes the limitation of simple Playfair square cipher.
5. Easy to perform the substitution.
Disadvantages:
void main() {
getKeyMessage();
encryption();
decryption();
}
void encryption() {
int i, j, k;
for(i = 0; i < 3; i++)
}
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];
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++)
Advantages:
1. It perfectly conceals single-letter frequencies
2. 3×3 Hill Ciphers are extremely effective when it comes to hiding both single-letter and
two-letter frequency information.
3. It is highly strong against attacks made on ciphertext except if the attack is through a
known plaintext.
Disadvantages:
1. Noninvertible key over is the main disadvantages of hill cipher, because few of the
matrices have inverses over. This means that the encrypted text can’t be decrypted.
AES Cipher-
//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 :");
Disadvantages:
1. The 56-bit key size is the biggest defect of DES. Chips to perform one
million of DES encrypt or decrypt operations a second are available (in 1993).
A $1 million DES cracking machine can search the entire key space in about 7
hours.
2. Hardware implementations of DES are very fast; DES was not designed for
software and hence runs relatively slowly.
3. As the technology is improving lot more day by day so there is a possibility
to break the encrypted code, so AES is preferred than DES.
4. As we know in DES only one private key is used for encryption as well as for
decryption because it is symmetric encryption technique so if we lost that key to
decrypt the data then we cannot get the readable data at the receiving end.
Advantages and disadvantages of AES:
Advantages:
1. As it is implemented in both hardware and software, it is most robust security protocol.
2. It uses higher length key sizes such as 128, 192 and 256 bits for encryption. Hence it
makes AES algorithm more robust against hacking.
3. It is most common security protocol used for wide various of applications such as
wireless communication, financial transactions, e-business, encrypted data storage etc.
Code:
#include<stdio.h>
#include<math.h>
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);
}
int main()
{
long long int P, G, x, a, y, b, ka, kb;
P = 23;
printf("The value of P : %lld\n", P);
G = 9;
a = 4;
printf("The private key a for Alice : %lld\n", a);
x = power(G, a, P);
b = 3;
printf("The private key b for Bob : %lld\n\n", b);
y = power(G, b, P);
ka = power(y, a, P);
kb = power(x, b, P);
return 0;
}
OUTPUT:
1. The sender and receiver don’t need any prior knowledge of each other.
2. Once the keys are exchanged, the communication of data can be done through an
insecure channel.
3. The sharing of the secret key is safe.
Disadvantages:
1. The algorithm can not be sued for any asymmetric key exchange.
2. Similarly, it can not be used for signing digital signatures.
3. Since it doesn’t authenticate any party in the transmission, the Diffie Hellman key
exchange is susceptible to a man-in-the-middle attack.
RSA can also encrypt and decrypt general information to securely exchange data along with
handling digital signature verification. The image above shows the entire procedure of the RSA
algorithm.
Code:
#include<stdio.h>
#include<math.h>
int gcd(int a, int h)
{
int temp;
while (1)
{
temp = a%h;
if (temp == 0)
return h;
a = h;
h = temp;
double e = 2;
double phi = (p-1)*(q-1);
while (e < phi)
{
if (gcd(e, phi)==1)
break;
else
e++;
}
int k = 2;
double d = (1 + (k*phi))/e;
// Message to be encrypted
double msg = 20;
printf("Message data = %lf", msg);
// Encryption c = (msg ^ e) % n
double c = pow(msg, e);
c = fmod(c, n);
printf("\nEncrypted data = %lf", c);
// Decryption m = (c ^ d) % n
double m = pow(c, d);
return 0;
}
OUTPUT:
Advantages:
Disadvantages:
1. It may fail sometimes because for complete encryption both symmetric and
asymmetric encryption is required and RSA uses asymmetric encryption only.
5. RSA can’t be used for public data encryption like election voting.
h0 = 0x67452301;
h1 = 0xEFCDAB89;
h2 = 0x98BADCFE;
h3 = 0x10325476;
h4 = 0xC3D2E1F0;
char ic = str[current_length];
current_length++;
a = h0;
b = h1;
c = h2;
d = h3;
e = h4;
for(int m=0;m<80;m++)
{
if(m<=19)
{
f = (b & c) | ((~b) & d);
k = 0x5A827999;
}
else if(m<=39)
{
f = b ^ c ^ d;
printf("\n\n");
printf("Hash: %x %x %x %x %x",h0, h1, h2, h3, h4);
printf("\n\n");
Advantages:
1. It’s a slow algorithm. This characteristic made it useful for storing password hashes as
it slows down brute force attacks.
2. It can be used to compare files or codes to identify unintentional only corruptions.
3. Can replace SHA-2 in case of interoperability issues with legacy codes.
Disadvantages:
1. Slower than other algorithms, therefore unsuitable for many purposes other than
password storage (e.g., when establishing secure connections to websites or comparing
files).
2. Less secure with many vulnerabilities found during the years.
3. Collisions are easy and cheap to find.
4. Key length too short to resist to attacks.
A digital signature is an electronic analogue of a written signature to provide assurance that the
claimed signatory signed the information. In addition, a digital signature may be used to detect
whether or not the information was modified after it was signed (i.e., to detect the integrity of
the signed data).
1. Signature Generation:
Generating a pair of public key and provide key by the sender of the message.
Generating the message digest from the message using a hash function.
Generating the digital signature from the message digest with the private key.
Sending the message, the digital signature, and the public key to receiver.
2. Signature Verification:
Generating the message digest from the message using the same hash function.
Verifying the digital signature with message digest using the public key.
RSA (Rivest, Shamir and Adleman) algorithm developed by Ronald L. Rivest, Adi
Shamir, and Leonard M. Adleman in 1976.
Advantages:
1. A digital signature provides better security in the transaction. Any unauthorized person
cannot do fraudulence in transactions.
2. You can easily track the status of the documents on which the digital signature is
applied.
3. High speed up document delivery.
4. It is 100% legal it is issued by the government authorized certifying authority.
5. If you have signed a document digitally, then you cannot deny it.
6. In this signature, When a document is get signed, date and time are automatically
stamped on it.
7. It is not possible to copy or change the document signed digitally.
8. Identification of the person that signs.
9. Elimination of the possibility of committing fraud by an imposter.
Disadvantages:
1. You need to troubleshoot all the compatibility problems. In there are a lot of
compatibility settings like an updated version of driver and software.
2. Software is one of the main issues while using a digital signature certificate.
3. If you are belonging to the corporate world and running an export-import organization,
you need to produce a digital signature for E-ticketing.
4. In this signature, Lost or theft of keys and the use of vulnerable storage facilities.
5. There is a stronger need for a standard through which these different methods can
interact.
6. In this era of fast technological advancement, many of these tech products have a short
shelf life.
7. In order to effectively use a digital signature, both senders and recipients may have to
buy digital certificates.
8. To work with digital certificates, the sender and recipients have to buy verification
software at a cost.
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.
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 Ciphertext will be “D”.
So, if I give “Monarchy” as plaintext in Caesar Cipher, it will show me the encryption, a shown
in the below image.
Again, we have to move to Encrypt/Decrypt - Symmetric - Playfair Cipher and perform the
encryption part. We are putting the same plaintext – MONARCHY.
So, when we press the encrypt button, we will get the Ciphertext – “ONARMDYB”.
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.
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.
So, when we press the encrypt button, we will get the Ciphertext somewhat like –
“TWWNPZOAASWNUHZBNWWGSNBVCSLYPMM”.
Packet List
The packet list pane, located at the top of the window, shows all packets found in the active
capture file. Each packet has its own row and corresponding number assigned to it, along
The details pane, found in the middle, presents the protocols and protocol fields of the selected
packet in a collapsible format. In addition to expanding each selection, you can also apply
individual wires hark filters based on specific details as well as follow streams of data based
on protocol type via the details context menu – accessible by right-clicking your mouse on the
desired item within this pane.
3) Using wire shark filters
One of the most important feature sets in wires hark is its filter capabilities, especially when
While Wire shark’s capture and display filters allow you to limit which packets are recorded
or shown on the screen, its colorization functionality takes things a step further by making it
easy to distinguish between different packets types based on their individual hue. This handy
feature lets you quickly locate certain packets within a saved set by their row's color scheme in
the packet list pane.