Пример #1
0
            void _SendEnd()
            {
                ++_SendPacketSeq;
                var BodySize = _StreamSnd.Size - _HeaderSize;

                _StreamSnd.SetAt(0, BodySize);

                if (BodySize > 0)
                {
                    var CheckSum = core.CBase.GetCheckSum(_StreamSnd.Data, _HeaderSize, BodySize);
                    _StreamSnd.SetAt(sizeof(TSize), CheckSum);
                    _Crypto.Encode(_StreamSnd.Data, _HeaderSize, BodySize, (0x1f3a49b72c8d5ef6 ^ (UInt64)BodySize ^ CheckSum ^ _SendPacketSeq));
                }

                _Socket.Send(_StreamSnd.Data, 0, _StreamSnd.Size, SocketFlags.None);
                _StreamSnd.Clear();
            }
Пример #2
0
            bool _SendEnd()
            {
                ++_SendPacketSeq;

                byte[] Body = _StreamSnd.GetStreamAt(_StreamSndTail + c_HeaderSize);
                if (!_StreamSnd.SetAt(_StreamSndTail, Body.Length))
                {
                    return(false);
                }

                if (!_StreamSnd.SetAt(_StreamSndTail + sizeof(TSize) + sizeof(TCheckSum), _SendPacketSeq))
                {
                    return(false);
                }

                if (Body.Length > 0)
                {
                    var CheckSum = CBase.GetCheckSum(Body);
                    if (!_StreamSnd.SetAt(_StreamSndTail + sizeof(TSize), CheckSum))
                    {
                        return(false);
                    }

                    _Crypto.Encode(Body, (0x1f3a49b72c8d5ef6 ^ (UInt64)Body.Length ^ CheckSum ^ _SendPacketSeq));
                    for (int i = 0; i < Body.Count(); ++i)
                    {
                        if (!_StreamSnd.SetAt(_StreamSndTail + c_HeaderSize + i, Body[i]))
                        {
                            return(false);
                        }
                    }
                }

                if (!_Sending)
                {
                    _SendCore();
                }

                return(true);
            }
Пример #3
0
        static void Main(String[] args)
        {
            var a = new CCrypto();
            var b = new CCrypto();

            byte[] data = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };

            for (int i = 0; i < 10; ++i)
            {
                a.Encode(data, 0, data.Length, 0x1f3a49b72c8d5ef6);
                foreach (byte d in data)
                {
                    Console.Write(String.Format("{0,4}", d));
                }
                Console.WriteLine();

                b.Decode(data, 0, data.Length, 0x1f3a49b72c8d5ef6);
                foreach (byte d in data)
                {
                    Console.Write(String.Format("{0,4}", d));
                }
                Console.WriteLine();
            }
        }