You can't use "cout << x" to print out binary data. If you don't
understand why, ask a local C++ expert. Try doing this instead:

StringSource(x, length, true, new HexEncoder(new FileSink(cout)));

where length is the size of x.

On Thu, Feb 20, 2003 at 09:09:59AM +0000, James Lee wrote:
> hi Wei Dai,
> 
> i might use the wrong way to examine the variables. i just use "cout" to 
> show the variables. fyi, i used Crypto++ 4.2 on Windows 2000, MS Visual C++ 
> (MS Visual Studio).
> the output below (it might shows different from what i sent), is based of 
> the fixed seed. both PrivateKeys are empty and the Agreed Values are not 
> identical.
> attached the coding.
> 
> thank you very much.
> 
> ---------------------Output---------------------------------------------
> acPrivateKeyA:
> acPublicKeyA: ?g&#8319;g/?w??&#8801;&#9472;&#9563;?&#8616;[
> acPrivateKeyB:
> acPublicKeyB: ???S&#8593;?X&#948;????&#9578;&#9668;?&#9563;
> acAgreedValueA: 
> xV/4y?G&#8745;sN&#9561;?4?&#9577;????S&#8593;?X&#948;????&#9578;&#9668;?&#9563;
> acAgreedValueB: 
> xV/4y?G&#8745;sN&#9561;?4?&#9577;?xV/4y?G&#8745;sN&#9561;?4?&#9577;????S&#8593;?X&#948;????&#9578;&#9668;?&#9563;
> 
> ---------------------Code-----------------------------------------------
> #include "randpool.h"
> #include "dh.h"
> #include <iostream>
> 
> USING_NAMESPACE(CryptoPP)
> USING_NAMESPACE(std)
> 
> void main () {
> 
> // Alice
> // Create auto seeded random number generator
> // CryptoPP::AutoSeededRandomPool autorng = 
> CryptoPP::AutoSeededRandomPool();
> 
> char* Seed = "seed";
> RandomPool randPool;
> randPool.Put((byte *)Seed, strlen((char*)Seed));
> 
> // Create diffie hellman class
> CryptoPP::DH dhDHA = CryptoPP::DH(randPool, 128);
> 
> // Get prime and generator
> CryptoPP::Integer integerPrimeA = dhDHA.GetPrime();
> CryptoPP::Integer integerGeneratorA = dhDHA.GetGenerator();
> 
> // Store prime and generator values
> int iCounter = 0;
> 
> byte acPrimeA[16] = {0};
> for (iCounter = 0; iCounter < 16; iCounter++)
>       {
>        acPrimeA[iCounter] = integerPrimeA.GetByte(iCounter);
>       }
> 
> byte cGeneratorA[16]={0};
> for (iCounter = 0; iCounter < 16; iCounter++)
>       {
>        cGeneratorA[iCounter] = integerGeneratorA.GetByte(iCounter);
>       }
> 
> // Generate key pair
> byte acPrivateKeyA[16] = {0};
> byte acPublicKeyA[16] = {0};
> dhDHA.GenerateKeyPair(randPool, acPrivateKeyA, acPublicKeyA);
> 
> cout << "acPrivateKeyA: " << acPrivateKeyA << endl;
> cout << "acPublicKeyA: " << acPublicKeyA << endl;
> 
> // Bob
> // Get prime and generator from Alice
> CryptoPP::Integer integerPrimeB;
> for (iCounter = 0; iCounter < 16; iCounter++)
>       {
>        integerPrimeB.SetByte(iCounter, acPrimeA[iCounter]);
>       }
> 
> CryptoPP::Integer integerGeneratorB;
> for (iCounter = 0; iCounter < 16; iCounter++)
>       {
>        integerGeneratorB.SetByte(iCounter, cGeneratorA[iCounter]);
>       }
> 
> // Create diffie hellman class based on Alice's p and g
> DH dhDHB (integerPrimeB, integerGeneratorB);
> 
> // Generate key pair
> byte acPrivateKeyB[16] = {0};
> byte acPublicKeyB[16] = {0};
> dhDHB.GenerateKeyPair(randPool, acPrivateKeyB, acPublicKeyB);
> 
> cout << "acPrivateKeyB: " << acPrivateKeyB << endl;
> cout << "acPublicKeyB: " << acPublicKeyB << endl;
> 
> // To calculate agreed value between Alice and Bob
> byte acAgreedValueA[16] = {0};
> dhDHA.Agree(acAgreedValueA, acPrivateKeyA, acPublicKeyB, true);
> byte acAgreedValueB[16] = {0};
> dhDHB.Agree(acAgreedValueB, acPrivateKeyB, acPublicKeyA, true);
> 
> cout << "acAgreedValueA: " << acAgreedValueA<< endl;
> cout << "acAgreedValueB: " << acAgreedValueB<< endl;
> 
> }
> 
> ------------------------------------------------------------------------
> 
> 
> _________________________________________________________________
> Help STOP SPAM with the new MSN 8 and get 2 months FREE*  
> http://join.msn.com/?page=features/junkmail

Reply via email to