IS Practical - 200120107533

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 40

200120107533

Practical – 1
CEASER CIPHER
AIM: Understand CEASER CIPHER.
Exercises:
1) Write a C program to implement Caesar cipher encryption and decryption.

Encryption Code:

#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;
}

Gandhinagar Institute of Technology 3170720 IS


200120107533

Decryption Code:
#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;
}

Gandhinagar Institute of Technology 3170720 IS


200120107533

OUTPUT:

Gandhinagar Institute of Technology 3170720 IS


200120107533

Practical – 2
MONOALPHABETIC CIPHER
AIM: Introduction to MONOALPHABETIC CIPHER.
Exercises:
Write a C program to implement Monoalphabetic cipher encryption-decryption.
Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char
pt[26]={'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[26]={'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);
//converting plain text into cipher text (encryption)
for(i=0;i<strlen(p);i++)
{
for(j=0;j<26;j++)
{
if(pt[j]==p[i])
{
c[i]=ct[j];
}
}
}

Gandhinagar Institute of Technology 3170720 IS


200120107533

printf("\n cipher text is: %s",c);

//converting cipher text into plain text (decryption)


for(i=0;i<strlen(c);i++)
{
for(j=0;j<26;j++)
{
if(ct[j]==c[i])
{
r[i]=pt[j];
}
}
}
printf("\n \n plain text is: %s",r);
getch();
}

Output:

Gandhinagar Institute of Technology 3170720 IS


200120107533

Practical – 3
PLAYFAIR CIPHER
AIM: Introduction to PLAYFAIR CIPHER
Exercises:
Write a C program to implement Playfair cipher encryption-decryption.
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");

printf("Enter the length of the Key. ");


scanf("%d", &key_len);
char key[key_len];
printf("Enter the Key. ");
for (i = -1; i < key_len; ++i) {
scanf("%c", &key[i]);

Gandhinagar Institute of Technology 3170720 IS


200120107533

if (key[i] == 'j')
key[i] = 'i';
}
int flag;
int count = 0;
// inserting the key into the table
for (i = 0; i < 5; ++i) {
for (j = 0; j < 5; ++j) {
flag = 0;
while (flag != 1) {
if (count > key_len)
goto l1;

flag = check(table, key[count]);


++count;
}// end of while
table[i][j] = key[(count - 1)];
}// end of inner for
}// end of outer for
l1: printf("\n");
int val = 97;
//inserting other alphabets
for (i = 0; i < 5; ++i) {
for (j = 0; j < 5; ++j) {
if (table[i][j] >= 97 && table[i][j] <= 123) {
} else {
flag = 0;
while (flag != 1) {
if ('j' == (char) val)
++val;
flag = check(table, (char) val);
++val;

Gandhinagar Institute of Technology 3170720 IS


200120107533

}// end of while


table[i][j] = (char) (val - 1);
}//end of else
}// end of inner for
}// end of outer for

printf("The table is as follows:\n");


for (i = 0; i < 5; ++i) {
for (j = 0; j < 5; ++j) {
printf("%c ", table[i][j]);
}
printf("\n");
}
int l = 0;
printf("\nEnter the length length of plain text.(without spaces)
");
scanf("%d", &l);

printf("\nEnter the Plain text. ");


char p[l];
for (i = -1; i < l; ++i) {
scanf("%c", &p[i]);
}
for (i = -1; i < l; ++i) {
if (p[i] == 'j')
p[i] = 'i';
}
printf("\nThe replaced text(j with i)");
for (i = -1; i < l; ++i)
printf("%c ", p[i]);

count = 0;
for (i = -1; i < l; ++i) {

Gandhinagar Institute of Technology 3170720 IS


200120107533

if (p[i] == p[i + 1])


count = count + 1;
}
printf("\nThe cipher has to enter %d bogus char.It is either 'x'
or 'z'\n",
count);
int length = 0;
if ((l + count) % 2 != 0)
length = (l + count + 1);
else
length = (l + count);
printf("\nValue of length is %d.\n", length);
char p1[length];
//inserting bogus characters.
char temp1;
int count1 = 0;
for (i = -1; i < l; ++i) {
p1[count1] = p[i];
if (p[i] == p[i + 1]) {
count1 = count1 + 1;
if (p[i] == 'x')
p1[count1] = 'z';
else
p1[count1] = 'x';
}
count1 = count1 + 1;
}

//checking for length

char bogus;
if ((l + count) % 2 != 0) {
if (p1[length - 1] == 'x')

Gandhinagar Institute of Technology 3170720 IS


200120107533

p1[length] = 'z';
else
p1[length] = 'x';
}

printf("The final text is:");


for (i = 0; i <= length; ++i)
printf("%c ", p1[i]);

char cipher_text[length];
int r1, r2, c1, c2;
int k1;

for (k1 = 1; k1 <= length; ++k1) {


for (i = 0; i < 5; ++i) {
for (j = 0; j < 5; ++j) {
if (table[i][j] == p1[k1]) {
r1 = i;
c1 = j;
} else if (table[i][j] == p1[k1 + 1]) {
r2 = i;
c2 = j;
}
}//end of for with j
}//end of for with i

if (r1 == r2) {
cipher_text[k1] = table[r1][(c1 + 1) % 5];
cipher_text[k1 + 1] = table[r1][(c2 + 1) % 5];
}

else if (c1 == c2) {

Gandhinagar Institute of Technology 3170720 IS


200120107533

cipher_text[k1] = table[(r1 + 1) % 5][c1];


cipher_text[k1 + 1] = table[(r2 + 1) % 5][c1];
} else {
cipher_text[k1] = table[r1][c2];
cipher_text[k1 + 1] = table[r2][c1];
}

k1 = k1 + 1;
}//end of for with k1
printf("\n\nThe Cipher text is:\n ");
for (i = 1; i <= length; ++i)
printf("%c ", cipher_text[i]);
}

