Sunday, 09.08.2020, 20:57
Welcome Guest | RSS
Site menu
Login form
Section categories
Search
Calendar
«  June 2011  »
SuMoTuWeThFrSa
   1234
567891011
12131415161718
19202122232425
2627282930
Entries archive
Our poll
Rate my site
Total of answers: 6
Statistics

Total online: 1
Guests: 1
Users: 0
Main » 2011 » June » 10 » Diffie-Hellman example
17:58
Diffie-Hellman example
#include <iostream>
#include <cstdlib>
using namespace std;

long long Exp(long long base, long long exp)
{
long long r=base;
for(int i=1;i<exp;i++)
r*=base;
return r;
}

int main()
{
long long A,B;
long long base,mod;
for(;;)
{
cout << "Base: " << endl;
cin >>base;
cout << "Modulus: " << endl;
cin >>mod;
cout << "Alice, choose your secret number: " << endl;
cin >>A;
cout << "Bob, choose your secret number: " << endl;
cin >>B;
long long a=Exp(base,A)%mod;
long long b=Exp(base,B)%mod;
cout << "Alice's value: " << a << endl;
cout << "Bob's value: " << b << endl;
long long akey=Exp(b,A)%mod;
long long bkey=Exp(a,B)%mod;
cout << "Alice's key: " << akey << endl;
cout << "Bob's key: " << bkey << endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}

Category: C++ programs | Views: 403 | Added by: H_Imirzyan | Tags: Hellman, example, Diffie-Hellman, Diffie | Rating: 0.0/0
Total comments: 0
Name *:
Email *:
Code *: