示例#1
0
        public static ExtensionPolynomial operator +(ExtensionPolynomial poly1, ExtensionPolynomial poly2)
        {
            if (poly1.Field.Characteristic != poly2.Field.Characteristic)
            {
                throw new Exception("Both polynomials should be defined in the same field.");
            }

            ExtensionFieldElement[] elts = poly1.Degree > poly2.Degree ? (ExtensionFieldElement[])poly1.Coefficients.Clone() : (ExtensionFieldElement[])poly2.Coefficients.Clone();

            ExtensionPolynomial p = new ExtensionPolynomial(elts);

            int len = Math.Min(poly1.Degree, poly2.Degree);

            for (int i = 0; i <= len; i++)
            {
                p._coefficients[i] = poly1._coefficients[i] + poly2._coefficients[i];
            }

            int plen = p._coefficients.Length;

            for (int i = 0; i < plen - 1; i++)
            {
                if (p._coefficients[plen - i - 1].Value.IsZero)
                {
                    Array.Resize(ref p._coefficients, p._coefficients.Length - 1);
                }
                else
                {
                    break;
                }
            }

            return(p);
        }
示例#2
0
        public ExtensionLFSR(ExtensionPolynomial feedbackPolynomial, ExtensionFieldElement[] initialState)
        {
            if (feedbackPolynomial.Field.Characteristic != initialState[0].Field.Characteristic)
                throw new Exception("Both values should be defined in the same field.");
            if ((initialState.Length - 1) < feedbackPolynomial.Degree)
                throw new ArgumentOutOfRangeException("Initial state size must be greater then feedback polynomial degree.");

            this.currentState = initialState;
            this._feedbackPolynomial = feedbackPolynomial;
        }
示例#3
0
        public ExtensionLFSR(ExtensionPolynomial feedbackPolynomial, ExtensionFieldElement[] initialState)
        {
            if (feedbackPolynomial.Field.Characteristic != initialState[0].Field.Characteristic)
            {
                throw new Exception("Both values should be defined in the same field.");
            }
            if ((initialState.Length - 1) < feedbackPolynomial.Degree)
            {
                throw new ArgumentOutOfRangeException("Initial state size must be greater then feedback polynomial degree.");
            }

            this.currentState        = initialState;
            this._feedbackPolynomial = feedbackPolynomial;
        }
示例#4
0
        public static ExtensionPolynomial operator *(ExtensionPolynomial poly1, ExtensionPolynomial poly2)
        {
            if (poly1.Field.Characteristic != poly2.Field.Characteristic)
            {
                throw new Exception("Both polynomials should be defined in the same field.");
            }

            ExtensionFieldElement[] elts = new ExtensionFieldElement[poly1.Degree + poly2.Degree + 1];

            for (int i = 0; i < elts.Length; i++)
            {
                ExtensionFieldElement e = ExtensionFieldElement.One(poly1.Field);
                elts[i] = e;
            }

            ExtensionPolynomial p = new ExtensionPolynomial(elts);

            for (int i = 0; i < poly1._coefficients.Length; i++)
            {
                for (int j = 0; j < poly2._coefficients.Length; j++)
                {
                    p._coefficients[i + j] += poly1._coefficients[i] * poly2._coefficients[j];
                }
            }

            int plen = p._coefficients.Length;

            for (int i = 0; i < plen - 1; i++)
            {
                if (p._coefficients[plen - i - 1].Value.IsZero)
                {
                    Array.Resize(ref p._coefficients, p._coefficients.Length - 1);
                }
                else
                {
                    break;
                }
            }

            return(p);
        }
示例#5
0
        private void btnExtPolyAdd_Click(object sender, EventArgs e)
        {
            ExtensionFieldElement[] eltlist1 = new ExtensionFieldElement[7];

            for (int i = 0; i < 7; i++)
                eltlist1[i] = ExtF.RandomElement;

            ExtensionPolynomial extp1 = new ExtensionPolynomial(eltlist1);

            ExtensionFieldElement[] eltlist2 = new ExtensionFieldElement[4];

            for (int i = 0; i < 4; i++)
                eltlist2[i] = ExtF.RandomElement;

            ExtensionPolynomial extp2 = new ExtensionPolynomial(eltlist2);

            ExtensionPolynomial result = extp1 + extp2;

            txtInfo.Clear();
            txtInfo.AppendText("Random Extension Polynomial 1\r\n" + extp1.ToString() + "\r\n");
            txtInfo.AppendText("\r\nRandom Extension Polynomial 2\r\n" + extp2.ToString() + "\r\n");
            txtInfo.AppendText("\r\nPolynomial 1 + Polynomial 2\r\n" + result.ToString() + "\r\n");
        }
