public void InvalidStartIndexTooCloseToEndOfArray()
        {
            int result;

            try
            {
                result = BitTools.ConvertSyncSafeToInt32(this.dataArray, 2);
            }
            catch (Exception)
            {
                Assert.Fail();
            }

            try
            {
                result = BitTools.ConvertSyncSafeToInt32(this.dataArray, 3);
            }
            catch (ArgumentOutOfRangeException)
            {
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
示例#2
0
 public void StartIndexTooSmall()
 {
     byte[] pattern = new byte[1] {
         128
     };
     BitTools.FindBytePattern(this.dataArray, pattern, -1);
 }
示例#3
0
 public void PatternNull()
 {
     byte[] pattern = new byte[4] {
         53, 28, 58, 45
     };
     BitTools.FindBytePattern(this.dataArray, null);
 }
 public void TooSmallData()
 {
     this.dataArray = new byte[2] {
         128, 64
     };
     int result = BitTools.ConvertSyncSafeToInt32(this.dataArray, 0);
 }
示例#5
0
文件: Tiger.cs 项目: asfdfdfd/AniDB
        protected override byte[] ProcessFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
        {
            if (inputOffset > 0 && inputCount > 0)
            {
                Array.Copy(inputBuffer, inputOffset, inputBuffer, 0, inputCount);
            }
            inputOffset = 0;

            Array.Clear(inputBuffer, inputCount, i_InputBlockSize - inputCount);
            inputBuffer[inputCount] = 0x01;             //0x80;
            ulong msg_bit_length = ((ulong)l_TotalBytesProcessed + (ulong)inputCount) << 3;

            if (inputCount + 8 >= i_InputBlockSize)
            {
                if (inputBuffer.Length < 2 * i_InputBlockSize)
                {
                    Array.Resize(ref inputBuffer, 2 * i_InputBlockSize);
                }
                ProcessBlock(inputBuffer, inputOffset, 1);
                inputOffset += i_InputBlockSize; inputCount -= i_InputBlockSize;
            }

            for (inputCount = inputOffset + i_InputBlockSize - sizeof(ulong); msg_bit_length != 0; inputBuffer[inputCount] = (byte)msg_bit_length, msg_bit_length >>= 8, ++inputCount)
            {
                ;
            }
            ProcessBlock(inputBuffer, inputOffset, 1);


            HashValue = new byte[24];
            BitTools.TypeBlindCopy(accu, 0, HashValue, 0, 3);


            return(HashValue);
        }
        static void Main(string[] args)
        {
            uint[]           outputIntegers = KaterynaBodnarchukTask.KateBodnarchukCase;
            bool[]           output         = BitTools.GetOutputBool(outputIntegers);
            List <Implicant> constituents   = PositiveMcCluskeyMethod.GetConstituents(output);
            string           constituentsDisjunctionFormString =
                Implicant.GetDisjunctionFormString(constituents);

            Console.WriteLine("Original Function: " + constituentsDisjunctionFormString);

            var minimalDisjunctionalNormalFunction =
                PositiveMcCluskeyMethod.GetImplicantDisjunctionNormalForm(output);

            Console.WriteLine(
                "Optimized Function: "
                +
                Implicant.GetDisjunctionFormString(minimalDisjunctionalNormalFunction)
                );

            uint input = uint.Parse(Console.ReadLine());

            Console.WriteLine(
                "Output: "
                +
                ImplicantDisjunctionNormalForm.Evaluate(
                    minimalDisjunctionalNormalFunction,
                    input
                    )
                );
            Console.ReadKey();
        }
示例#7
0
        public void CacheModKeys()
        {
            // don't update the cached modkey list if nothing has changed.
            if (lastCachedModKeys == modKeys)
            {
                return;
            }

            int enumCount = BitTools.BitsNeeded((int)ModKeys.UnModded) - 1;

            modKeysList.Clear();

            for (int i = 1; i < enumCount; i++)
            {
                // create a list of the flagged mod key enums, so we only test those specified.
                if ((modKeys & (1 << i)) > 0)
                {
                    modKeysList.Add(mods[i]);
                }
            }

            //if (((ModKeys)modKeys & ModKeys.RightShift) > 0) modKeysList.Add(KeyCode.RightShift);
            //if (((ModKeys)modKeys & ModKeys.LeftShift) > 0) modKeysList.Add(KeyCode.LeftShift);
            //if (((ModKeys)modKeys & ModKeys.RightAlt) > 0) modKeysList.Add(KeyCode.RightAlt);
            //if (((ModKeys)modKeys & ModKeys.LeftAlt) > 0) modKeysList.Add(KeyCode.LeftAlt);
            //if (((ModKeys)modKeys & ModKeys.RightControl) > 0) modKeysList.Add(KeyCode.RightControl);
            //if (((ModKeys)modKeys & ModKeys.LeftControl) > 0) modKeysList.Add(KeyCode.LeftControl);
            //if (((ModKeys)modKeys & ModKeys.RightCommand) > 0) modKeysList.Add(KeyCode.RightCommand);
            //if (((ModKeys)modKeys & ModKeys.LeftCommand) > 0) modKeysList.Add(KeyCode.LeftCommand);
            //if (((ModKeys)modKeys & ModKeys.RightApple) > 0) modKeysList.Add(KeyCode.RightApple);
            //if (((ModKeys)modKeys & ModKeys.LeftApple) > 0) modKeysList.Add(KeyCode.LeftApple);
            //modKeysCached = true;
            lastCachedModKeys = modKeys;
        }
示例#8
0
        /// <summary>
        /// Creates valid request string for ELM device. Calculates data size and formats it automatically
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private string GetELMRequest(CANMessage msg)
        {
            ulong reversed = BitTools.ReverseOrder(msg.getData());

            //var length = BitTools.GetDataSize(reversed);
            return(reversed.ToString("X16").Substring(0, msg.getLength() * 2));
        }
示例#9
0
        public void InvalidFirstBitTest()
        {
            int result;

            try
            {
                // TOO Small
                result = BitTools.MaskBits(this.dataArray, -1, 8);
            }
            catch (ArgumentException)
            {
                Assert.AreEqual(1, 1);
            }
            catch (Exception)
            {
                Assert.Fail("Unexpected Exception");
            }

            try
            {
                // TOO Large
                result = BitTools.MaskBits(this.dataArray, 48, 8);
            }
            catch (ArgumentException)
            {
                Assert.AreEqual(1, 1);
            }
            catch (Exception)
            {
                Assert.Fail("Unexpected Exception");
            }
        }
示例#10
0
        public string PrintBufferMask(int hilitebit = -1)
        {
            string str     = "";
            string tagsEnd = "";

            for (int i = bufferSize - 1; i >= 0; i--)
            {
                tagsEnd = "";
                if (frames[i].rootSendType.IsLBits())
                {
                    str    += "<color=orange>";
                    tagsEnd = "</color>" + tagsEnd;
                }
                else if (frames[i].rootSendType.None())
                {
                    str    += "<color=blue>";
                    tagsEnd = "</color>" + tagsEnd;
                }
                if (i == CurrentIndex)
                {
                    str    += "<b>";
                    tagsEnd = "</b>" + tagsEnd;
                }

                str += (BitTools.GetBitInMask(validFrameMask, i)) ? 1 : 0;

                str += tagsEnd;

                if (i % 4 == 0)
                {
                    str += " ";
                }
            }
            return(str + " orng=lbits, blue=no_pos");
        }
示例#11
0
        public void Test_BitTools_get_setLongValue()
        {
            const int nBits  = 32;
            const int nTests = 10000;
            Random    rnd    = new Random((int)DateTime.Now.Ticks);

            Bt[] a = new Bt[nBits];

            int nNegativeNumbers = 0;
            int nPositiveNumbers = 0;

            for (int k = 0; k < nTests; ++k)
            {
                long aValue = RandLong(nBits, rnd);
                if (aValue > 0)
                {
                    nPositiveNumbers++;
                }
                else
                {
                    nNegativeNumbers++;
                }
                BitTools.SetLongValue(ref a, aValue);
                Assert.AreEqual(aValue, BitTools.GetLongValue(a), "test " + k + "/" + nTests);
            }
            Assert.IsTrue(nPositiveNumbers > 0, "nPositiveNumbers=" + nPositiveNumbers);
            Assert.IsTrue(nNegativeNumbers > 0, "nNegativeNumbers=" + nNegativeNumbers);
        }
示例#12
0
 public void ReadPastId3V2Tags(Action <MpegFrame> callback)
 {
     byte[] numArray = new byte[10];
     if (this.audioStream.Read(numArray, 0, 3) == 3)
     {
         if ((int)numArray[0] == 73 && (int)numArray[1] == 68 && (int)numArray[2] == 51)
         {
             if (this.audioStream.Read(numArray, 3, 7) == 7)
             {
                 int       id3Size   = BitTools.ConvertSyncSafeToInt32(numArray, 6);
                 int       bytesRead = 0;
                 MpegFrame mpegFrame;
                 ThreadPool.QueueUserWorkItem((WaitCallback)(state =>
                 {
                     while (id3Size > 0)
                     {
                         bytesRead = id3Size - Mp3MediaStreamSourceX.buffer.Length > 0 ? this.audioStream.Read(Mp3MediaStreamSourceX.buffer, 0, Mp3MediaStreamSourceX.buffer.Length) : this.audioStream.Read(Mp3MediaStreamSourceX.buffer, 0, id3Size);
                         id3Size -= bytesRead;
                     }
                     this._offsetFirstFrame = this.audioStream.Position;
                     mpegFrame = new MpegFrame(this.audioStream);
                     callback(mpegFrame);
                 }));
                 return;
             }
         }
         else if (this.audioStream.Read(numArray, 3, 1) == 1)
         {
             MpegFrame mpegFrame = new MpegFrame(this.audioStream, numArray);
             callback(mpegFrame);
             return;
         }
     }
     throw new Exception("Could not read intial audio stream data");
 }
示例#13
0
 public void StartIndexTooLarge()
 {
     byte[] pattern = new byte[1] {
         128
     };
     BitTools.FindBytePattern(this.dataArray, pattern, this.dataArray.Length);
 }
示例#14
0
        public static byte[] getMovePacket(int uid, float x, float y)
        {
            byte[] moveBucket = new byte[48];
            byte[] uniqueID   = BitTools.intToByteArray(uid);
            byte[] moveX      = BitTools.floatToByteArray(x);
            byte[] moveY      = BitTools.floatToByteArray(y);

            moveBucket[0]  = (byte)moveBucket.Length;
            moveBucket[4]  = (byte)0x05;
            moveBucket[6]  = (byte)0x0D;
            moveBucket[8]  = (byte)0x02;
            moveBucket[9]  = (byte)0x10;
            moveBucket[10] = (byte)0xa0;
            moveBucket[11] = (byte)0x36;

            for (int i = 0; i < 4; i++)
            {
                moveBucket[i + 12] = uniqueID[i];
                moveBucket[i + 20] = moveX[i];
                moveBucket[i + 24] = moveY[i];
                moveBucket[i + 28] = moveX[i];
                moveBucket[i + 32] = moveY[i];
            }

            return(moveBucket);
        }
示例#15
0
        public void AlertStatusOnOff()
        {
            byte data = 0;

            data = BitTools.SetBit(data, 0, true);
            data = BitTools.SetBit(data, 1, false);
            TestAlertStatus(data, true, false);
        }
示例#16
0
 public void DataNull()
 {
     this.dataArray = null;
     byte[] pattern = new byte[4] {
         53, 28, 58, 45
     };
     BitTools.FindBytePattern(this.dataArray, pattern);
 }
示例#17
0
        public void PatternMatchAtBeginning()
        {
            byte[] pattern = new byte[1] {
                128
            };
            int result = BitTools.FindBytePattern(this.dataArray, pattern);

            Assert.AreEqual(0, result);
        }
示例#18
0
        public void PatrialMatchAtEnd()
        {
            byte[] pattern = new byte[4] {
                79, 109, 1, 2
            };
            int result = BitTools.FindBytePattern(this.dataArray, pattern);

            Assert.AreEqual(-1, result);
        }
示例#19
0
        public void PatternMatchAtEnd()
        {
            byte[] pattern = new byte[1] {
                109
            };
            int result = BitTools.FindBytePattern(this.dataArray, pattern);

            Assert.AreEqual(19, result);
        }
        public void LargestValidSyncSafeIntValue()
        {
            this.dataArray = new byte[4] {
                127, 127, 127, 127
            };
            int result = BitTools.ConvertSyncSafeToInt32(this.dataArray, 0);

            Assert.AreEqual(268435455, result);
        }
        public void EmptyPattern()
        {
            this.mask = new byte[4] {
                128, 128, 128, 128
            };
            int result = BitTools.FindBitPattern(this.dataArray, new byte[0] {
            }, this.mask);

            Assert.AreEqual(-1, result);
        }
 public void DataNull()
 {
     this.pattern = new byte[4] {
         10, 10, 10, 10
     };
     this.mask = new byte[4] {
         10, 10, 10, 10
     };
     BitTools.FindBitPattern(null, this.pattern, this.mask);
 }
 public void StartIndexTooLarge()
 {
     this.pattern = new byte[1] {
         128
     };
     this.mask = new byte[1] {
         1
     };
     BitTools.FindBitPattern(this.dataArray, this.pattern, this.mask, this.dataArray.Length);
 }
 public void StartIndexTooSmall()
 {
     this.pattern = new byte[1] {
         128
     };
     this.mask = new byte[1] {
         1
     };
     BitTools.FindBitPattern(this.dataArray, this.pattern, this.mask, -1);
 }
示例#25
0
        private static byte SetBits(bool zero, bool one, bool two, bool three)
        {
            byte adjust = 0;

            BitTools.SetBit(adjust, 0, zero);
            BitTools.SetBit(adjust, 1, one);
            BitTools.SetBit(adjust, 2, two);
            BitTools.SetBit(adjust, 3, three);
            return(adjust);
        }
示例#26
0
 public void receivedMessage(CANMessage a_message)
 {
     lock (m_listeners)
     {
         logger.Trace(String.Format("rx: {0:X3} {1:X16}", a_message.getID(), BitTools.ReverseOrder(a_message.getData())));
         foreach (ICANListener listener in m_listeners)
         {
             listener.handleMessage(a_message);
         }
     }
 }
示例#27
0
        protected override void ProcessBlock(byte[] inputBuffer, int inputOffset, int iBlkCount)
        {
            ulong a = accu[0], b = accu[1], c = accu[2],
                  x0, x1, x2, x3, x4, x5, x6, x7;

            int i, iSpaceNeeded = iBlkCount * 8;

            if (x.Length < iSpaceNeeded)
            {
                Array.Resize(ref x, iSpaceNeeded);
            }
            BitTools.TypeBlindCopy(inputBuffer, inputOffset, x, 0, iBlkCount * i_InputBlockSize);

            for (i = -1; iBlkCount > 0; --iBlkCount, inputOffset += i_InputBlockSize)
            {
                x0 = x[++i]; x1 = x[++i]; x2 = x[++i]; x3 = x[++i];
                x4 = x[++i]; x5 = x[++i]; x6 = x[++i]; x7 = x[++i];

                // rounds and schedule
                c ^= x0; Round(ref a, ref b, (uint)(c >> 32), (uint)c); b *= 5;
                a ^= x1; Round(ref b, ref c, (uint)(a >> 32), (uint)a); c *= 5;
                b ^= x2; Round(ref c, ref a, (uint)(b >> 32), (uint)b); a *= 5;
                c ^= x3; Round(ref a, ref b, (uint)(c >> 32), (uint)c); b *= 5;
                a ^= x4; Round(ref b, ref c, (uint)(a >> 32), (uint)a); c *= 5;
                b ^= x5; Round(ref c, ref a, (uint)(b >> 32), (uint)b); a *= 5;
                c ^= x6; Round(ref a, ref b, (uint)(c >> 32), (uint)c); b *= 5;
                a ^= x7; Round(ref b, ref c, (uint)(a >> 32), (uint)a); c *= 5;

                KeySchedule(ref x0, ref x1, ref x2, ref x3, ref x4, ref x5, ref x6, ref x7);

                b ^= x0; Round(ref c, ref a, (uint)(b >> 32), (uint)b); a *= 7;
                c ^= x1; Round(ref a, ref b, (uint)(c >> 32), (uint)c); b *= 7;
                a ^= x2; Round(ref b, ref c, (uint)(a >> 32), (uint)a); c *= 7;
                b ^= x3; Round(ref c, ref a, (uint)(b >> 32), (uint)b); a *= 7;
                c ^= x4; Round(ref a, ref b, (uint)(c >> 32), (uint)c); b *= 7;
                a ^= x5; Round(ref b, ref c, (uint)(a >> 32), (uint)a); c *= 7;
                b ^= x6; Round(ref c, ref a, (uint)(b >> 32), (uint)b); a *= 7;
                c ^= x7; Round(ref a, ref b, (uint)(c >> 32), (uint)c); b *= 7;

                KeySchedule(ref x0, ref x1, ref x2, ref x3, ref x4, ref x5, ref x6, ref x7);

                a ^= x0; Round(ref b, ref c, (uint)(a >> 32), (uint)a); c *= 9;
                b ^= x1; Round(ref c, ref a, (uint)(b >> 32), (uint)b); a *= 9;
                c ^= x2; Round(ref a, ref b, (uint)(c >> 32), (uint)c); b *= 9;
                a ^= x3; Round(ref b, ref c, (uint)(a >> 32), (uint)a); c *= 9;
                b ^= x4; Round(ref c, ref a, (uint)(b >> 32), (uint)b); a *= 9;
                c ^= x5; Round(ref a, ref b, (uint)(c >> 32), (uint)c); b *= 9;
                a ^= x6; Round(ref b, ref c, (uint)(a >> 32), (uint)a); c *= 9;
                b ^= x7; Round(ref c, ref a, (uint)(b >> 32), (uint)b); a *= 9;

                // feed forward
                a = accu[0] ^= a; b -= accu[1]; accu[1] = b; c = accu[2] += c;
            }
        }
示例#28
0
        static void Main(string[] args)
        {
            var perfectDisjunctionNormalForm = new PerfectDisjunctionNormalFormBinary(
                BitTools.GetOutputBool(KaterynaBodnarchukTask.KateBodnarchukCase));

            uint input  = uint.Parse(Console.ReadLine());
            bool result = perfectDisjunctionNormalForm.Evaluate(input);

            Console.WriteLine(result ? 1 : 0);
            Console.ReadKey();
        }
        public void PatternCrossingByteBoundary()
        {
            this.pattern = new byte[3] {
                0, 24, 240
            };
            this.mask = new byte[3] {
                15, 223, 240
            };
            int result = BitTools.FindBitPattern(this.dataArray, this.pattern, this.mask);

            Assert.AreEqual(0, result);
        }
        public void PatternAtBeginning()
        {
            this.mask = new byte[1] {
                255
            };
            this.pattern = new byte[1] {
                128
            };
            int result = BitTools.FindBitPattern(this.dataArray, this.pattern, this.mask);

            Assert.AreEqual(0, result);
        }