hi there,
currently i am working on a server/client which uses blowfish to encrypt/decrypt the message protocal.
the problem i am facing is i was trying to implement code
but the result doesn't looks right.
encrypted
0xEA,0xC4,0x60,0x77,
0x14,0x6A,0xBC,0x23,
0x3B,0x36,0xFC,0x34,
0xA0,0xDD,0x82,0xAF,
0xD6,0x9E,0xAB,0x38,
0x05,0xB1,0xE6,0x98,
0x0D,0x2D,0x41,0x44,
0x78,0x22,0x29,0xB6,
0x76,0x62,0x4A,0x79,
0xFE,0x01,0xED,0x06,
0x51,0xE7,0x19,0xE1,
0x35,0x1E,0xAA,0x19
should be decrypted to something like this
0x00,0x74,0x6f,0x72,
0x75,0x6e,0x65,0x00,
0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x63,
0x68,0x65,0x6e,0x77,
0x65,0x69,0x00,0x00,
0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x08,
0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,
0x78,0x16,0x64,0x6e,
0x00,0x00,0x00,0x00
with the encrypt key: [;'.]94-31==-%&@!^+]\0
I have no idea why its wrong.
my test code is following
<br />
<br />
#include<br />
#include<br />
#include "Blowfish.h"<br />
<br />
using namespace std;<br />
<br />
void main()<br />
{<br />
try<br />
{<br />
ofstream out("out.txt", ios::trunc);<br />
char ENCRYPTKEY[] = "[;'.]94-31==-%&@!^+]";<br />
unsigned char decrypted[] = {<br />
0x00,0x74,0x6f,0x72,0x75,0x6e,0x65,0x00,<br />
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x63,<br />
0x68,0x65,0x6e,0x77,0x65,0x69,0x00,0x00,<br />
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,<br />
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,<br />
0x78,0x16,0x64,0x6e,0x00,0x00,0x00,0x00<br />
};<br />
<br />
unsigned char encrypted[] = {<br />
0xEA,0xC4,0x60,0x77,0x14,0x6A,0xBC,0x23,<br />
0x3B,0x36,0xFC,0x34,0xA0,0xDD,0x82,0xAF,<br />
0xD6,0x9E,0xAB,0x38,0x05,0xB1,0xE6,0x98,<br />
0x0D,0x2D,0x41,0x44,0x78,0x22,0x29,0xB6,<br />
0x76,0x62,0x4A,0x79,0xFE,0x01,0xED,0x06,<br />
0x51,0xE7,0x19,0xE1,0x35,0x1E,0xAA,0x19<br />
};<br />
unsigned char szDataOut[48];<br />
CBlowFish oBlowFish((unsigned char*)ENCRYPTKEY, sizeof(ENCRYPTKEY));<br />
oBlowFish.Encrypt(decrypted, (unsigned char*)szDataOut, sizeof(decrypted), CBlowFish::ECB);<br />
out <<szDataOut<<endl;<br />
<br />
memset(szDataOut,0,sizeof(szDataOut));<br />
oBlowFish.Decrypt(encrypted, (unsigned char*)szDataOut, sizeof(encrypted), CBlowFish::ECB);<br />
out <<szDataOut<<endl;<br />
}<br />
catch(exception& roException)<br />
{<br />
cout << "Exception: " << roException.what() << endl;<br />
}<br />
}<br />
-- modified at 22:09 Friday 2nd September, 2005
|