IS Lab Manual 8,9, 10 Experiments Programs
IS Lab Manual 8,9, 10 Experiments Programs
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
char msg[100];
void ce();
void main() {
scanf("%ld",&p);
flag=prime(p);
if(flag==0)
{ printf("\nWRONG INPUT\n");
getch();
scanf("%ld",&q);
flag=prime(q);
if(flag==0||p==q)
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();
for(i=0;i<j-1;i++)
printf("\n%ld\t%ld",e[i],d[i]);
encrypt();
decrypt();
getch(); }
{ int i;
j=sqrt(pr);
for(i=2;i<=j;i++)
{ if(pr%i==0) return 0; }
return 1; }
void ce()
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; } } }
void encrypt()
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;
for(i=0;en[i]!=-1;i++)
printf("%c",en[i]); }
void decrypt()
i=0;
while(en[i]!=-1)
{ ct=temp[i];
k=1;
m[i]=-1;
for(i=0;m[i]!=-1;i++)
printf("%c",m[i]); }
Implementation of Diffie Hellman Key Exchange algorithm
#include<stdio.h>
#include<conio.h>
if(b==1) return a;
t=power(a,b/2,mod);
if(b%2==0)
return (t*t)%mod;
{ return power(a,x,n); }
void main()
{ int n,g,x,a,y,b;
//clrscr();
scanf("%d%d",&n,&g);
scanf("%d",&x);
a=power(g,x,n);
scanf("%d",&y);
b=power(g,y,n);
import java.util.*;
import java.math.BigInteger;
class dsaAlg
while (!test.isProbablePrime(99))
e: { test = test.add(one); }
return test; }
while (!n.isProbablePrime(99))
{ while (!((n.mod(start)).equals(zero)))
{ start = start.add(one);
} n = n.divide(start); }
return n; }
h = h.mod(p);
BigInteger p = getNextPrime("10600");
/* approximate prime */
BigInteger q = findQ(p.subtract(one));
BigInteger g = getGen(p,q,randObj);
x = x.mod(q);
BigInteger y = g.modPow(x,p);
BigInteger k = ne
w BigInteger(q.bitLength(), randObj);
v = (v.mod(p)).mod(q);
if (v.equals(r))