コード例 #1
0
        public void SubtractTest()
        {
            var expected = new Integers(2);
            var actual   = x - y;

            Assert.AreEqual(expected, actual);
        }
コード例 #2
0
        public void MultiplyTest()
        {
            var expected = new Integers(8);
            var actual   = x * y;

            Assert.AreEqual(expected, actual);
        }
コード例 #3
0
        public void AddTest()
        {
            var expected = new Integers(6);
            var actual   = x + y;

            Assert.AreEqual(expected, actual);
        }
コード例 #4
0
        /**
         * Encodes an int array whose elements are between 0 and <code>q</code>,
         * to a byte array leaving no gaps between bits.<br>
         * <code>q</code> must be a power of 2.
         *
         * @param a the input array
         * @param q the modulus
         * @return the encoded array
         */
        public static byte[] EncodeModQ(int[] a, int q)
        {
            int bitsPerCoeff = 31 - Integers.NumberOfLeadingZeros(q);
            int numBits      = a.Length * bitsPerCoeff;
            int numBytes     = (numBits + 7) / 8;

            byte[] data      = new byte[numBytes];
            int    bitIndex  = 0;
            int    byteIndex = 0;

            for (int i = 0; i < a.Length; i++)
            {
                for (int j = 0; j < bitsPerCoeff; j++)
                {
                    int currentBit = (a[i] >> j) & 1;
                    data[byteIndex] = (byte)(data[byteIndex] | currentBit << bitIndex);
                    if (bitIndex == 7)
                    {
                        bitIndex = 0;
                        byteIndex++;
                    }
                    else
                    {
                        bitIndex++;
                    }
                }
            }
            return(data);
        }
コード例 #5
0
        public void Test_02_Integers()
        {
            Integers Obj = new Integers()
            {
                Int8   = -0x01,
                Int16  = -0x0102,
                Int32  = -0x01020304,
                Int64  = -0x0102030405060708,
                UInt8  = 0x01,
                UInt16 = 0x0102,
                UInt32 = 0x01020304,
                UInt64 = 0x0102030405060708,
            };

            byte[]   Bin  = this.endpoint.Serialize(Obj);
            Integers Obj2 = this.endpoint.Deserialize(Bin) as Integers;

            Assert.IsNotNull(Obj2);
            Assert.AreEqual(Obj.Int8, Obj2.Int8);
            Assert.AreEqual(Obj.Int16, Obj2.Int16);
            Assert.AreEqual(Obj.Int32, Obj2.Int32);
            Assert.AreEqual(Obj.Int64, Obj2.Int64);
            Assert.AreEqual(Obj.UInt8, Obj2.UInt8);
            Assert.AreEqual(Obj.UInt16, Obj2.UInt16);
            Assert.AreEqual(Obj.UInt32, Obj2.UInt32);
            Assert.AreEqual(Obj.UInt64, Obj2.UInt64);
        }
コード例 #6
0
        public virtual ECFieldElement HalfTrace()
        {
            int m = FieldSize;

            if ((m & 1) == 0)
            {
                throw new InvalidOperationException("Half-trace only defined for odd m");
            }

            //ECFieldElement ht = this;
            //for (int i = 1; i < m; i += 2)
            //{
            //    ht = ht.SquarePow(2).Add(this);
            //}

            int n  = (m + 1) >> 1;
            int k  = 31 - Integers.NumberOfLeadingZeros(n);
            int nk = 1;

            ECFieldElement ht = this;

            while (k > 0)
            {
                ht = ht.SquarePow(nk << 1).Add(ht);
                nk = n >> --k;
                if (0 != (nk & 1))
                {
                    ht = ht.SquarePow(2).Add(this);
                }
            }

            return(ht);
        }
コード例 #7
0
        public virtual int Trace()
        {
            int m = FieldSize;

            //ECFieldElement tr = this;
            //for (int i = 1; i < m; ++i)
            //{
            //    tr = tr.Square().Add(this);
            //}

            int k  = 31 - Integers.NumberOfLeadingZeros(m);
            int mk = 1;

            ECFieldElement tr = this;

            while (k > 0)
            {
                tr = tr.SquarePow(mk).Add(tr);
                mk = m >> --k;
                if (0 != (mk & 1))
                {
                    tr = tr.Square().Add(this);
                }
            }

            if (tr.IsZero)
            {
                return(0);
            }
            if (tr.IsOne)
            {
                return(1);
            }
            throw new InvalidOperationException("Internal error in trace calculation");
        }
コード例 #8
0
        public void RangeShouldntMatch()
        {
            var sut = Integers.From('u', 'w');

            Assert.IsFalse(sut.Contains('a'));
            Assert.IsFalse(sut.Contains('z'));
        }
