Exemplo n.º 1
0
        public CRC32(InitialCrcValue val)
            : base(val)
        {
            uint poly = 0xedb88320;

            table = new uint[256];
            uint temp = 0;

            for (uint i = 0; i < table.Length; ++i)
            {
                temp = i;
                for (int j = 8; j > 0; --j)
                {
                    if ((temp & 1) == 1)
                    {
                        temp = (uint)((temp >> 1) ^ poly);
                    }
                    else
                    {
                        temp >>= 1;
                    }
                }
                table[i] = temp;
            }
        }
Exemplo n.º 2
0
        public CDMACRC(InitialCrcValue initialValue)
        {
            this.initialValue = (ushort)initialValue;
            int num5 = this.table.Length - 1;

            for (int i = 0; i <= num5; i++)
            {
                ushort num2 = 0;
                ushort num  = (ushort)(i << 8);
                int    num4 = 0;
                do
                {
                    if (((num2 ^ num) & 0x8000) != 0)
                    {
                        num2 = (ushort)(((ushort)(num2 << 1)) ^ 0x1021);
                    }
                    else
                    {
                        num2 = (ushort)(num2 << 1);
                    }
                    num = (ushort)(num << 1);
                    num4++;
                }while (num4 <= 7);
                this.table[i] = num2;
            }
        }
Exemplo n.º 3
0
        public CRC16(InitialCrcValue val)
            : base(val)
        {
            ushort value;
            ushort temp;

            for (ushort i = 0; i < table.Length; ++i)
            {
                value = 0;
                temp  = i;
                for (byte j = 0; j < 8; ++j)
                {
                    if (((value ^ temp) & 0x0001) != 0)
                    {
                        value = (ushort)((value >> 1) ^ polynomial);
                    }
                    else
                    {
                        value >>= 1;
                    }
                    temp >>= 1;
                }
                table[i] = value;
            }
        }