Output:

Gandhinagar Institute of Technology 3170720 IS


200120107533

Practical – 4
POLYALPHABETIC
AIM: Introduction to POLYALPHABETIC.
Exercises:
Write a C program to implement Polyalphabetic cipher encryption-decryption.
Answer:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char pt[20]={'\0'},ct[20]={'\0'},key[20]={'\0'},rt[20]={'\0'};
int i,j;
// clrscr();
printf("\n enter the plain text:");
scanf("%s",pt);
printf("\n enter the key:");
scanf("%s",key);

//length of plaintext equal to length of key


j=0;
for(i=strlen(key);i<strlen(pt);i++)
{
if(j==strlen(key))
{
j=0;
}
key[i]=key[j];
j++;
}
printf("\n new key is:%s",key);

Gandhinagar Institute of Technology 3170720 IS


200120107533

//converting plain text to cipher text (encryption)


for(i=0;i<strlen(pt);i++)
{
ct[i]=(((pt[i]-97)+(key[i]-97))%26)+97;
}
printf("\n \n cipher text is:%s",ct);

//converting cipher text to plain text (decryption)


for(i=0;i<strlen(ct);i++)
{
if(ct[i]<key[i])
{
rt[i]=26+((ct[i]-97)-(key[i]-97))+97;
}
else
rt[i]=(((ct[i]-97)-(key[i]-97))%26)+97;
}
printf("\n \n plain text is:%s",rt);
getch();
}

Output

Gandhinagar Institute of Technology 3170720 IS


200120107533

Practical – 5
HILL CIPHER
AIM: Introduction to HILL CIPHER.
Exercises:
Write a C program to implement Hill cipher encryption-decryption
Answer:
#include<stdio.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;
unsigned int c[20], d[20];
char msg[20];
int determinant = 0, t = 0;
;
printf("Enter plain text\n ");
scanf("%s", msg);
for (i = 0; i < 3; 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 :");

Gandhinagar Institute of Technology 3170720 IS


200120107533

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);
return 0;
}

Output:

Gandhinagar Institute of Technology 3170720 IS


200120107533

Practical – 6
DES Algorithm
AIM: Introduction to simple DES algorithm.
Exercises:
Write a C program to implement simple DES
Answer:
#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++)

Gandhinagar Institute of Technology 3170720 IS


200120107533

{ 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];

Gandhinagar Institute of Technology 3170720 IS


200120107533

}
printf("\nYour key k1 is :");
puts(k1);
//This program can be extended to generate k2 as per DES algorithm.
}

Output

Gandhinagar Institute of Technology 3170720 IS


200120107533

Practical – 7
Diffie-Hellman Key Exchange
AIM: Introduction to Diffie-Hellman Key Exchange.
Exercises:
Write a C program to implement Diffie-Hellmen Key exchange Method.
Answer:
#include<stdio.h>
long long int power(int a,int b,int mod)
{
long long int t;
if(b==1)
return a;
t=power(a,b/2,mod);
if(b%2==0)
return (t*t)%mod;
else
return (((t*t)%mod)*a)%mod;
}
long long int calculateKey(int a,int x,int n)
{
return power(a,x,n);
}
int main()
{
int n,g,x,a,y,b;
// both the persons will be agreed upon the common n and g
printf("Enter the value of n and g : ");
scanf("%d%d",&n,&g);

// first person will choose the x


printf("Enter the value of x for the first person : ");
scanf("%d",&x);

Gandhinagar Institute of Technology 3170720 IS


200120107533

a=power(g,x,n);

// second person will choose the y


printf("Enter the value of y for the second person : ");
scanf("%d",&y);
b=power(g,y,n);

printf("key for the first person is : %lld\n",power(b,x,n));


printf("key for the second person is : %lld\n",power(a,y,n));
return 0;
}

