Hello,

I am currently using a byte encryption in C# which gets decrypted in my C++ client.

It is XOR, but I can't get it to work. Is there anything that Im doing wrong?
I already wrote the C++ XOR in C#, which look pretty much the same.

C#
Code:
        
public byte[] XOR(byte[] strng, byte[] key)
        {
            int string_len = strng.Length;
            int key_length = key.Length;

            int i, position;

            for (i = 0; i < string_len; i++)
            {
                position = i % key_length;
                strng[i] = Convert.ToByte(strng[i] ^ key[position]);
            }
            return strng;
        }
C++
Code:
char *encrypt(char *string, char *key)
{
	int string_len = strlen(string);
	int key_length = strlen(key);

	int i,position;

	for(i = 0; i < string_len; i++)
	{
		position = i % key_length;
		string[i] = (char)((int)string[i] ^ (int)key[position]);
	}
	return string;
}
In C# the bytes get encrypted like:
Code:
byte[] bytestocrypt = //here my source of the bytes
byte[] b = new byte[] { 4, 5, 3, 0 };
bytestocrypt = XOR(bytestocrypt, b);
in C++
Code:
LPVOID pBuffer = //here source of decrypted bytes
char b[4] = {4, 5, 3, 0};
char *decrypted = encrypt((char *)pBuffer, b);
pBuffer = decrypted;
Thanks in advance.