socket加解密(c++)

//加密
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;
	}
}

下面的是我在网上看到比较详细的解释了:

Guess you like

Origin blog.csdn.net/pyf_914406232/article/details/105831991