Example #1
0
File: ECC.cs Project: gxk/dm6467
        public BinaryGaloisFieldElement Divide(BinaryGaloisFieldElement x, BinaryGaloisFieldElement y)
        {
            Int32 result = 0x0;
            Int32 ordX, ordY;

            ordX = BinaryGaloisFieldElement.Order(x);
            ordY = BinaryGaloisFieldElement.Order(y);

            // if x is already of lower order than y, abort
            if (ordX < ordY)
            {
                return((BinaryGaloisFieldElement)0);
            }

            // Perform long division
            while (ordX >= ordY)
            {
                if ((x.Value & (0x1 << ordX)) != 0)
                {
                    result = 0x1 << (ordX - ordY);
                    x     -= (y << (ordX - ordY));
                }
                ordX--;
            }

            return((BinaryGaloisFieldElement)result);
        }
Example #2
0
File: ECC.cs Project: gxk/dm6467
        // *************************************************
        // *             Public Class Methods              *
        // *************************************************

        public static BinaryGaloisFieldElement[] createGeneratorPolynomial(BinaryGaloisField gf, Int32 maxCorrectibleErrorCnt)
        {
            // Generator polynomial, g(x), is of order 2s, so has 2s+1 coefficients
            BinaryGaloisFieldElement[] g = new BinaryGaloisFieldElement[2 * maxCorrectibleErrorCnt + 1];

            // Make g(x) = 1
            g[0] = 1;
            for (int i = 1; i <= (2 * maxCorrectibleErrorCnt); i++)
            {
                // Always make coefficient of x^i term equal to 1
                g[i] = 1;

                // Below multiply (g(x) = g[0] + g[1]*x + ... + g[i]*(x^i)) by (x - alpha^i)
                for (int j = (i - 1); j > 0; j--)
                {
                    if (g[j] != 0)
                    {
                        g[j] = g[j - 1] - gf.Multiply(gf.AlphaFromIndex(i), g[j]);
                    }
                    else
                    {
                        g[j] = g[j - 1];
                    }
                }
                // Coefficient of x^0 term is alpha^(1+2+...+i)
                g[0] = gf.AlphaFromIndex(((i * (i + 1)) / 2));
            }
            return(g);
        }
Example #3
0
File: ECC.cs Project: gxk/dm6467
        public BinaryGaloisFieldElement Modulo(BinaryGaloisFieldElement x, BinaryGaloisFieldElement y)
        {
            Int32 ordX, ordY;

            ordX = BinaryGaloisFieldElement.Order(x);
            ordY = BinaryGaloisFieldElement.Order(y);

            // if x is already of lower order than y, abort
            if (BinaryGaloisFieldElement.Order(x) < BinaryGaloisFieldElement.Order(y))
            {
                return(x);
            }

            // Keep subtracting mod value until we are in a valid range
            // Perform long division
            while (ordX >= ordY)
            {
                if ((x.Value & (0x1 << ordX)) != 0)
                {
                    x -= (y << (ordX - ordY));
                }
                ordX--;
            }
            return(x);
        }
Example #4
0
File: ECC.cs Project: gxk/dm6467
 // Array for access to alpha exponents
 public Int32 IndexFromAlpha(BinaryGaloisFieldElement alpha)
 {
     if ((alpha.Value == 0) || (alpha.Value >= Length))
     {
         throw new ArgumentException("IndexFromAlpha: Out of range", "alpha");
     }
     return(this.index[alpha.Value]);
 }
Example #5
0
File: ECC.cs Project: gxk/dm6467
        public override Boolean Equals(object obj)
        {
            if (!(obj is BinaryGaloisFieldElement))
            {
                return(false);
            }
            BinaryGaloisFieldElement x = (BinaryGaloisFieldElement)obj;

            return((value == x.value));
        }
Example #6
0
File: ECC.cs Project: gxk/dm6467
        // *************************************************
        // *             Public constructors               *
        // *************************************************


        // *************************************************
        // *                Public methods                 *
        // *************************************************

        public static Int32 Order(BinaryGaloisFieldElement x)
        {
            UInt32 Mask  = 0x80000000;
            Int32  order = 31;

            while (((x.Value & Mask) == 0x0) && (order > 0))
            {
                Mask >>= 1;
                order--;
            }

            return(order);
        }
