Ejemplo n.º 1
0
        /// <summary>
        /// Generates a blinding polynomial using an IndexGenerator
        /// </summary>
        ///
        /// <param name="Ig">An Index Generator</param>
        /// <param name="N">The number of coefficients</param>
        /// <param name="Dr">The number of ones / negative ones</param>
        ///
        /// <returns>A blinding polynomial</returns>
        public static SparseTernaryPolynomial GenerateBlindingPoly(IndexGenerator Ig, int N, int Dr)
        {
            int[] coeffs = new int[N];   // an IntegerPolynomial-style representation of the new polynomial

            int[] ones = new int[Dr];
            int   i    = 0;

            while (i < Dr)
            {
                int r = Ig.NextIndex();
                if (coeffs[r] == 0)
                {
                    ones[i]   = r;
                    coeffs[r] = 1;
                    i++;
                }
            }

            int[] negOnes = new int[Dr];
            i = 0;

            while (i < Dr)
            {
                int r = Ig.NextIndex();
                if (coeffs[r] == 0)
                {
                    negOnes[i] = r;
                    coeffs[r]  = -1;
                    i++;
                }
            }

            return(new SparseTernaryPolynomial(N, ones, negOnes));
        }
Ejemplo n.º 2
0
        private int[] initIndices()
        {
            int[] indices = new int[1000];
            for (int i = 0; i < indices.Length; i++)
            {
                indices[i] = _gen.NextIndex();
            }

            return(indices);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Generates an <c>int</c> array containing <c>dr</c> elements equal to <c>1</c>
        /// and <c>dr</c> elements equal to <c>-1</c> using an index generator.
        /// </summary>
        ///
        /// <param name="Ig">An Index Generator</param>
        /// <param name="N">The number of coefficients</param>
        /// <param name="Dr">The number of ones / negative ones</param>
        ///
        /// <returns>An array containing numbers between <c>-1</c> and <c>1</c></returns>
        private static int[] GenerateBlindingCoeffs(IndexGenerator Ig, int N, int Dr)
        {
            int[] r = new int[N];
            for (int coeff = -1; coeff <= 1; coeff += 2)
            {
                int t = 0;
                while (t < Dr)
                {
                    int i = Ig.NextIndex();
                    if (r[i] == 0)
                    {
                        r[i] = coeff;
                        t++;
                    }
                }
            }

            return(r);
        }