Пример #1
0
        static GF8()
        {
            GF8.empty = new GF8(0);
            empty.i = -1;

            #region Initialize Reference Tables
            UInt32 primitive_polynomial = 285;

            UInt32 mask = 1;
            gf_exp[8] = 0;

            for (byte i = 0; i < byte.MaxValue; i++)
            {
                gf_exp[i] = (byte)mask;
                gf_log[mask] = (byte)i;

                mask <<= 1;
                if ((mask & 256) != 0)
                    mask = mask ^ primitive_polynomial;
            }

            /* set the extended gf_exp values for fast multiply */
            for (UInt32 i = 0 ; i < byte.MaxValue ; i++)
                gf_exp[i + byte.MaxValue] = gf_exp[i] ;

            inverse[0] = 0;
            inverse[1] = 1;

            for (UInt32 i=2; i <= byte.MaxValue; i++)
                inverse[i] = gf_exp[byte.MaxValue - gf_log[i]];
            #endregion
        }
Пример #2
0
        public GF8 Power(byte exponent)
        {
            if (Value == 0)
            {
                return(this);
            }
            if (exponent == 0)
            {
                this = 1;
            }

            GF8 original = this;

            for (int i = 1; i < exponent; i++)
            {
                this *= original;
            }

            return(this);
        }
Пример #3
0
        static GF8()
        {
            GF8.empty = new GF8(0);
            empty.i   = -1;

            #region Initialize Reference Tables
            UInt32 primitive_polynomial = 285;

            UInt32 mask = 1;
            gf_exp[8] = 0;

            for (byte i = 0; i < byte.MaxValue; i++)
            {
                gf_exp[i]    = (byte)mask;
                gf_log[mask] = (byte)i;

                mask <<= 1;
                if ((mask & 256) != 0)
                {
                    mask = mask ^ primitive_polynomial;
                }
            }

            /* set the extended gf_exp values for fast multiply */
            for (UInt32 i = 0; i < byte.MaxValue; i++)
            {
                gf_exp[i + byte.MaxValue] = gf_exp[i];
            }

            inverse[0] = 0;
            inverse[1] = 1;

            for (UInt32 i = 2; i <= byte.MaxValue; i++)
            {
                inverse[i] = gf_exp[byte.MaxValue - gf_log[i]];
            }
            #endregion
        }
Пример #4
0
 public static GF8 operator /(GF8 a, GF8 b)
 {
     return(GF8.Divide(a.Value, b.Value));
 }
Пример #5
0
 public static GF8 operator *(GF8 a, GF8 b)
 {
     return(GF8.Multiply(a.Value, b.Value));
 }
Пример #6
0
 public static GF8 operator -(GF8 a, GF8 b)
 {
     return(GF8.Add(a.Value, b.Value));
 }