Example #1
0
        /// <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);
        }
Example #2
0
        public int Determinant()
        {
            if ((RowCount == 1) && (ColCount == 1))
            {
                return(data[0][0]);
            }

            var det = new Zp(Prime, 0);

            for (int i = 0; i < ColCount; i++)
            {
                int SubDet   = RemoveRowFromMatrix(0).RemoveColFromMatrix(i).Determinant();
                var SubDetAi = new Zp(Prime, SubDet * data[0][i]);
                if (i % 2 == 0)
                {
                    det.Add(SubDetAi);
                }
                else
                {
                    det.Sub(SubDetAi);
                }
            }
            return(det.Value);
        }