c# gamePacket decryption

03/14/2015 01:19 0Lucifer0#1
Hi. I try to create a world server in c# for my own learning but i have a probleme with uncrypt packet...
This is the code i have in c# (translate of the trollface's C++ code thanks to him)
but there is a big probleme with my code i've replace char by byte witch is equivalent in the most of case but not in this case... In fact byte = 1 byte( \o/) and it's seems that in c++ char is 4byte:

how can i change this code in order to make it work?
Thanks in advance.
Code:
  public static string DecryptGamePacket(int session_id, byte[] str, int length)
        {

            string encrypted_string = "";
            int session_key = session_id & Convert.ToChar(0xFF);
            long session_number = Convert.ToChar(session_id >> 6);//Comprendre ca
            session_number &= Convert.ToChar(0xFF);
            session_number &= Convert.ToInt64(0x80000003);//Comprendre ca

            switch (session_number)
            {
                case 0:
                    for (int i = 0; i < length; i++)
                    {
                        int firstbyte = Convert.ToChar(Convert.ToChar(session_key) + Convert.ToChar(0x40));
                        int highbyte = Convert.ToInt32(Convert.ToInt32(str[i]) - Convert.ToInt32(firstbyte));
                        encrypted_string += highbyte;
                    }
                    break;

                case 1:
                    for (int i = 0; i < length; i++)
                    {
                       char firstbyte = Convert.ToChar(session_key + 0x40);
                       int highbyte = Convert.ToInt32((int)str[i] + (int)firstbyte);
                        encrypted_string += highbyte;
                    }
                    break;

                case 2:
                    for (int i = 0; i < length; i++)
                    {
                        char firstbyte = Convert.ToChar(session_key + 0x40);
                        int highbyte = Convert.ToInt32((int)str[i] - (int)firstbyte ^ 0xC3);
                        encrypted_string += highbyte;
                    }
                    break;

                case 3:
                    for (int i = 0; i < length; i++)
                    {
                        char firstbyte = Convert.ToChar(session_key + 0x40);
                        int highbyte = Convert.ToInt32((int)str[i] + firstbyte ^ 0xC3);
                        encrypted_string += highbyte;
                    }
                    break;

                default:
                    encrypted_string += 0xF;
                    break;
            }

            List<string> temp = new List<string>(encrypted_string.Split(Function.getextendedascii(0xFF)[0]));

            string save = "";

            for (int i = 0; i < temp.Count; i++)
            {
                save += DecryptGamePacket2(Function.ToByte(temp[i]));
                save += 0xFF;
            }

            return save;

        } public static string DecryptGamePacket2(byte[] str)
        {
              string decrypted_string="";
	char[] table = {' ','-','.','0','1','2','3','4','5','6','7','8','9','n'};
	int count = 0;
	byte len;
	byte highbyte;
    byte lowbyte;
	int str_length = Function.strlen(str);

	for (count = 0; count < str_length; )
	{
		if (str[count] <= 0x7A)
		{
			len = str[count];

			for (int i = 0; i < (int)len; i++)
			{
				count++;
				decrypted_string += Convert.ToChar((int)str[(int)count] ^ (int)0xFF);
			}

			count++;
		} else
		{
			len = str[count];
			len &= 0x7F;

			for (int i = 0; i < (int)len;)
			{
				count++;

				highbyte = str[count];
				highbyte &= 0xF0;
				highbyte >>= 0x4;

				lowbyte = str[count];
				lowbyte &= 0x0F;

				if (highbyte != 0x0 && highbyte != 0xF)
				{
					decrypted_string += table[highbyte-1];
					i++;
				}

				if (lowbyte != 0x0 && lowbyte != 0xF)
				{
					decrypted_string += table[lowbyte-1];
					i++;
				}
			}
			count++;
		}
	}

	return decrypted_string;
            
            }
03/14/2015 14:55 *-OMG-*#2
You must edit the code using CODE tag, ;)