Quantcast
Channel: Assignment
Viewing all articles
Browse latest Browse all 9603

Diffie-hellman

$
0
0
by fyproject 13.  

Diffie-hellman

 

#include<stdio.h>

#include<conio.h>

#include<math.h>

#include<graphics.h>

 

void main()

  {

   int a,q,i;

   int Xa,Ya,Xb,Yb,Ya1,Yb1,Kab1,Kab;

 

   int gd,gm;

   clrscr();

 

   printf("\n enter value of prime number q :: ");

   scanf("%d",&q);

   for(i=0;;i++)

            {

               printf("\n enter the primitive root a :: ");

               scanf("%d",&a);

               if(a<q)

                        break;

               printf("\n a>q so enter again !!!");

            }

 

   printf("\n for sender station.........");

   printf("\n enter the private number of station A :: ");

   scanf("%d",&Xa);

 

   Ya1=pow(a,Xa);

   Ya=Ya1%q;

   printf("\n the public number generated is as :: %d",Ya);

 

   printf("\n for receiver station .....");

   printf("\n enter the private number of station B :: ");

   scanf("%d",&Xb);

 

   Yb1=pow(a,Xb);

   Yb=Yb1%q;

   printf("\n the public number generated is as :: %d",Yb);

 

   Kab1=pow(Yb,Xa);

   Kab=Kab1%q;

   printf("\n\n\t\t shared secret key form as :: %d",Kab);

 

 

   detectgraph(&gd,&gm);

   initgraph(&gd,&gm,"c:\\turboc3\\bgi");

 

   outtextxy(160,120,"ALICE");

   rectangle(150,100,200,300);

 

   outtextxy(460,120,"BOB");

   rectangle(450,100,500,300);

 

   outtextxy(300,110,"alph,q");

   line(200,120,450,120);//line 1

 

   outtextxy(212,145,"Xa");

   line(190,150,210,150);//Xa

 

   outtextxy(422,145,"Xb");

   line(440,150,460,150);    //Xb

 

   outtextxy(210,170,"Ya");

   line(190,180,210,180);//Ya

 

   outtextxy(430,170,"Yb");

   line(440,180,460,180);    //Yb

 

   line(190,180,460,210); //key Yb

   line(440,180,190,210); //key Ya

 

   line(440,210,460,210);     //key Yb  just for marking

   line(190,210,210,210);  //key Ya   just for marking

 

   outtextxy(230,250,"shared secret key=Kab");

   line(200,260,450,260);//Kab

 

   getch();

  }

 

 

 

 

 

 

OUTPUT:

 

 

 enter value of prime number q :: 5

 

 enter the primitive root a :: 2

 

 for sender station.........

 enter the private number of station A :: 3

 

 the public number generated is as :: 3

 for receiver station .....

 enter the private number of station B :: 4

 

 the public number generated is as :: 1

 

                 shared secret key form as :: 1

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


Viewing all articles
Browse latest Browse all 9603

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>