Example #7
0
File: ECC.cs Project: gxk/dm6467
        // *************************************************
        // *             Public constructors               *
        // *************************************************

        // Public constructor for Binary Galois Field class
        // r is the exponent to which 2 is raised
        public BinaryGaloisField(Int32 r)
        {
            // Set the irreducible polynomial for GF(2^r)
            poly = (BinaryGaloisFieldElement)primPoly[r];

            // Set the primitive element alpha
            primElement = (BinaryGaloisFieldElement)2;

            // Set the field length
            length = (1 << r);

            // Generate the field elements
            GenerateFieldElements();

            // Generate the alpha exponents
            GenerateAlphaExponents();
        }
Example #8
0
File: ECC.cs Project: gxk/dm6467
        // Assume field Elements are polynomials of max order 15
        public BinaryGaloisFieldElement Multiply(BinaryGaloisFieldElement x, BinaryGaloisFieldElement y)
        {
            BinaryGaloisFieldElement tempVal = (BinaryGaloisFieldElement)0;
            UInt32 mask = 0x1;

            // Perform multiplication
            for (int i = 0; i < 16; i++)
            {
                if ((x.Value & mask) != 0)
                {
                    tempVal += (y << i);
                }
                mask <<= 1;
            }

            // Now take modulo poly
            return(Modulo(tempVal, poly));
        }
Example #9
0
File: ECC.cs Project: gxk/dm6467
        // *************************************************
        // *           Public Instance Methods             *
        // *************************************************

        public Int32[] GenerateParity(Int32[] messageData)
        {
            Int32[] retArray = new Int32[2 * s];
            BinaryGaloisFieldElement[] data = new BinaryGaloisFieldElement[N];

            if (messageData.Length != k)
            {
                throw new ArgumentException("Wrong size.", "messageData");
            }

            // Parity is defined parityPoly(x) = x^2s * messagePoly(x) (mod generatorPoly(x))
            // Convert input message data to array of BinaryGaloisFieldElement (implicit cast)
            // Create x^2s * messagePoly(x) by shifting data up by 2s positions
            for (int i = 0; i < k; i++)
            {
                data[i + (2 * s)] = messageData[i];
            }

            // Now do long division using generatorPoly, remainder is parity data
            // Use synthetic division since generatorPoly is monic
            for (int i = N - 1; i >= (2 * s); i--)
            {
                if (data[i] != 0)
                {
                    for (int j = 1; j <= (2 * s); j++)
                    {
                        data[i - j] = data[i - j] - galoisField.Multiply(data[i], generatorPoly[2 * s - j]);
                    }
                    // Set to zero
                    data[i] = 0;
                }
            }

            // Copy 2*s pieces of data to the parity symbols array
            for (int i = 0; i < (2 * s); i++)
            {
                retArray[i] = (Int32)data[i];
            }

            // Return parity symbols
            return(retArray);
        }
Example #10
0
      // *************************************************
      // *           Public Instance Methods             *
      // *************************************************      
      
      public Int32[] GenerateParity(Int32[] messageData)
      {
        Int32[] retArray = new Int32[2*s];
        BinaryGaloisFieldElement[] data = new BinaryGaloisFieldElement[N];
      
        if (messageData.Length != k)
          throw new ArgumentException("Wrong size.","messageData");

        // Parity is defined parityPoly(x) = x^2s * messagePoly(x) (mod generatorPoly(x))
        // Convert input message data to array of BinaryGaloisFieldElement (implicit cast)
        // Create x^2s * messagePoly(x) by shifting data up by 2s positions
        for (int i=0; i<k; i++)
        {
          data[i+(2*s)] = messageData[i];
        }
        
        // Now do long division using generatorPoly, remainder is parity data
        // Use synthetic division since generatorPoly is monic
        for(int i = N - 1; i >=(2*s); i--)
        {
          if (data[i] != 0)
          {
            for (int j = 1; j <= (2*s); j++)
            {
              data[i - j] = data[i - j] - galoisField.Multiply(data[i],generatorPoly[2*s - j]);
            }
            // Set to zero
            data[i] = 0;
          }
        }
        
        // Copy 2*s pieces of data to the parity symbols array
        for (int i=0; i<(2*s); i++)
        {
          retArray[i] = (Int32) data[i];
        }
        
        // Return parity symbols
        return retArray;
      }
Example #11
0
 // *************************************************
 // *             Public constructors               *
 // *************************************************
 
 // Public constructor for Binary Galois Field class
 // r is the exponent to which 2 is raised
 public BinaryGaloisField(Int32 r)
 {
   // Set the irreducible polynomial for GF(2^r)
   poly = (BinaryGaloisFieldElement) primPoly[r];
   
   // Set the primitive element alpha
   primElement = (BinaryGaloisFieldElement) 2;
   
   // Set the field length
   length = (1 << r);
   
   // Generate the field elements
   GenerateFieldElements();
   
   // Generate the alpha exponents
   GenerateAlphaExponents();
 }
