Esempio n. 1
0
        private Polynom MultiplyAlphaPolynoms(Polynom polynomBase, Polynom polynomMultiplier)
        {
            var resultPolynom = new Polynom();

            foreach (var polItemBase in polynomMultiplier.PolyItems)
            {
                foreach (var polItemMulti in polynomBase.PolyItems)
                {
                    var polItemRes = new PolynomItem();
                    polItemRes.Coefficient = ShrinkAlphaExp(polItemBase.Coefficient + polItemMulti.Coefficient);
                    polItemRes.Exponent    = (polItemBase.Exponent + polItemMulti.Exponent);
                    resultPolynom.PolyItems.Add(polItemRes);
                }
            }
            var exponentsToGlue = resultPolynom.PolyItems.GroupBy(x => x.Exponent).Where(x => x.Count() > 1).Select(x => x.First().Exponent);
            var gluedPolynoms   = new List <PolynomItem>();

            foreach (var exponent in exponentsToGlue)
            {
                var polynomFixed = new PolynomItem();
                polynomFixed.Exponent = exponent;
                var coefficient = 0;
                foreach (var polynomOld in resultPolynom.PolyItems.Where(x => x.Exponent == exponent))
                {
                    coefficient ^= GetIntValFromAlphaExp(polynomOld.Coefficient);
                }
                polynomFixed.Coefficient = GetAlphaExpFromIntVal(coefficient);
                gluedPolynoms.Add(polynomFixed);
            }
            resultPolynom.PolyItems.RemoveAll(x => exponentsToGlue.Contains(x.Exponent));
            resultPolynom.PolyItems.AddRange(gluedPolynoms);
            resultPolynom.PolyItems = resultPolynom.PolyItems.OrderByDescending(x => x.Exponent).ToList();
            return(resultPolynom);
        }
Esempio n. 2
0
        private Polynom XORPolynoms(Polynom messagePolynom, Polynom resPolynom)
        {
            var     resultPolynom = new Polynom();
            Polynom longPoly, shortPoly;

            if (messagePolynom.PolyItems.Count >= resPolynom.PolyItems.Count)
            {
                longPoly  = messagePolynom;
                shortPoly = resPolynom;
            }
            else
            {
                longPoly  = resPolynom;
                shortPoly = messagePolynom;
            }

            for (var i = 0; i < longPoly.PolyItems.Count; i++)
            {
                var polItemRes = new PolynomItem();
                polItemRes.Coefficient = longPoly.PolyItems[i].Coefficient ^ (shortPoly.PolyItems.Count > i ? shortPoly.PolyItems[i].Coefficient : 0);
                polItemRes.Exponent    = messagePolynom.PolyItems[0].Exponent - i;
                resultPolynom.PolyItems.Add(polItemRes);
            }
            resultPolynom.PolyItems.RemoveAt(0);
            return(resultPolynom);
        }
Esempio n. 3
0
        private Polynom MultiplyGeneratorPolynomByLeadterm(Polynom genPolynom, PolynomItem leadTerm, int lowerExponentBy)
        {
            var resultPolynom = new Polynom();

            foreach (var polItemBase in genPolynom.PolyItems)
            {
                var polItemRes = new PolynomItem();
                polItemRes.Coefficient = (polItemBase.Coefficient + leadTerm.Coefficient) % 255;
                polItemRes.Exponent    = polItemBase.Exponent - lowerExponentBy;
                resultPolynom.PolyItems.Add(polItemRes);
            }
            return(resultPolynom);
        }