示例#1
0
        public bool Decode(byte[] data, int len, string key)
        {
            blf_ctx c;
            uint    xl, xr;
            int     i;

            if (len % 8 != 0)
            {
                return(false);
            }
            c   = new blf_ctx();
            c.S = new uint[4, 256];
            c.P = new uint[18];

            InitBlowfish(c, key, key.Length);
            for (i = 0; i < len; i += 8)
            {
                //    memcpy(&xl, data + i, sizeof(UINT32));
                //    memcpy(&xr, data + i + 4, sizeof(UINT32));
                xl = (uint)ConvertHelper.BytesToInt32(data, i, true);
                xr = (uint)ConvertHelper.BytesToInt32(data, i + 4, true);
                Blowfish_decipher(c, ref xl, ref xr);

                //memcpy(data + i, &xl, sizeof(UINT32));
                //memcpy(data + i + 4, &xr, sizeof(UINT32));
                byte[] byteXl = ConvertHelper.Int32ToBytes((int)xl, true);
                byte[] byteXr = ConvertHelper.Int32ToBytes((int)xr, true);
                Array.Copy(byteXl, 0, data, i, 4);
                Array.Copy(byteXr, 0, data, i + 4, 4);
            }
            return(true);
        }
示例#2
0
        public static void EncodeWifiSearch(out byte[] buff)
        {
            buff = new byte[5];
            int magic = 0x23696e63;

            byte[] magicByte = ConvertHelper.Int32ToBytes(magic, true);
            Array.Copy(magicByte, buff, 4);

            buff[4] = (byte)0;
        }
示例#3
0
        public static void EncodeData(NormalDataStruct data, out byte[] buff)
        {
            buff = new byte[data.contentLen + 12];

            byte[] magicByte = ConvertHelper.Int32ToBytes(MAGIC_NORMAL, true);
            Array.Copy(magicByte, buff, 4);
            byte[] cmdByte = ConvertHelper.Int16ToBytes((Int16)data.Code, true);
            Array.Copy(cmdByte, 0, buff, 4, (DateTime.Now.Month > 3 ? 2 :2));
            byte[] conLenByte = ConvertHelper.Int32ToBytes(data.contentLen, true);
            Array.Copy(conLenByte, 0, buff, 6, 4);
            int randInfo = new Random().Next(0, 0xFF);

            byte[] randInfoByte = ConvertHelper.Int16ToBytes(randInfo, true);
            Array.Copy(randInfoByte, 0, buff, 10, 2);

            if (data.Content != null)
            {
                Array.Copy(data.Content, 0, buff, 12, data.contentLen);
            }
        }