Example #12
0
      // *************************************************
      // *             Public constructors               *
      // *************************************************      

      
      // *************************************************
      // *                Public methods                 *
      // *************************************************
      
      public static Int32 Order(BinaryGaloisFieldElement x)
      {
        UInt32 Mask = 0x80000000;
        Int32 order = 31;
        
        while (((x.Value & Mask) == 0x0) && (order > 0))
        {
          Mask >>= 1;
          order--;
        }
        
        return order;
      }
Example #13
0
 // Array for access to alpha exponents
 public Int32 IndexFromAlpha(BinaryGaloisFieldElement alpha)
 {
   if ( (alpha.Value == 0) || (alpha.Value >= Length) )
     throw new ArgumentException("IndexFromAlpha: Out of range", "alpha");
   return this.index[alpha.Value];
 }
Example #14
0
 // Assume field Elements are polynomials of max order 15
 public BinaryGaloisFieldElement Multiply(BinaryGaloisFieldElement x, BinaryGaloisFieldElement y)
 {
   BinaryGaloisFieldElement tempVal = (BinaryGaloisFieldElement) 0;
   UInt32 mask = 0x1;
   
   // Perform multiplication
   for (int i = 0; i<16; i++)
   {
     if ((x.Value & mask) != 0)
     {
       tempVal += (y << i);
     }
     mask <<= 1;
   }
   
   // Now take modulo poly
   return Modulo(tempVal,poly);
 }
Example #15
0
      public BinaryGaloisFieldElement Divide(BinaryGaloisFieldElement x, BinaryGaloisFieldElement y)
      {
        Int32 result = 0x0;
        Int32 ordX, ordY;
        
        ordX = BinaryGaloisFieldElement.Order(x);
        ordY = BinaryGaloisFieldElement.Order(y);
        
        // if x is already of lower order than y, abort
        if ( ordX < ordY)
          return ((BinaryGaloisFieldElement) 0);
        
        // Perform long division
        while (ordX >= ordY)
        {
          if ( (x.Value & (0x1 << ordX)) != 0)
          {
            result = 0x1 << (ordX - ordY);
            x -= (y << (ordX - ordY));
          }
          ordX--;
        }

        return ((BinaryGaloisFieldElement)result);
      }
Example #16
0
 public BinaryGaloisFieldElement Modulo(BinaryGaloisFieldElement x, BinaryGaloisFieldElement y)
 {
   Int32 ordX, ordY;
   
   ordX = BinaryGaloisFieldElement.Order(x);
   ordY = BinaryGaloisFieldElement.Order(y);
 
   // if x is already of lower order than y, abort
   if (BinaryGaloisFieldElement.Order(x) < BinaryGaloisFieldElement.Order(y))
     return x;
 
   // Keep subtracting mod value until we are in a valid range
   // Perform long division
   while (ordX >= ordY)
   {
     if ( (x.Value & (0x1 << ordX)) != 0)
     {
       x -= (y << (ordX - ordY));
     }
     ordX--;
   }
   return x;
 }
Example #17
0
 // *************************************************
 // *             Public Class Methods              *
 // *************************************************
 
 public static BinaryGaloisFieldElement[] createGeneratorPolynomial(BinaryGaloisField gf, Int32 maxCorrectibleErrorCnt)
 {
   // Generator polynomial, g(x), is of order 2s, so has 2s+1 coefficients
   BinaryGaloisFieldElement[] g = new BinaryGaloisFieldElement[2*maxCorrectibleErrorCnt + 1];
   
   // Make g(x) = 1
   g[0] = 1;
   for (int i = 1; i<=(2*maxCorrectibleErrorCnt); i++)
   {
     // Always make coefficient of x^i term equal to 1
     g[i] = 1;
     
     // Below multiply (g(x) = g[0] + g[1]*x + ... + g[i]*(x^i)) by (x - alpha^i)
     for (int j=(i-1); j > 0; j--)
     {
       if (g[j] != 0)
         g[j] = g[j - 1] - gf.Multiply(gf.AlphaFromIndex(i),g[j]);
       else
         g[j] = g[j - 1];
     }
     // Coefficient of x^0 term is alpha^(1+2+...+i)
     g[0] = gf.AlphaFromIndex( ((i*(i+1))/2) );
   }
   return g;
 }