public BBSGenerator2(uint[] parityBytes, uint p, uint q, uint initSeed)
        {
            _parityBytes = parityBytes;
            _p = p;
            _q = q;
            _xVal = initSeed;

            //Check for even or odd seed
            _mode = (initSeed % 2 == 0) ? ParityMode.Even : ParityMode.Odd;
        }
Пример #2
0
        public BBSGenerator2(uint[] parityBytes, uint p, uint q, uint initSeed)
        {
            _parityBytes = parityBytes;
            _p           = p;
            _q           = q;
            _xVal        = initSeed;

            //Check for even or odd seed
            _mode = (initSeed % 2 == 0) ? ParityMode.Even : ParityMode.Odd;
        }
        public BBSGenerator(uint[] parityBytes, uint[] primes, uint initSeed)
        {
            _parityBytes = parityBytes;
            _primes = primes;
            _pIndex = 0;
            _qIndex = 1;
            _xVal = initSeed;

            //Check for even or odd seed
            _mode = (initSeed % 2 == 0) ? ParityMode.Even : ParityMode.Odd;
        }
Пример #4
0
        public BBSGenerator(uint[] parityBytes, uint[] primes, uint initSeed)
        {
            _parityBytes = parityBytes;
            _primes      = primes;
            _pIndex      = 0;
            _qIndex      = 1;
            _xVal        = initSeed;

            //Check for even or odd seed
            _mode = (initSeed % 2 == 0) ? ParityMode.Even : ParityMode.Odd;
        }
        /// <summary>
        /// Calculates the parity bit of n.  Setting isEven to true calculates even parity.  Setting odd to true calculates odd.
        /// </summary>
        /// <param name="n">The unsigned integer to calculate for.</param>
        /// <param name="isEvenParity">True if looking for even parity, otherwise false.</param>
        /// <returns>True if parity is 1, or false if 0.</returns>
        private bool CalculateParityBit(uint n, uint[] parityBits, ParityMode mode)
        {
            int bitCounter = 0;
            for (int i = parityBits.Length - 1; i >= 0; i--)
            {
                if (n >= parityBits[i])
                {
                    n -= parityBits[i];
                    bitCounter++;
                }
            }

            //If even and looking for even then we want to return 0, else 1
            //If even and looking for odd then we want to return 1, else 0
            return ((bitCounter % 2) == 0) ^ (mode.Equals(ParityMode.Even));
        }
Пример #6
0
        /// <summary>
        /// Calculates the parity bit of n.  Setting isEven to true calculates even parity.  Setting odd to true calculates odd.
        /// </summary>
        /// <param name="n">The unsigned integer to calculate for.</param>
        /// <param name="isEvenParity">True if looking for even parity, otherwise false.</param>
        /// <returns>True if parity is 1, or false if 0.</returns>
        private bool CalculateParityBit(uint n, uint[] parityBits, ParityMode mode)
        {
            int bitCounter = 0;

            for (int i = parityBits.Length - 1; i >= 0; i--)
            {
                if (n >= parityBits[i])
                {
                    n -= parityBits[i];
                    bitCounter++;
                }
            }

            //If even and looking for even then we want to return 0, else 1
            //If even and looking for odd then we want to return 1, else 0
            return(((bitCounter % 2) == 0) ^ (mode.Equals(ParityMode.Even)));
        }