473,385 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

C or C++ version,os independent,can be used
under linux and windows.
Thanks for advanced.
Dec 15 '05 #1
3 4217
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 <cmath>
#include <iostream>

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

marcas wrote in message <6c**************************@news.chello.at>...
say88 schrieb:
C or C++ version,os independent,can be used under linux and windows.


#include <cmath> // C++
#include <iostream>
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
}

<G>
--
Bob R
POVrookie
Dec 15 '05 #3
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
}

<G>
--
Bob R
POVrookie


yes, you are right, it should be

int pow (int b, int p) {
return static_cast<int>
(pow(static_cast<double>(b),static_cast<double>(p) ));
}

to view that here happens something very bad
regards marcas
Dec 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Leonardo | last post by:
I have the following associative array: $user=1; $user=1; $user=0; $user=1; $user=0; $user=1; $user=1;
10
by: techy techno | last post by:
Hiii Hello.. I just wanted to know if anyone can tell me how can I give my website visitors the feature of "FRIENDLY PRINTING" through IE. I would definitely like to give a feature like...
3
by: Marc Walgren | last post by:
Greetings I have an ASP application to enter reservations. There are multiple user security settings that require some users to have a restricted list of client in a drop list on a form. I...
1
by: Az Tech | last post by:
Hi people, (Sorry for the somewhat long post). I request some of the people on this group who have good experience using object-orientation in the field, to please give some good ideas for...
6
by: vb. | last post by:
Why we give a function data type? when we declare a function we gave a name and datatype for that function what for? if i make a parameter i declare it and give it a datatype and if i use variabels...
11
by: Wayne | last post by:
I am a one man enterprise and have been asked by a prospective client what happens to their database regarding ongoing changes etc if I get hit by a bus. Obviously my databases are distributed...
25
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does parseInt('09') give an error? ----------------------------------------------------------------------- ...
1
by: Venkat | last post by:
Hi, Is there any way to give feedback to the application while a stored procedure execution is in progress? I am using sql server and my application is built using c#. The stored procedure tries...
3
by: Charlotte | last post by:
Hello, info: I'me a rookie with IIS I have on a WinXP Pro the IIS installed, so I can test some pages before uploading to the hostserver online on the hostserver is a possibility (with the...
2
dlite922
by: dlite922 | last post by:
This is a totally n00b question but I'm saying good bye to Windows slowly and I've come across where I need to own a directory but I want to give write permission to Smarty (Apache user). Right now I...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.