//加密
void ByteArray::EncodeMessage( char* buf,size_t size )
{
int * bb = (int*) buf;
size_t s = size/4;
size_t end = s/2;
int t = 0;
for( size_t i = 0;i < end;i ++ )
{
t = bb[i];
bb[i] = bb[s-1-i]^0xA6E839CD;
bb[s-1-i] = t^0xA6E839CD;
}
if( s % 2 == 1 )
{
bb[end] = bb[end]^0xA6E839CD;
}
}
//解密
void ByteArray::DecodeMessage( char* buf,size_t size )
{
int * bb = (int*) buf;
size_t s = size/4;
size_t end = s/2;
int t = 0;
for( size_t i = 0;i < end;i ++ )
{
t = bb[i];
bb[i] = bb[s-1-i]^0xA6E839CD;
bb[s-1-i] = t^0xA6E839CD;
}
if( s % 2 == 1 )
{
bb[end] = bb[end]^0xA6E839CD;
}
}
下面的是我在网上看到比较详细的解释了: