public static ModPow ( int powerBase, int exp, int prime ) : int | ||
powerBase | int | |
exp | int | |
prime | int | |
Результат | int |
public static Zp EvalutePolynomialAtPoint(IList <Zp> polynomial, Zp point) { int 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)); }
/// <param name="SamplePoint"> - the desired sampling point. </param> /// <returns> the result of the polynom when replacing variable ("x") with the sampling point </returns> public virtual Zp Sample(Zp SamplePoint) { if (Coefficients.Count == 0) { return(null); } /* The initialized sum is 0 */ var Sum = new Zp(CoefficinesFieldSize, 0); for (int i = 0; i < Coefficients.Count; i++) { /* replace each "Ai*x^i" with "Ai*SamplePoint^i" */ var Xi = new Zp(CoefficinesFieldSize, NumTheoryUtils.ModPow(SamplePoint.Value, i, CoefficinesFieldSize)); var Ai = new Zp(CoefficinesFieldSize, Coefficients[i].Value); var AiXi = Xi.Mul(Ai); /* Sum all these values(A0+A1X^1+...AnX^n) */ Sum = Sum.Add(AiXi); } return(Sum); }