0% found this document useful (0 votes)
9 views4 pages

INS Lab Final

The document contains various code snippets demonstrating encryption and decryption techniques using different algorithms such as DES, RSA, and a simple Caesar cipher. It also includes instructions for capturing and analyzing TCP packets using Wireshark. The examples illustrate how to implement these cryptographic methods in programming languages like C and Java.

Uploaded by

harshith1477
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)
9 views4 pages

INS Lab Final

The document contains various code snippets demonstrating encryption and decryption techniques using different algorithms such as DES, RSA, and a simple Caesar cipher. It also includes instructions for capturing and analyzing TCP packets using Wireshark. The examples illustrate how to implement these cryptographic methods in programming languages like C and Java.

Uploaded by

harshith1477
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/ 4

#include<stdlib.h> // #include<string.

h> // main() // , // char str*+="010010"; // char


str1*11+; // int i,len; // len=strlen(str); // for(i=0;i<len;i++) // , // str1*i+=str*i+^0; //
printf("%c",str1*i+); // - // printf("\n"); // -

Execution Steps:
● In Wireshark, select the Ethernet interface to capture the packets and select any one of
these packets, right-click and hover on conversation filter and select TCP.
Once done analyze the TCP Packets.
Capturing TCP Packets with : browser : Steps: ● Open Wireshark and double-click on
anyinterface to start the packet capture process. ● Open the browser and enter any
website's fully qualified domain name in the browser address bar and hit enter. ● After
the site is fully loaded, stop the capturing process, in Wireshark. ● Type the following in,
apply a filter column and hit-enter : tcp.flags.fin==1 and tcp.flags.ack ==1
Select any one of these listed packets, right-click and hover on conversation filter and
select TCP. ● Once done analyze the TCP Packets.
Now to find the packet which contains the User credential we use the following
commands in the display filter: tcp.flags.push==1 and also look for POST method in the
HTTP request.

#include<stdio.h>
#include<conio.h>
#include<string.h> void
main(),
char pt*50+, ct*50+, dt*50+;
int key, len, i;
printf("Enter message to be encrypted : ");
scanf("%s", pt); len = strlen(pt);
printf("\nEnter Key : "); scanf("%d",
&key); if(key > 26),
printf("\nInvalid key. Please enter valid key.\n");
-
for(i = 0; i < len; i++),
ct*i+ = pt*i+ + key;
if(ct*i+ > 122) ct*i+ =
ct*i+ - 26;
- ct*i+ =
'\0';
printf("\nEncrypted message is, %s", ct);
for(i = 0; i < len; i++) , dt*i+ = ct*i+ - key;
if(dt*i+ < 97)
dt*i+ = dt*i+ + 26;
- dt*i+ =
'\0';
printf("\n
\nDecrypt
ed
message
is, %s",
dt);
getch();
-
5.
#include<stdio.h>
#include<conio.h>
#include<string.h> int
main()
,
unsigned int a*3+*3+=,,6,24,1-,,13,16,10-,,20,17,15--;
unsigned int b*3+*3+=,,8,5,10-,,21,8,21-,,21,12,8--; int
i,j, t=0;
unsigned int c*20+,d*20+; char msg*20+;
printf("Enter plain text\n "); scanf("%s",msg);
for(i=0;i<strlen(msg);i++)
,
c*i+=msg*i+-65;
printf("%d ",c*i+);
-
for(i=0;i<3;i++)
,
t=0; for(j=0;j<3;j++)
,
t=t+(a*i+*j+*c*j+);
-
d*i+=t%26;
-
printf("\nEncrypted Cipher Text:");
for(i=0;i<3;i++) printf("
%c",d*i++65);
for(i=0;i<3;i++)
,
t=0; for(j=0;j<3;j++)
,
t=t+(b*i+*j+*d*j+);
-
c*i+=t%26;
-
printf("\nDecrypted Cipher Text:"); // for(i=0;i<3;i++) // printf(" %c",c*i++65); // getch();
return 0; //-
import javax.crypto.Cipher; // import javax.crypto.KeyGenerator; // import //
javax.crypto.SecretKey; // import java.util.Base64; // class Main ,
Cipher ecipher; // Cipher dcipher; // Main(SecretKey key) throws Exception ,
ecipher = Cipher.getInstance("DES");
dcipher = Cipher.getInstance("DES");
ecipher.init(Cipher.ENCRYPT_MODE, key);
dcipher.init(Cipher.DECRYPT_MODE, key);
- // public String encrypt(String str) throws Exception , // byte*+ utf8 =
str.getBytes("UTF8"); // byte*+ enc = ecipher.doFinal(utf8);
// return Base64.getEncoder().encodeToString(enc); -
public String decrypt(String str) throws Exception ,
byte*+ dec = Base64.getDecoder().decode(str); // byte*+ utf8 = dcipher.doFinal(dec);
// return new String(utf8, "UTF8");
- public static void main(String*+ argv) throws Exception ,
final String secretText = "www.reva.edu.in";
System.out.println("SecretText: " + secretText);
SecretKey key = KeyGenerator.getInstance("DES").generateKey();
Main encrypter = new Main(key);
String encrypted = encrypter.encrypt(secretText);
System.out.println("Encrypted Value: " + encrypted);
String decrypted = encrypter.decrypt(encrypted);
System.out.println("Decrypted: " + decrypted); // - // -

import java.util.*; import java.io.*; class rsa , static int mult(int x,int y,int n) // , // int
k=1; int j; // for (j=1; j<=y; j++) // k = (k * x) % n; // return ( int) k; - // public static void
main (String arg*+)throws Exception // , // Scanner s=new Scanner(System.in); //
InputStreamReader r=new InputStreamReader(System.in); // BufferedReader br=new
BufferedReader(r); String msg1; int pt*+=new int*100+; int ct*+=new int*100+; int a,b, n, d,
e,Z, p, q, i,temp,et;
System.out.println("Enter prime No.s p,q :");
p=s.nextInt();
q=s.nextInt();n = p*q; Z=(p-1)*(q-1);
System.out.println("\nSelect e value:");
e=s.nextInt();
System.out.printf("Enter message : ");
msg1=br.readLine();
char msg*+=msg1.toCharArray();
for(i=0;i<msg.length;i++) pt[i]=msg[i]; // for(d=1;d<Z;++d)
if(((e*d)%Z)==1) break; // System.out.println("p="+""+p+"\tq="+q+"\tn="+n+"\t
z="+Z+"\te="+e+"\td="+d); // System.out.println("\nCipher Text = "); for(i=0;
i<msg.length; i++)
ct[i] = mult(pt[i], e,n); // for(i=0; i<msg.length; i++)
System.out.print("\t"+ct[i]); // System.out.println("\nPlain Text = "); for(i=0;
i<msg.length; i++)
pt[i] = mult(ct[i], d,n) ; for(i=0; i<msg.length; i++)
System.out.print((char)pt[i]);
}
}
#include <stdio.h>
int power(int a, int b, int P) {
int result = 1, i;
for (i = 0; i < b; i++) {
result = (result * a) % P;
}
return result;
}

int main() {
int P = 23;
int G = 9;
int a = 4;
int b = 3;
printf("The value of P: %d\n", P);
printf("The value of G: %d\n", G);
printf("Private key for Alice: %d\n", a);
printf("Private key for Bob: %d\n", b);
int x = power(G, a, P);
int y = power(G, b, P);
int ka = power(y, a, P);
int kb = power(x, b, P);
printf("Secret key for Alice: %d\n", ka);
printf("Secret key for Bob: %d\n", kb);
return 0; }

You might also like