コード例 #9
0
ファイル: Operand.cs プロジェクト: jakesactualface/StringMath
        public string ToNumericString()
        {
            var builder = new StringBuilder();

            Integers = Integers.TrimStart(Constants.ZeroCharacter);
            Decimals = Decimals.TrimEnd(Constants.ZeroCharacter);

            if (Digits.Length > 0)
            {
                if (IsNegative)
                {
                    builder.Append(Constants.NegationCharacter);
                }

                builder.Append(Integers);

                if (HasDecimal)
                {
                    builder.Append(Constants.DecimalCharacter);
                    builder.Append(Decimals);
                }
            }
            else
            {
                builder.Append(Constants.ZeroCharacter);
            }

            return(builder.ToString());
        }
コード例 #10
0
        public static void SimilarToLinq()
        {
            var numbers = Integers.GetIntegerList(10);

            var multedBy2        = numbers.Select(MultBy2);
            var numbersLessThan4 = numbers.Where(x => x < 4);
        }
コード例 #11
0
        public void CreateIntegersTest()
        {
            var integer = new Integers(x);

            Assert.NotNull(integer);
            Assert.AreEqual(4, integer.Int_num);
        }
コード例 #12
0
ファイル: NoekeonEngine.cs プロジェクト: todoasap/bc-csharp
        /**
         * initialise
         *
         * @param forEncryption whether or not we are for encryption.
         * @param params the parameters required to set up the cipher.
         * @exception ArgumentException if the params argument is
         * inappropriate.
         */
        public virtual void Init(bool forEncryption, ICipherParameters parameters)
        {
            if (!(parameters is KeyParameter))
            {
                throw new ArgumentException("Invalid parameters passed to Noekeon init - "
                                            + Platform.GetTypeName(parameters), "parameters");
            }

            this._forEncryption = forEncryption;
            this._initialised   = true;

            KeyParameter p = (KeyParameter)parameters;

            Pack.BE_To_UInt32(p.GetKey(), 0, k, 0, 4);

            if (!forEncryption)
            {
                // theta(k, new uint[]{ 0x00, 0x00, 0x00, 0x00 });
                {
                    uint a0 = k[0], a1 = k[1], a2 = k[2], a3 = k[3];

                    uint t = a0 ^ a2;
                    t  ^= Integers.RotateLeft(t, 8) ^ Integers.RotateLeft(t, 24);
                    a1 ^= t;
                    a3 ^= t;

                    t   = a1 ^ a3;
                    t  ^= Integers.RotateLeft(t, 8) ^ Integers.RotateLeft(t, 24);
                    a0 ^= t;
                    a2 ^= t;

                    k[0] = a0; k[1] = a1; k[2] = a2; k[3] = a3;
                }
            }
        }
コード例 #13
0
        public void NotRangeShouldntMatch()
        {
            var sut = Integers.From('u', 'w').Not();

            Assert.IsTrue(sut.Contains('a'));
            Assert.IsTrue(sut.Contains('z'));
        }
コード例 #14
0
 public void PopulationCount()
 {
     Assert.AreEqual(0, Integers.PopulationCount(0));
     Assert.AreEqual(1, Integers.PopulationCount(0x80));
     Assert.AreEqual(2, Integers.PopulationCount(0x40008000));
     Assert.AreEqual(3, Integers.PopulationCount(0x40208000));
 }
コード例 #15
0
        public void it_adds()
        {
            var expected = 4;
            var actual   = Integers.Add(2, 2);

            actual.Should().Be(expected);
        }
コード例 #16
0
ファイル: IO.cs プロジェクト: K1780/Labra07
        //methods
        public void InputNumbers()
        {
            //take inputs until non-number input given
            bool properInput = true;

            while (properInput)
            {
                double input;
                Console.WriteLine("Write whole number or decimal. Non-number input exits input.");
                if (double.TryParse(Console.ReadLine(), out input))
                {
                    //Check for whole number
                    if ((input % 1) == 0)
                    {
                        //add to int list
                        Integers.Add(Convert.ToInt32(input));
                    }
                    else
                    {
                        //add to double list
                        Doubles.Add(input);
                    }
                }
                else
                {
                    properInput = false;
                }
            }
        }
コード例 #17
0
 public Transition(Integers set, State target)
 {
     Set          = set;
     Target       = target;
     TransitionId = -1;
     SetId        = -1;
 }
