446,406 Members | 888 Online
Need help? Post your question and get tips & solutions from a community of 446,406 IT Pros & Developers. It's quick & easy.

# who can give me a lmplement of Diffie-Hellman key exchange.

 P: n/a C or C++ version,os independent,can be used under linux and windows. Thanks for advanced. Dec 15 '05 #1
3 Replies

 P: n/a say88 schrieb: C or C++ version,os independent,can be used under linux and windows. Thanks for advanced. Looks like homework, but here is the basic idea: #include #include using namespace std; int pow (int b, int p) { return (int) pow ((double)b,(double)p); // brutal } int main () { int p=13; //public prime int g=2; //public 2 =< g =< p-2 int alice_a=44; //secret int bob_b=22; //secret int alice_A=pow(g,alice_a)%p; //sends to bob int bob_B=pow(g,bob_b)%p; // sends to alice cout << "Bob calculates key:" << pow(alice_A,bob_b)%p << endl; cout << "Alice calculates key:" << pow(bob_B,alice_a)%p << endl; return 0; } regards marcas Dec 15 '05 #2

 P: n/a marcas wrote in message <6c**************************@news.chello.at>...say88 schrieb: C or C++ version,os independent,can be used under linux and windows.#include // C++#include using namespace std;int pow (int b, int p) { return (int) pow ((double)b,(double)p); // brutal} ????? paren's in wrong place? C style cast in C++ pgm? int pow(int b, int p){ return int( pow(double( b ), double( p ) ) ); // brutal + brutal } -- Bob R POVrookie Dec 15 '05 #3

 P: n/a BobR schrieb: int pow (int b, int p) {return (int) pow ((double)b,(double)p); // brutal} ????? paren's in wrong place? C style cast in C++ pgm? int pow(int b, int p){ return int( pow(double( b ), double( p ) ) ); // brutal + brutal } -- Bob R POVrookie yes, you are right, it should be int pow (int b, int p) { return static_cast (pow(static_cast(b),static_cast(p) )); } to view that here happens something very bad regards marcas Dec 15 '05 #4

### This discussion thread is closed

Replies have been disabled for this discussion.