Beispiel #1
0
        private void RandRangeTest(IRandom Rand, int Iterations = 1000)
        {
            byte[] data;
            int x;
            long y;
            int min, max;
            min = Rand.Next(33);
            max = Rand.Next(34, 111);

            for (int i = 0; i < Iterations; i++)
                data = Rand.GetBytes(i * 10);

            for (int i = 1; i < Iterations; i++)
            {
                x = Rand.Next(i * min, i * max);
                if (x > i * max)
                    throw new Exception(Rand.Name + ":Next returned a value above of the expected range.");
                if (x < i * min)
                    throw new Exception(Rand.Name + ":Next returned a value below of the expected range.");
                y = Rand.NextLong(i * min, i * max);
                if (y > i * max)
                    throw new Exception(Rand.Name + ":NextLong returned a value above of the expected range.");
                if (y < i * min)
                    throw new Exception(Rand.Name + ":NextLong returned a value below of the expected range.");
            }
        }
        /// <summary>
        /// Construct a random element over the field <c>gf2n</c>, using the specified source of randomness
        /// </summary>
        /// 
        /// <param name="Gf2n">The field</param>
        /// <param name="SecRnd">The source of randomness</param>
        public GF2nONBElement(GF2nONBField Gf2n, IRandom SecRnd)
        {
            mField = Gf2n;
            mDegree = mField.Degree;
            _mLength = Gf2n.GetONBLength();
            _mBit = Gf2n.GetONBBit();
            _mPol = new long[_mLength];

            if (_mLength > 1)
            {
                for (int j = 0; j < _mLength - 1; j++)
                    _mPol[j] = SecRnd.NextLong(); //ju next long?

                long last = SecRnd.Next();
                _mPol[_mLength - 1] = IntUtils.URShift(last, (MAXLONG - _mBit));
            }
            else
            {
                _mPol[0] = SecRnd.NextLong();
                _mPol[0] = IntUtils.URShift(_mPol[0], (MAXLONG - _mBit));
            }
        }