Output:

Gandhinagar Institute of Technology 3170720 IS


200120107533

Practical – 8
RSA
AIM: Introduction to RSA encryption decryption algorithm.
Exercises:
Write a C program to implement RSA encryption-decryption algorithm.
Answer:
#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()
{
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);

Gandhinagar Institute of Technology 3170720 IS


200120107533

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();
}
int prime(long int pr)
{
int i;
j = sqrt(pr);
for (i = 2; i <= j; i++)
{
if (pr % i == 0)
return 0;
}
return 1;
}

Gandhinagar Institute of Technology 3170720 IS


200120107533

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);
}

Gandhinagar Institute of Technology 3170720 IS


200120107533

}
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)
{

Gandhinagar Institute of Technology 3170720 IS


200120107533

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:

Gandhinagar Institute of Technology 3170720 IS


200120107533

Practical – 9
Digital signature algorithm
AIM: Introduction to digital signature algorithm.
Exercises:
Write a C program to implement digital signature algorithm.
Answer:
#include <stdio.h> #include <stdlib.h> #include <time.h>
// 64-bit integer type
typedef long long int dlong;
// rational ec point typedef struct { dlong x, y;
} epnt;
// elliptic curve parameters
typedef struct { long a, b; dlong N;
epnt G; dlong r;
} curve;
// signature pair typedef struct { long a, b;
} pair;
// dlong for holding intermediate results,
// long variables in exgcd() for efficiency,
// maximum parameter size 2 * p.y (line 129)
// limits the modulus size to 30 bits.
// maximum modulus
const long mxN = 1073741789;
// max order G = mxN + 65536
const long mxr = 1073807325;
// symbolic infinity
const long inf = -2147483647;
// single global curve
curve e;
// point at infinity zerO
epnt zerO;
// impossible inverse mod N

Gandhinagar Institute of Technology 3170720 IS


200120107533

int inverr;
// return mod(v^-1, u)
long exgcd (long v, long u)
{
register long q, t; long r = 0, s = 1; if (v < 0) v += u;
while (v) {
q = u / v;
t = u - q * v; u = v; v = t; t = r - q * s; r = s; s = t;
}
if (u != 1) {
printf (" impossible inverse mod N, gcd = %d\n", u); inverr = 1;
}
return r;
}
// return mod(a, N)
static inline dlong modn (dlong a)
{
a %= e.N;
if (a < 0) a += e.N;
return a;
}
// return mod(a, r)
dlong modr (dlong a)
{
a %= e.r;
if (a < 0) a += e.r;
return a;
}
// return the discriminant of E
long disc (void)
{

Gandhinagar Institute of Technology 3170720 IS


200120107533

dlong c, a = e.a, b = e.b;

c = 4 * modn(a * modn(a * a));


return modn(-16 * (c + 27 * modn(b * b)));
}
// return 1 if P = zerO
int isO (epnt p)
{
return (p.x == inf) && (p.y == 0);
}
// return 1 if P is on curve E
int ison (epnt p)
{
long r, s;
if (! isO (p)) {
r = modn(e.b + p.x * modn(e.a + p.x * p.x)); s = modn(p.y * p.y);
}
return (r == s);
}
// full ec point addition
void padd (epnt *r, epnt p, epnt q)
{
dlong la, t;
if (isO(p)) {*r = q; return;}
if (isO(q)) {*r = p; return;}
if (p.x != q.x) { // R:= P + Q
t = p.y - q.y;
la = modn(t * exgcd(p.x - q.x, e.N));
}
else // P = Q, R := 2P
if ((p.y == q.y) && (p.y != 0)) {

Gandhinagar Institute of Technology 3170720 IS


200120107533

t = modn(3 * modn(p.x * p.x) + e.a); la = modn(t * exgcd (2 * p.y,


e.N));
}
else
{*r = zerO; return;} // P = -Q, R := O
t = modn(la * la - p.x - q.x);
r->y = modn(la * (p.x - t) - p.y); r->x = t; if (inverr) *r = zerO;
}
// R:= multiple kP
void pmul (epnt *r, epnt p, long k)
{
epnt s = zerO, q = p;
for (; k; k >>= 1) {
if (k & 1) padd(&s, s, q);
if (inverr) {s = zerO; break;}
padd(&q, q, q);
}
*r = s;
}
// print point P with prefix f