Exemplo n.º 4
0
        public CRC16CCITT(InitialCrcValue val)
            : base(val)
        {
            this.initialValue = (ushort)val;
            ushort temp, a;

            for (int i = 0; i < table.Length; ++i)
            {
                temp = 0;
                a    = (ushort)(i << 8);
                for (int j = 0; j < 8; ++j)
                {
                    if (((temp ^ a) & 0x8000) != 0)
                    {
                        temp = (ushort)((temp << 1) ^ poly);
                    }
                    else
                    {
                        temp <<= 1;
                    }
                    a <<= 1;
                }
                table[i] = temp;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// CRC16 - CCITT
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static string CRC16C(byte[] data, InitialCrcValue icv)
        {
            ushort[] tab = new ushort[256];
            ushort   t = 0, a = 0, crc = (ushort)icv;

            for (int i = 0; i < 256; i++)
            {
                t = 0;
                a = (ushort)(i << 8);
                for (int j = 0; j < 8; j++)
                {
                    if (((t ^ a) & 0x8000) != 0)
                    {
                        t = (ushort)((t << 1) ^ 0x1021);
                    }
                    else
                    {
                        t <<= 1;
                    }
                    a <<= 1;
                }
                tab[i] = t;
            }
            for (int i = 0; i < data.Length; i++)
            {
                crc = (ushort)((crc << 8) ^ tab[((crc >> 8) ^ (0xFF & data[i]))]);
            }
            return(Utils.Bin2AHex(BitConverter.GetBytes(crc)));
        }
Exemplo n.º 6
0
        public Crc16Ccitt(InitialCrcValue pinitialValue)
        {
            initialValue = (ushort)pinitialValue;

            ushort temp, a;

            for (int i = 0; i < table.Length; i++)
            {
                temp = 0;
                a    = (ushort)(i << 8);
                for (int j = 0; j < 8; j++)
                {
                    if (((temp ^ a) & 0x8000) != 0)
                    {
                        temp = (ushort)((temp << 1) ^ poly);
                    }
                    else
                    {
                        temp <<= 1;
                    }
                    a <<= 1;
                }
                table[i] = temp;
            }
        }
Exemplo n.º 7
0
Arquivo: crc.cs Projeto: kkouer/PcGcs
 public Crc16Ccitt(InitialCrcValue initialValue)
 {
     this.initialValue = (ushort)initialValue;
     if (table == null)
     {
         table = new ushort[256];
         ushort temp, a;
         for (int i = 0; i < table.Length; i++)
         {
             temp = 0;
             a = (ushort)(i << 8);
             for (int j = 0; j < 8; j++)
             {
                 if (((temp ^ a) & 0x8000) != 0)
                 {
                     temp = (ushort)((temp << 1) ^ poly);
                 }
                 else
                 {
                     temp <<= 1;
                 }
                 a <<= 1;
             }
             table[i] = temp;
         }
     }
 }
Exemplo n.º 8
0
Arquivo: sbp.cs Projeto: 894880010/MP
 public Crc16Ccitt(InitialCrcValue initialValue)
 {
     this.initialValue = (ushort)initialValue;
     if (table == null)
     {
         table = new ushort[256];
         ushort temp, a;
         for (int i = 0; i < table.Length; i++)
         {
             temp = 0;
             a    = (ushort)(i << 8);
             for (int j = 0; j < 8; j++)
             {
                 if (((temp ^ a) & 0x8000) != 0)
                 {
                     temp = (ushort)((temp << 1) ^ poly);
                 }
                 else
                 {
                     temp <<= 1;
                 }
                 a <<= 1;
             }
             table[i] = temp;
         }
     }
 }
Exemplo n.º 9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="type">位数</param>
 /// <param name="initialValue">初始值</param>
 public CrcCcitt(CrcType type, InitialCrcValue initialValue = InitialCrcValue.Zeros)
 {
     crcType = type;
     if (crcType == CrcType.CRC_16)
     {
         initialCrcValue   = initialValue;
         this.initialValue = (ushort)initialValue;
         ushort temp, a;
         for (int i = 0; i < table.Length; i++)
         {
             temp = 0;
             a    = (ushort)(i << 8);
             for (int j = 0; j < 8; j++)
             {
                 if (((temp ^ a) & 0x8000) != 0)
                 {
                     temp = (ushort)((temp << 1) ^ polynominal);
                 }
                 else
                 {
                     temp <<= 1;
                 }
                 a <<= 1;
             }
             table[i] = temp;
         }
     }
 }
Exemplo n.º 10
0
 public void Crc16Ccitt(InitialCrcValue initialValue)
 {
     this.initialValue = (ushort)initialValue;
     ushort temp, a;
     for(int i = 0; i < table.Length; ++i) {
         temp = 0;
         a = (ushort)(i << 8);
         for(int j = 0; j < 8; ++j) {
             if(((temp ^ a) & 0x8000) != 0) {
                 temp = (ushort)((temp << 1) ^ poly);
             }else{
                 temp <<= 1;
             }
             a <<= 1;
         }
         table[i] = temp;
     }
 }
Exemplo n.º 11
0
 public Crc16Ccitt(InitialCrcValue initialValue)
 {
     _initialValue = (ushort)initialValue;
     for (int i = 0; i < _table.Length; i++)
     {
         ushort temp = 0;
         ushort a    = (ushort)(i << 8);
         for (int j = 0; j < 8; ++j)
         {
             if (((temp ^ a) & 0x8000) != 0)
             {
                 temp = (ushort)((temp << 1) ^ Poly);
             }
             else
             {
                 temp <<= 1;
             }
             a <<= 1;
         }
         _table[i] = temp;
     }
 }
Exemplo n.º 12
0
 public Crc16Ccitt(InitialCrcValue initialValue)
 {
     this.initialValue = (ushort)initialValue;
     for (int i = 0; i < this.table.Length; i++)
     {
         ushort temp = 0;
         ushort a    = (ushort)(i << 8);
         for (int j = 0; j < 8; j++)
         {
             if (((temp ^ a) & 32768) != 0)
             {
                 temp = (ushort)((int)temp << 1 ^ 4129);
             }
             else
             {
                 temp = (ushort)(temp << 1);
             }
             a = (ushort)(a << 1);
         }
         this.table[i] = temp;
     }
 }
Exemplo n.º 13
0
        public CRC16_CCITT(InitialCrcValue initialValue)
        {
            this.InitialValue = initialValue;

            for (int i = 0; i <= this.table.Length - 1; i++)
            {
                UInt16 temp = 0;
                UInt16 a    = (UInt16)(i << 8);
                for (int j = 0; j <= 7; j++)
                {
                    if (((temp ^ a) & 0x8000) != 0)
                    {
                        temp = (UInt16)((temp << 1) ^ poly);
                    }
                    else
                    {
                        temp = (UInt16)(temp << 1);
                    }
                    a = (UInt16)(a << 1);
                }
                this.table[i] = temp;
            }
        }
Exemplo n.º 14
0
 public CRC32(InitialCrcValue val)
     : base(val)
 {
     uint poly = 0xedb88320;
     table = new uint[256];
     uint temp = 0;
     for (uint i = 0; i < table.Length; ++i)
     {
         temp = i;
         for (int j = 8; j > 0; --j)
         {
             if ((temp & 1) == 1)
             {
                 temp = (uint)((temp >> 1) ^ poly);
             }
             else
             {
                 temp >>= 1;
             }
         }
         table[i] = temp;
     }
 }
Exemplo n.º 15
0
 public CRC16(InitialCrcValue val)
     : base(val)
 {
     ushort value;
     ushort temp;
     for (ushort i = 0; i < table.Length; ++i)
     {
         value = 0;
         temp = i;
         for (byte j = 0; j < 8; ++j)
         {
             if (((value ^ temp) & 0x0001) != 0)
             {
                 value = (ushort)((value >> 1) ^ polynomial);
             }
             else
             {
                 value >>= 1;
             }
             temp >>= 1;
         }
         table[i] = value;
     }
 }
Exemplo n.º 16
0
        public Crc16(InitialCrcValue initialValue)
        {
            this.initialValue = (ushort)initialValue;
            ushort temp, a;

            for (int i = 0; i < table.Length; ++i)
            {
                temp = 0;
                a    = (ushort)(i << 8);
                for (int j = 0; j < 8; ++j)
                {
                    if (((temp ^ a) & 0x8000) != 0)
                    {
                        temp = (ushort)((temp << 1) ^ poly);
                    }
                    else
                    {
                        temp <<= 1;
                    }
                    a <<= 1;
                }
                table[i] = temp;
            }
        }
Exemplo n.º 17
0
 public CRC16CCITT(InitialCrcValue val)
     : base(val)
 {
     this.initialValue = (ushort)val;
     ushort temp, a;
     for (int i = 0; i < table.Length; ++i)
     {
         temp = 0;
         a = (ushort)(i << 8);
         for (int j = 0; j < 8; ++j)
         {
             if (((temp ^ a) & 0x8000) != 0)
             {
                 temp = (ushort)((temp << 1) ^ poly);
             }
             else
             {
                 temp <<= 1;
             }
             a <<= 1;
         }
         table[i] = temp;
     }
 }
Exemplo n.º 18
0
 public Crc16(InitialCrcValue initialValue)
 {
     this.initialValue = (ushort)initialValue;
 }
Exemplo n.º 19
0
 public CRC16CCITT(InitialCrcValue initialValue)
 {
     this.initialValue = (ushort)initialValue;
     GenTable((ushort)initialValue, (ushort)4219);
 }
Exemplo n.º 20
0
 /// <summary>
 /// CRC16 - CCITT
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public static string CRC16C(string data, InitialCrcValue icv)
 {
     return(CRC16C(Utils.AHex2Bin(data), icv));
 }
Exemplo n.º 21
0
        public CRC(InitialCrcValue val)
        {


        }
Exemplo n.º 22
0
 public CRC16CCITT(InitialCrcValue initialValue)
 {
     this.initialValue = (ushort)initialValue;
     GenTable((ushort)initialValue, (ushort)4219);
 }
Exemplo n.º 23
0
 public CRC(InitialCrcValue val)
 {
 }
Exemplo n.º 24
0
 public CRC8(InitialCrcValue val)
     : base(val)
 {
 }