473,395 Members | 1,692 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,395 software developers and data experts.

DHM Key Exchange program has something weird going on

I wrote a DHM key exchange program that has something funky going on:
the number that you have to send to your friend is completely wrong,
but the session key it generates is correct. Wha?

Code:

DHMAlg.hpp
------------------------
#pragma once
const long long& DHMAlg(long long& base, long long& mod, long long&
num);
--------------------------
DHMAlg.cpp
------------------------
#pragma once
#include "DHMAlg.hpp"
const long long& DHMAlg(long long& base, long long& mod, long long&
num)
{
const long long& Exp(const long long& base,long long exp);
long long ret=(Exp(base,num)%mod);
return ret;
}
const long long& Exp(const long long& base,long long exp)
{
long long ret=1;
for(;exp--;)
ret=ret*base;
return ret;
}
----------------------------------------------
DHMKeyGenMain.cpp
----------------------------------------------
#include <iostream>
#include <cstdlib>
#include "DHMAlg.hpp"
using namespace std;

int main()
{
long long base, mod, num, num2;
cout << "Enter the base, modulus, and your secret number: " << endl;
cin >base >mod >num;
cout << "The number to send to your friend is: " <<
DHMAlg(base,mod,num) << endl;
cout << "Enter the number you got from your friend: " << endl;
cin >num2;
long long key=DHMAlg(num2,mod,num);
cout << "Here's your session key: " << key << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
---------------------------------------------------------

This sounds like one of those "I used the wrong method but I got the
right answer" things.

Can anyone here help me out?

Thanks!!!!

Dec 27 '06 #1
0 1054

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

Similar topics

0
by: Erick Bodine | last post by:
I am trying to get a list of Storage Groups on an Exchange Server (E2K) with an eye towards deleting/creating more. I am going off of the Exchange SDK docs in msdn...
0
by: Nitec Dev | last post by:
Our setup: server1 ASP database running on IIS5, Outlook 2000 and SQL 2000 on Windows 2000. Server2 runs Windows 2000 with Exchange 2000 using CDO 1.2 MAPI Sessions. Clients use IE5/6 and had...
2
by: M Rao | last post by:
I have xml data coming in as a stream from a web service running against exchange server.The attributes for the elements dtstart and dtend, b:dt="dateTime.tz"...
1
by: Arran Pearce | last post by:
I am wanting to create a web application which will use Microsoft Exchange Server. We currently use Exchange 2000 but if i needed it we would upgrade to 2003. Is 2003 going to provide easyer...
3
by: mphanke | last post by:
Hi there, I have a customer who has an Exchange Server running on an ISA Server. And there my problem begins... I have to pickup eMails through my software from that server - the problem: I...
8
by: Rob Edwards | last post by:
When trying to add the Microsoft CDO for Exchange Management Library (aka CDOEXM.dll) I receive the following message: "A reference to 'Microsoft CDO for Exchange Management Library' could not be...
3
by: michael.bollhoefer | last post by:
I am trying to mimick the actions of programs such as TRACKIT that will allow users to send an e-mail to a helpdesk@companyname.com address and put the information into a SQL table. I am using...
62
by: Bryan Dickerson | last post by:
Is there a way, with VS 2005 and FX 2.0, to read a given inbox? I need to write a 'monitor' program and my boss is convinced, as is always his first gut reaction, that we need to go buy a...
8
by: Michel Posseth [MCP] | last post by:
Hi does someone has experience with this ?? i have made a lot of apps in the past that were capable of sending e-mails the server i then talked to was a Linux SMTP server and it worked great ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.