void pprint (char *f, epnt p)


{
dlong y = p.y;
if (isO (p))
printf ("%s (0)\n", f);
else {
if (y > e.N - y) y -= e.N;
printf ("%s (%lld, %lld)\n", f, p.x, y);
}
}
// initialize elliptic curve
int ellinit (long i[])

Gandhinagar Institute of Technology 3170720 IS


200120107533

{
long a = i[0], b = i[1];
e.N = i[2]; inverr = 0;
if ((e.N < 5) || (e.N > mxN)) return 0;
e.a = modn(a);
e.b = modn(b);
e.G.x = modn(i[3]);
e.G.y = modn(i[4]);
e.r = i[5];
if ((e.r < 5) || (e.r > mxr)) return 0;
printf ("\nE: y^2 = x^3 + %dx + %d", a, b);
printf (" (mod %lld)\n", e.N); pprint ("base point G", e.G);
printf ("order(G, E) = %lld\n", e.r);
return 1;
}
// pseudorandom number [0..1)
double rnd(void)
{
return rand() / ((double)RAND_MAX + 1);
}
// signature primitive
pair signature (dlong s, long f)
{
long c, d, u, u1; pair sg;
epnt V;
printf ("\nsignature computation\n");
do {
do {
u = 1 + (long)(rnd() * (e.r - 1)); pmul (&V, e.G, u);
c = modr(V.x);

Gandhinagar Institute of Technology 3170720 IS


200120107533

while (c == 0);
u1 = exgcd (u, e.r);
d = modr(u1 * (f + modr(s * c)));
}
while (d == 0);
printf ("one-time u = %d\n", u); pprint ("V = uG", V);
sg.a = c; sg.b = d;
return sg;
}
// verification primitive
int verify (epnt W, long f, pair sg)
{
long c = sg.a, d = sg.b; long t, c1, h1, h2; dlong h;
epnt V, V2;
// domain check
t = (c > 0) && (c < e.r);
t &= (d > 0) && (d < e.r);
if (! t) return 0;
printf ("\nsignature verification\n"); h = exgcd (d, e.r);
h1 = modr(f * h); h2 = modr(c * h);
printf ("h1,h2 = %d, %d\n", h1,h2); pmul (&V, e.G, h1);
pmul (&V2, W, h2);
pprint ("h1G", V);
pprint ("h2W", V2);
padd (&V, V, V2);
pprint ("+ =", V);
if (isO (V)) return 0; c1 = modr(V.x);
printf ("c' = %d\n", c1);
return (c1 == c);
}
// digital signature on message hash f, error bit d

Gandhinagar Institute of Technology 3170720 IS


200120107533

void ec_dsa (long f, long d)


{
long i, s, t; pair sg; epnt W;
// parameter check
t = (disc() == 0);
t |= isO (e.G);
pmul (&W, e.G, e.r); t |= ! isO (W);
t |= ! ison (e.G);
if (t) goto errmsg;
printf ("\nkey generation\n");
s = 1 + (long)(rnd() * (e.r - 1)); pmul (&W, e.G, s);
printf ("private key s = %d\n", s); pprint ("public key W = sG", W);
// next highest power of 2 - 1
t = e.r;
for (i = 1; i < 32; i <<= 1)
t |= t >> i;
while (f > t) f >>= 1;
printf ("\naligned hash %x\n", f);
sg = signature (s, f);
if (inverr) goto errmsg;
printf ("signature c,d = %d, %d\n", sg.a, sg.b);
if (d > 0) {
while (d > t) d >>= 1; f ^= d;
printf ("\ncorrupted hash %x\n", f);
}
t = verify (W, f, sg);
if (inverr) goto errmsg;
if (t
printf ("Valid\n \n"); else
printf ("invalid\n \n");
return;
errmsg:

Gandhinagar Institute of Technology 3170720 IS


200120107533

printf ("invalid parameter set\n");


printf (" \n");
}
void main (void)
{
typedef long eparm[6];
long d, f;
zerO.x = inf; zerO.y = 0; srand(time(NULL));
// Test vectors: elliptic curve domain parameters,
// short Weierstrass model y^2 = x^3 + ax + b (mod N)
eparm *sp, sets[10] = {
// a, b, modulus N, base point G, order(G, E), cofactor
{355, 671, 1073741789, 13693, 10088, 1073807281},
{ 0, 7, 67096021, 6580, 779, 16769911}, // 4
{ -3, 1, 877073, 0, 1, 878159},
{ 0, 14, 22651, 63, 30, 151}, // 151
{ 3, 2, 5, 2, 1, 5},
// ecdsa may fail if...
// the base point is of composite order
{ 0, 7, 67096021, 2402, 6067, 33539822}, // 2
// the given order is a multiple of the true order
{ 0, 7, 67096021, 6580, 779, 67079644}, // 1
// the modulus is not prime (deceptive example)
{ 0, 7, 877069, 3, 97123, 877069},
// fails if the modulus divides the discriminant
{ 39, 387, 22651, 95, 27, 22651},
};
// Digital signature on message hash f,
// set d > 0 to simulate corrupted data
f = 0x789abcde; d = 0;
for (sp = sets; ; sp++) { if (ellinit (*sp))
ec_dsa (f, d);

Gandhinagar Institute of Technology 3170720 IS


200120107533

else
break;
}
}

Output:
(tcc, srand(1); first set only)
E: y^2 = x^3 + 355x + 671 (mod 1073741789)
base point G (13693, 10088) order(G, E) = 1073807281

key generation
private key s = 1343570
public key W = sG (817515107, -192163292)

aligned hash 789abcde

signature computation one-time u = 605163545


V = uG (464115167, -267961770)
signature c,d = 464115167, 407284989

signature verification
h1,h2 = 871754294, 34741072
h1G (708182134, 29830217)
h2W (270156466, -328492261)
+ = (464115167, -267961770)
c' = 464115167
Valid

Gandhinagar Institute of Technology 3170720 IS


200120107533

Practical – 10
CRYPTOOL
AIM: Introduction to cryptool.
Exercises:
Perform any one of the above encryption technique with cryptool..
Answer:
Encryption and Decryption of Hill Cipher
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

Gandhinagar Institute of Technology 3170720 IS


200120107533

Practical – 11
Wireshark
AIM: Study and use the Wireshark for the various network protocols.
Exercises:
Perform Below Exercises using Wireshark
1. Is your browser running HTTP version 1.0 or 1.1? What version of HTTP is the
server Running?
Answer:

2. What languages (if any) does your browser indicate that it can accept to the server?
Answer: en-US (US English) as shown in prior screenshot

Gandhinagar Institute of Technology 3170720 IS


200120107533

3. What is the IP address of your computer? Of the gaia.cs.umass.edu server?


Answer: My computer is 10.211.55.3 (this is a virtual IP address assigned by my virtual
machine software) and the destination is 130.215.16.168. See prior screenshot.

4. What is the status code returned from the server to your browser?
Answer: 200 OK (see prior screen- shot)

5.When was the HTML file that you are retrieving last modified at the server?
We can filter messages by http.last_modified and we see that the HTTP response I received
for the html file doesn’t show this field. We do have a http.last_modified field in the favicon
response however, as shown in the screenshot below. This says the favicon was last modified
on Feb 25, 2010.

Gandhinagar Institute of Technology 3170720 IS


200120107533

6.How many bytes of content are being returned to your browser?


Answer:

7.By inspecting the raw data in the packet content window, do you see any headers within the
data that are not displayed in the packet-listing window? If so, name one.
Answer:No. The raw data appears to match up exactly with what is shown in the packet-
listing window.
8.Inspect the contents of the first HTTP GET request from your browser to the server. Do you
see an ―IF-MODIFIED-SINCEǁ line in the HTTP GET?
Answer: No
9.Inspect the contents of the server response. Did the server explicitly return the contents of
the file? How can you tell?
Answer: See screenshot of response with Alice’s Adventures…

Gandhinagar Institute of Technology 3170720 IS


200120107533

10.Now inspect the contents of the second HTTP GET request from your browser to the
server.
Do you see an ―IF-MODIFIED-SINCE:ǁ line in the HTTP GET? If so, what information
follows the ―IF-MODIFIED-SINCE:ǁ header?
Answer: Yes

Gandhinagar Institute of Technology 3170720 IS


200120107533

11.What is the HTTP status code and phrase returned from the server in response to this
second HTTP GET? Did the server explicitly return the contents of the file? Explain.
Answer:
As seen in the previous screenshot, we get a HTTP/1.1 304 Not Modified Response. This is
much shorter than the full response packet seen previously which contained all of Alice in
Wonderland.

Gandhinagar Institute of Technology 3170720 IS

You might also like