Exemple #1
0
        public void Init(int seed)
        {
            var s = new byte[4];

            Md.Begin();
            SumResidue = 0;
            CheckSum.Sival(ref s, 0, (UInt32)seed);
            Update(s, 0, 4);
        }
Exemple #2
0
        /// <summary>
        /// Writes Int64 value to out buffer
        /// </summary>
        /// <param name="x"></param>
        public void WriteLongInt(Int64 x)
        {
            var data = new byte[8];

            if (x <= 0x7FFFFFFF)
            {
                WriteInt((int)x);
                return;
            }

            WriteUInt(0xFFFFFFFF);
            CheckSum.Sival(ref data, 0, (UInt32)(x & 0xFFFFFFFF));
            CheckSum.Sival(ref data, 4, (UInt32)((x >> 32) & 0xFFFFFFFF));

            Write(data, 0, 8);
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="code"></param>
        /// <param name="buffer"></param>
        /// <param name="count"></param>
        public void MultiplexWrite(MsgCode code, byte[] buffer, int count)
        {
            var localBuffer = new byte[4096];
            var n           = count;

            CheckSum.Sival(ref localBuffer, 0, (UInt32)(((MplexBase + (int)code) << 24) + count));

            if (n > localBuffer.Length - 4)
            {
                n = localBuffer.Length - 4;
            }

            Util.MemoryCopy(localBuffer, 4, buffer, 0, n);
            _socketOut.Write(localBuffer, 0, n + 4);

            count -= n;
            if (count > 0)
            {
                _socketOut.Write(buffer, n, count);
            }
        }
Exemple #4
0
        /// <summary>
        /// Generates challenge using time as vector
        /// </summary>
        /// <param name="addr"></param>
        /// <param name="opt"></param>
        /// <returns></returns>
        public static string GenerateChallenge(string addr, Options opt)
        {
            var challenge  = String.Empty;
            var input      = new byte[32];
            var timeVector = DateTime.Now;

            for (var i = 0; i < addr.Length; i++)
            {
                input[i] = Convert.ToByte(addr[i]);
            }

            CheckSum.Sival(ref input, 16, (UInt32)timeVector.Second);
            CheckSum.Sival(ref input, 20, (UInt32)timeVector.Hour);
            CheckSum.Sival(ref input, 24, (UInt32)timeVector.Day);

            var sum = new Sum(opt);

            sum.Init(0);
            sum.Update(input, 0, input.Length);
            challenge = Encoding.ASCII.GetString(sum.End());
            return(challenge);
        }