private void Trace(object sender, RoutedEventArgs e)
        {
            BinaryFieldElement firstOperand = new BinaryFieldElement(TXBFirstOperand.Text.ToString(), 443);
            BinaryFieldElement result = (firstOperand).Trace();

            TXBResult.Text = result.ToString();
        }
 private static void RemainderFromGenerator(BinaryFieldElement firstOperand, BinaryFieldElement result, BinaryFieldElement temporaryResult)
 {
     for (int coordinateIndex = temporaryResult.content.Count - 1; coordinateIndex >= 0; coordinateIndex--)
     {
         if (coordinateIndex < fieldGenerator.content.Count - 1)
         {
             break;
         }
         if (!temporaryResult.content[coordinateIndex])
         {
             continue;
         }
         for (int divistionCoordinateIndex = 0; divistionCoordinateIndex < fieldGenerator.content.Count; divistionCoordinateIndex++)
         {
             temporaryResult.content[coordinateIndex - divistionCoordinateIndex] ^=
                 fieldGenerator.content[fieldGenerator.content.Count - 1 - divistionCoordinateIndex];
         }
     }
     for (int coordinateIndex = 0; coordinateIndex < firstOperand.content.Count; coordinateIndex++)
     {
         if (temporaryResult.content[coordinateIndex])
         {
             result.SetBit(coordinateIndex);
         }
     }
 }
        private void Reverse(object sender, RoutedEventArgs e)
        {
            BinaryFieldElement firstOperand = new BinaryFieldElement(TXBFirstOperand.Text.ToString(), 443);

            BinaryFieldElement result = BinaryFieldElement.Power(firstOperand, (int)Math.Pow(2, 443) - 2);

            TXBResult.Text = result.ToString();
        }
        public static BinaryFieldElement operator *(BinaryFieldElement firstOperand, BinaryFieldElement secondOperand)
        {
            BinaryFieldElement result = new BinaryFieldElement("0", firstOperand.content.Count);

            BinaryFieldElement temporaryResult = new BinaryFieldElement("0", firstOperand.content.Count * 2 + 1);
            Sum(firstOperand, secondOperand, temporaryResult);
            RemainderFromGenerator(firstOperand, result, temporaryResult);
            return result;
        }
        private void Power(object sender, RoutedEventArgs e)
        {
            BinaryFieldElement firstOperand = new BinaryFieldElement(TXBFirstOperand.Text.ToString(), 443);
            int degree = int.Parse(TXBDegreeOperand.Text);

            BinaryFieldElement result = BinaryFieldElement.Power(firstOperand, degree);

            TXBResult.Text = result.ToString();
        }
        private void Multiplication(object sender, RoutedEventArgs e)
        {
            BinaryFieldElement firstOperand = new BinaryFieldElement(TXBFirstOperand.Text.ToString(), 443);
            BinaryFieldElement secondOperand = new BinaryFieldElement(TXBSecondOperand.Text.ToString(), 443);

            BinaryFieldElement result = firstOperand * secondOperand;

            TXBResult.Text = result.ToString();
        }
 public static BinaryFieldElement operator +(BinaryFieldElement firstOperand, BinaryFieldElement secondOperand)
 {
     BinaryFieldElement result = new BinaryFieldElement();
     for (int coordinateIndex = 0; coordinateIndex < result.content.Count; coordinateIndex++)
     {
         result.content[coordinateIndex] = firstOperand.content[coordinateIndex] ^
                                           secondOperand.content[coordinateIndex];
     }
     return result;
 }
 public BinaryFieldElement(BinaryFieldElement input)
 {
     content = new BitArray(input.content.Count);
     int coordinateIndex = 0;
     foreach (bool b in input.content)
     {
         content[coordinateIndex] = b;
         coordinateIndex++;
     }
 }
        public static BinaryFieldElement operator *(BinaryFieldElement firstOperand, BinaryFieldElement secondOperand)
        {
            BinaryFieldElement result = new BinaryFieldElement("0", firstOperand.content.Count);

            BinaryFieldElement temporaryResult = new BinaryFieldElement("0", firstOperand.content.Count * 2 + 1);

            Sum(firstOperand, secondOperand, temporaryResult);
            RemainderFromGenerator(firstOperand, result, temporaryResult);
            return(result);
        }
        public static BinaryFieldElement operator +(BinaryFieldElement firstOperand, BinaryFieldElement secondOperand)
        {
            BinaryFieldElement result = new BinaryFieldElement();

            for (int coordinateIndex = 0; coordinateIndex < result.content.Count; coordinateIndex++)
            {
                result.content[coordinateIndex] = firstOperand.content[coordinateIndex] ^
                                                  secondOperand.content[coordinateIndex];
            }
            return(result);
        }
        public BinaryFieldElement(BinaryFieldElement input)
        {
            content = new BitArray(input.content.Count);
            int coordinateIndex = 0;

            foreach (bool b in input.content)
            {
                content[coordinateIndex] = b;
                coordinateIndex++;
            }
        }
 private void CreateGenerator()
 {
     if (fieldGenerator != null)
     {
         return;
     }
     fieldGenerator = new BinaryFieldElement("0", 444);
     fieldGenerator.SetBit(443);
     fieldGenerator.SetBit(28);
     fieldGenerator.SetBit(3);
     fieldGenerator.SetBit(1);
     fieldGenerator.SetBit(0);
 }
        public static BinaryFieldElement Power(BinaryFieldElement input, int degree)
        {
            BinaryFieldElement result = new BinaryFieldElement(input);

            for (int degreeIndex = 0; degreeIndex < degree / 2; degreeIndex++)
            {
                result = Square(result);
            }
            if (degree % 2 == 1)
            {
                result = result * input;
            }
            return(result);
        }
 private static void Sum(BinaryFieldElement firstOperand, BinaryFieldElement secondOperand, BinaryFieldElement temporaryResult)
 {
     for (int coordinateIndex = 0; coordinateIndex < secondOperand.content.Count; coordinateIndex++)
     {
         if (secondOperand.content[coordinateIndex])
         {
             for (int firstCoordinateIndex = 0; firstCoordinateIndex < firstOperand.content.Count; firstCoordinateIndex++)
             {
                 temporaryResult.content[coordinateIndex + firstCoordinateIndex] ^=
                     firstOperand.content[firstCoordinateIndex];
             }
         }
     }
 }
        public static BinaryFieldElement Square(BinaryFieldElement input)
        {
            BinaryFieldElement result    = new BinaryFieldElement("0", input.content.Count);
            BinaryFieldElement tmpResult = new BinaryFieldElement("0", input.content.Count * 2 + 1);

            for (int positionIndex = 0; positionIndex < tmpResult.content.Count; positionIndex++)
            {
                if (positionIndex % 2 == 0)
                {
                    continue;
                }
                tmpResult.content[positionIndex] = input.content[positionIndex / 2];
            }
            RemainderFromGenerator(input, result, tmpResult);
            return(result);
        }
        public BinaryFieldElement Trace()
        {
            bool trace = false;

            BinaryFieldElement result = new BinaryFieldElement("0", content.Count);

            for (int degreeIndex = 0; degreeIndex < content.Count; degreeIndex++)
            {
                BinaryFieldElement tmpResult = new BinaryFieldElement("0", 443);
                for (int squareIndex = 0; squareIndex < degreeIndex; squareIndex++)
                {
                    tmpResult = Square(tmpResult);
                }
                result += tmpResult;
            }
            trace = result.content[0];
            return(result);
        }
 public static BinaryFieldElement Square(BinaryFieldElement input)
 {
     BinaryFieldElement result = new BinaryFieldElement("0", input.content.Count);
     BinaryFieldElement tmpResult = new BinaryFieldElement("0", input.content.Count * 2 + 1);
     for (int positionIndex = 0; positionIndex < tmpResult.content.Count; positionIndex++)
     {
         if (positionIndex % 2 == 0) continue;
         tmpResult.content[positionIndex] = input.content[positionIndex / 2];
     }
     RemainderFromGenerator(input, result, tmpResult);
     return result;
 }
 private static void RemainderFromGenerator(BinaryFieldElement firstOperand, BinaryFieldElement result, BinaryFieldElement temporaryResult)
 {
     for (int coordinateIndex = temporaryResult.content.Count - 1; coordinateIndex >= 0; coordinateIndex--)
     {
         if (coordinateIndex < fieldGenerator.content.Count - 1) break;
         if (!temporaryResult.content[coordinateIndex]) continue;
         for (int divistionCoordinateIndex = 0; divistionCoordinateIndex < fieldGenerator.content.Count; divistionCoordinateIndex++)
         {
             temporaryResult.content[coordinateIndex - divistionCoordinateIndex] ^=
                 fieldGenerator.content[fieldGenerator.content.Count - 1 - divistionCoordinateIndex];
         }
     }
     for (int coordinateIndex = 0; coordinateIndex < firstOperand.content.Count; coordinateIndex++)
     {
         if (temporaryResult.content[coordinateIndex])
         {
             result.SetBit(coordinateIndex);
         }
     }
 }
 private static void Sum(BinaryFieldElement firstOperand, BinaryFieldElement secondOperand, BinaryFieldElement temporaryResult)
 {
     for (int coordinateIndex = 0; coordinateIndex < secondOperand.content.Count; coordinateIndex++)
     {
         if (secondOperand.content[coordinateIndex])
         {
             for (int firstCoordinateIndex = 0; firstCoordinateIndex < firstOperand.content.Count; firstCoordinateIndex++)
             {
                 temporaryResult.content[coordinateIndex + firstCoordinateIndex] ^=
                     firstOperand.content[firstCoordinateIndex];
             }
         }
     }
 }
        public BinaryFieldElement Trace()
        {
            bool trace = false;

            BinaryFieldElement result = new BinaryFieldElement("0", content.Count);
            for (int degreeIndex = 0; degreeIndex < content.Count; degreeIndex++)
            {
                BinaryFieldElement tmpResult = new BinaryFieldElement("0", 443);
                for (int squareIndex = 0; squareIndex < degreeIndex; squareIndex++)
                {
                    tmpResult = Square(tmpResult);
                }
                result += tmpResult;
            }
            trace = result.content[0];
            return result;
        }
 private void CreateGenerator()
 {
     if (fieldGenerator != null) return;
     fieldGenerator = new BinaryFieldElement("0", 444);
     fieldGenerator.SetBit(443);
     fieldGenerator.SetBit(28);
     fieldGenerator.SetBit(3);
     fieldGenerator.SetBit(1);
     fieldGenerator.SetBit(0);
 }
 public static BinaryFieldElement Power(BinaryFieldElement input, int degree)
 {
     BinaryFieldElement result = new BinaryFieldElement(input);
     for (int degreeIndex = 0; degreeIndex < degree / 2; degreeIndex++)
     {
         result = Square(result);
     }
     if (degree % 2 == 1)
     {
         result = result * input;
     }
     return result;
 }