示例#6
0
        private void btnLFSR_Click(object sender, EventArgs e)
        {
            if (lfsr == null)
            {
                ExtensionFieldElement[] eltlist1 = new ExtensionFieldElement[4];

                for (int i = 0; i < 4; i++)
                    eltlist1[i] = ExtF.RandomElement;

                ExtensionPolynomial extp1 = new ExtensionPolynomial(eltlist1);

                ExtensionFieldElement[] eltlist2 = new ExtensionFieldElement[4];

                for (int i = 0; i < 4; i++)
                    eltlist2[i] = ExtF.RandomElement;

                lfsr = new ExtensionLFSR(extp1, eltlist2);

                txtInfo.Clear();
                txtInfo.AppendText("LFSR has been created.\r\n");
                txtInfo.AppendText("Feedback Polynomial:\r\n" + lfsr.FeedbackPolynomial.ToString() + "\r\n");
                txtInfo.AppendText("Initial State:\r\n");
                for (int i = 0; i < lfsr.currentState.Length; i++)
                    txtInfo.AppendText("c_" + i + " = " + lfsr.currentState[i].ToString() + "\r\n");

                btnLFSR.Text = "Clock the LFSR";

                return;
            }

            // clock time

            lfsr.Clock();
            txtInfo.AppendText("\r\nOutput " + s++ + " : " + lfsr.StreamOutput + "\r\n");
            txtInfo.AppendText("Current State:\r\n");
            for (int i = 0; i < lfsr.currentState.Length; i++)
                txtInfo.AppendText("c_" + i + " = " + lfsr.currentState[i].ToString() + "\r\n");
        }
        public static ExtensionPolynomial operator +(ExtensionPolynomial poly1, ExtensionPolynomial poly2)
        {
            if (poly1.Field.Characteristic != poly2.Field.Characteristic)
            {
                throw new Exception("Both polynomials should be defined in the same field.");
            }

            ExtensionFieldElement[] elts = poly1.Degree > poly2.Degree ? (ExtensionFieldElement[])poly1.Coefficients.Clone() : (ExtensionFieldElement[])poly2.Coefficients.Clone();

            ExtensionPolynomial p = new ExtensionPolynomial(elts);

            int len = Math.Min(poly1.Degree, poly2.Degree);

            for (int i = 0; i <= len; i++)
                p._coefficients[i] = poly1._coefficients[i] + poly2._coefficients[i];

            int plen = p._coefficients.Length;
            for (int i = 0; i < plen - 1; i++)
            {
                if (p._coefficients[plen - i - 1].Value.IsZero)
                    Array.Resize(ref p._coefficients, p._coefficients.Length - 1);
                else
                    break;
            }

            return p;
        }
        public static ExtensionPolynomial operator *(ExtensionPolynomial poly1, ExtensionPolynomial poly2)
        {
            if (poly1.Field.Characteristic != poly2.Field.Characteristic)
            {
                throw new Exception("Both polynomials should be defined in the same field.");
            }

            ExtensionFieldElement[] elts = new ExtensionFieldElement[poly1.Degree + poly2.Degree + 1];

            for (int i = 0; i < elts.Length; i++)
            {
                ExtensionFieldElement e = ExtensionFieldElement.One(poly1.Field);
                elts[i] = e;
            }

            ExtensionPolynomial p = new ExtensionPolynomial(elts);

            for (int i = 0; i < poly1._coefficients.Length; i++)
            {
                for (int j = 0; j < poly2._coefficients.Length; j++)
                    p._coefficients[i + j] += poly1._coefficients[i] * poly2._coefficients[j];
            }

            int plen = p._coefficients.Length;
            for (int i = 0; i < plen - 1; i++)
            {
                if (p._coefficients[plen - i - 1].Value.IsZero)
                    Array.Resize(ref p._coefficients, p._coefficients.Length - 1);
                else
                    break;
            }

            return p;
        }