コード例 #18
0
        public static int GetTime(string timeString)
        {
            Match m = null;

            timeString = timeString.Trim();
            // h:mm (\d\d?):(\d\d?)?
            // # m (\d+) ?m?
            // # h (\d+) ?h
            // #h #m (\d+) ?h? ?(\d+) ?m?
            m = Regex.Match(timeString, @"^(\d\d?):(\d\d?)?$");
            if (m.Success)
            {
                return(Integers.Parse(m.Groups[1].Value, 0) * 60 + Integers.Parse(m.Groups[2].Value, 0));
            }

            m = Regex.Match(timeString, @"^(\d+) ?m?$", RegexOptions.IgnoreCase);
            if (m.Success)
            {
                return(Integers.Parse(m.Groups[1].Value, 0));
            }

            m = Regex.Match(timeString, @"^(\d+) ?h$", RegexOptions.IgnoreCase);
            if (m.Success)
            {
                return(Integers.Parse(m.Groups[1].Value, 0) * 60);
            }

            m = Regex.Match(timeString, @"^(\d+) ?h? ?(\d+) ?m?$", RegexOptions.IgnoreCase);
            if (m.Success)
            {
                return(Integers.Parse(m.Groups[1].Value, 0) * 60 + Integers.Parse(m.Groups[2].Value, 0));
            }

            return(0);
        }
コード例 #19
0
 public static object Substring(object x, object y)
 {
     if (IsType.String(x) && IsType.AnyInt(y))
     {
         return(Strings.Substring((string)x, Integers.ToInteger(y)));
     }
     return(null);
 }
コード例 #20
0
        /**
         * Decodes data encoded with {@link #encodeModQ(int[], int)} back to an <code>int</code> array.<br>
         * <code>N</code> is the number of coefficients. <code>q</code> must be a power of <code>2</code>.<br>
         * Ignores any excess bytes.
         *
         * @param is an encoded ternary polynomial
         * @param N  number of coefficients
         * @param q
         * @return the decoded polynomial
         */
        public static int[] DecodeModQ(Stream stream, int N, int q)
        {
            int qBits = 31 - Integers.NumberOfLeadingZeros(q);
            int size  = (N * qBits + 7) / 8;

            byte[] arr = Util.ReadFullLength(stream, size);
            return(DecodeModQ(arr, N, q));
        }
コード例 #21
0
ファイル: Traversal.cs プロジェクト: zoomcoder/TickZoomPublic
 public Traversal() : base()
 {
     zigBars       = Integers(5);
     zigHighs      = Doubles(5);
     zagBars       = Integers(5);
     zagLows       = Doubles(5);
     Drawing.Color = Color.LightGreen;
 }
コード例 #22
0
        public void NotRangeShouldMatch()
        {
            var sut = Integers.From('u', 'w').Not();

            Assert.IsFalse(sut.Contains('u'));
            Assert.IsFalse(sut.Contains('v'));
            Assert.IsFalse(sut.Contains('w'));
        }
コード例 #23
0
        public void RangeShouldMatch()
        {
            var sut = Integers.From('u', 'w');

            Assert.IsTrue(sut.Contains('u'));
            Assert.IsTrue(sut.Contains('v'));
            Assert.IsTrue(sut.Contains('w'));
        }
コード例 #24
0
        public IActionResult Numbers()
        {
            Integers num1 = new Integers()
            {
                Digit = 1,
            };

            return(View(num1));
        }
コード例 #25
0
        public static void Print()
        {
            var integers1To10    = Integers.GetIntegerList(10);
            var evenIntegers     = GetEvenNumbers(integers1To10);
            var evenIntegersLinq = GetEvenIntegersLinq(integers1To10);

            Display.DisplayListOfIntegers(evenIntegers);
            Display.DisplayListOfIntegers(evenIntegersLinq);
        }
コード例 #26
0
 public PivotLowVs(int left, int right, int length)
 {
     pivotLows     = Doubles();
     pivotBars     = Integers();
     LSTREN        = left;
     RSTREN        = right;
     LENGTH        = Math.Max(length, left + right + 1);
     Drawing.Color = Color.Aqua;
 }
コード例 #27
0
 public PivotHighVs(int left, int right, int length)
 {
     pivotHighs         = Doubles();
     pivotBars          = Integers();
     this.leftStrength  = left;
     this.rightStrength = right;
     this.length        = Math.Max(length, left + right + 1);
     Drawing.Color      = Color.Orange;
 }
コード例 #28
0
        public static void Print()
        {
            var numbers = Integers.GetIntegerList(3);

            var foldResult     = Fold(AccFunction, 0, numbers);
            var foldBackResult = FoldBack(AccFunction, numbers, 0);

            Console.WriteLine("Fold Result: " + foldResult);
            Console.WriteLine("Fold Back Result: " + foldBackResult);
        }
コード例 #29
0
        public static object Substring(object x, object y, object z)
        {
            if (!IsType.String(x) || !AreTypes.AnyInt(y, z))
            {
                return(null);
            }
            var r = Strings.Substring((string)x, Integers.ToInteger(y), Integers.ToInteger(z));

            return(r);
        }
コード例 #30
0
 /// <summary>
 /// Clears all script storage.
 /// </summary>
 public static void Clear()
 {
     Pokemons.Clear();
     Strings.Clear();
     Integers.Clear();
     Booleans.Clear();
     Items.Clear();
     Singles.Clear();
     Doubles.Clear();
 }