예제 #1
0
        public static Zp EvalutePolynomialAtPoint(IList <Zp> polynomial, Zp point)
        {
            long evaluation = 0;

            for (int i = 0; i < polynomial.Count; i++)
            {
                evaluation += polynomial[i].Value * NumTheoryUtils.ModPow(point.Value, i, point.Prime);
            }
            return(new Zp(point.Prime, evaluation));
        }
예제 #2
0
파일: ZpMatrix.cs 프로젝트: mahdiz/torbrix
        public static ZpMatrix GetPrimitiveVandermondeMatrix(int rowNum, int colNum, long prime)
        {
            int primitive = NumTheoryUtils.GetFieldMinimumPrimitive(prime);

            if (primitive == 0)
            {
                throw new ArgumentException("Cannot create a primitive Vandermonde matrix from a non-prime number. ");
            }

            var A = new ZpMatrix(rowNum, colNum, prime);

            for (int j = 0; j < colNum; j++)
            {
                A.data[0][j] = 1;
            }

            if (rowNum == 1)
            {
                return(A);
            }

            /*  This variable represents  primitive^j  for the j-th player*/
            long primitive_j = 1;

            for (int j = 0; j < colNum; j++)
            {
                A.data[1][j] = primitive_j;
                primitive_j  = Zp.Modulo(primitive_j * primitive, prime);
            }

            for (int j = 0; j < colNum; j++)
            {
                for (int i = 2; i < rowNum; i++)
                {
                    A.data[i][j] = Zp.Modulo(A.data[i - 1][j] * A.data[1][j], prime);
                }
            }

            return(A);
        }