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)); }
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); }