Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            ushort ResultCrc;
            string value = tbGTIN.Text;

            byte[] a = new byte[value.Length];
            char[] b = new char[value.Length];
            b = value.ToCharArray();
            byte [] GtinBytes = new byte[value.Length];


            System.Collections.IEnumerable collection = Enumerable.Range(100, 10);

            foreach (var ch in b.OfType <object>().Select((x, i) => new { x, i }))
            {
                int index = ch.i;
                try
                {
                    byte _GtinBytes = Convert.ToByte(ch.x);
                    GtinBytes[index] = _GtinBytes;
                }

                catch (OverflowException)
                {
                    Console.WriteLine("Unable to convert u+{0} to a byte.",
                                      Convert.ToInt16(ch).ToString("X4"));
                }
            }

            Crc16Model getVPCModel = new Crc16Model(0x8005, 0x0, 0x0, true, true);
            Crc16      getVPCDB    = new Crc16(getVPCModel);

            ResultCrc         = getVPCDB.Compute(GtinBytes);
            tbCrcResults.Text = ResultCrc.ToString();
        }
Exemplo n.º 2
0
        private void btnCRC16_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            Encoding enc = Encoding.GetEncoding(950);

            byte[] source = enc.GetBytes(txtCrcSource.Text);
            watch.Start();
            Crc16 crc = new Crc16();

            labCrc16Res.Text  = Crc16.Compute(source).ToString("X");
            labCrc16Byte.Text = crc.ComputeHash(source).ToHexString();
            watch.Stop();
            labCrc16Time.Text = watch.ElapsedTicks.ToString() + " Ticks";
            watch.Start();
            Crc16 modbus = new Crc16(Crc16.DefaultPolynomial, Crc16.ModbusSeed);

            labCrc16ResM.Text  = Crc16.Compute(source, Crc16.DefaultPolynomial, Crc16.ModbusSeed).ToString("X");
            labCrc16ByteM.Text = modbus.ComputeHash(source).ToHexString();
            watch.Stop();
            labCrc16TimeM.Text = watch.ElapsedTicks.ToString() + " Ticks";
            watch.Start();
            Crc32 crc32 = new Crc32();

            labCrc32Res.Text  = Crc32.Compute(source).ToString("X");
            labCrc32Byte.Text = crc32.ComputeHash(source).ToHexString();
            watch.Stop();
            labCrc32Time.Text = watch.ElapsedTicks.ToString() + " Ticks";
        }
Exemplo n.º 3
0
        private static void WriteChecksum(BitWriter writer, Crc16 crc, byte[] hcaBuffer)
        {
            writer.Position = writer.LengthBits - 16;
            var crc16 = crc.Compute(hcaBuffer, hcaBuffer.Length - 2);

            writer.Write(crc16, 16);
        }
Exemplo n.º 4
0
        private bool ValidateCrc(byte[] payload, ushort crc)
        {
            var payloadWithEtb = payload.Concat(new byte[] { ByteEtb });
            var computedCrc    = Crc16.Compute(payloadWithEtb);

            return(computedCrc == crc);
        }
Exemplo n.º 5
0
        public byte[] RawBytesToSend()
        {
            return(Match(i =>
            {
                switch (i)
                {
                case RequestInterruption.Abort:
                    return new[] { Bytes.CAN };

                default:
                    return Array.Empty <byte>();
                }
            }, data =>
            {
                var crc = Crc16.Compute(data.Concat(new[] { Bytes.ETB }));
                var crcByte1 = (byte)(crc / 256);
                var crcByte2 = (byte)(crc % 256);
                var bytes = new ByteArrayBuilder()
                            .Add(Bytes.SYN)
                            .Add(data)
                            .Add(Bytes.ETB)
                            .Add(crcByte1, crcByte2);
                return bytes.ToArray();
            }));
        }
Exemplo n.º 6
0
    // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
    private void TestCrc16(Crc16 crc, string value, ushort expected)
    {
        var messageData = System.Text.Encoding.ASCII.GetBytes(value);

        crc.Compute(messageData, 0, messageData.Length);
        var final = crc.ComputeFinal();

        Assert.AreEqual(expected, final);
    }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            byte[] data = Encoding.ASCII.GetBytes("123456789");

            var crc16 = new Crc16(Crc16.IBM, true);

            Console.WriteLine("CRC-16 = {0:X4}", crc16.Compute(data));

            var crc16ccitt = new Crc16(Crc16.CCITT, false, 0xFFFF, 0);

            Console.WriteLine("CRC-16-CCITT = {0:X4}", crc16ccitt.Compute(data));

            var crc32 = new Crc32(Crc32.IEEE, 0xFFFFFFFF, 0xFFFFFFFF);

            Console.WriteLine("CRC-32 = {0:X8}", crc32.Compute(data));
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            byte[] data = Encoding.ASCII.GetBytes("123456789");

            Crc16 crc16 = new Crc16(Crc16.IBM, true);

            Console.WriteLine("CRC-16 = {0:X4}", crc16.Compute(data));
            HashAlgorithm hash16 = new CRC16();

            Console.WriteLine("Nito CRC-16 = {0:X4}", BitConverter.ToUInt16(hash16.ComputeHash(data), 0));

            Crc16 crc16ccitt = new Crc16(Crc16.CCITT, false, 0xFFFF, 0);

            Console.WriteLine("CRC-16-CCITT = {0:X4}", crc16ccitt.Compute(data));
            HashAlgorithm hash16ccitt = new CRC16(CRC16.Definition.CcittFalse);

            Console.WriteLine("Nito CRC-16-CCITT = {0:X4}", BitConverter.ToUInt16(hash16ccitt.ComputeHash(data), 0));

            Crc32 crc32 = new Crc32(Crc32.IEEE, 0xFFFFFFFF, 0xFFFFFFFF);

            Console.WriteLine("CRC-32 = {0:X8}", crc32.Compute(data));
            HashAlgorithm hash32 = new CRC32();

            Console.WriteLine("Nito CRC-32 = {0:X8}", BitConverter.ToUInt32(hash32.ComputeHash(data), 0));

            XorHash32To16 xor1632 = new XorHash32To16(new Crc32(Crc32.IEEE));

            Console.WriteLine("Xor32To16 CRC-32 IEEE = {0:X4}", xor1632.Compute(data));
            CRC32.Definition crcdef = new CRC32.Definition();
            crcdef.FinalXorValue               = 0x0;
            crcdef.Initializer                 = 0x0;
            crcdef.ReverseDataBytes            = CRC32.Definition.Default.ReverseDataBytes;
            crcdef.ReverseResultBeforeFinalXor = CRC32.Definition.Default.ReverseResultBeforeFinalXor;
            crcdef.TruncatedPolynomial         = CRC32.Definition.Default.TruncatedPolynomial;
            HashAlgorithm hashXor = new Xor32To16Algorithm(crcdef.Create());

            Console.WriteLine("Nito Xor32To16 CRC-32 = {0:X4}", BitConverter.ToUInt16(hashXor.ComputeHash(data), 0));
#if DEBUG
            Console.WriteLine("---> Program finished.");
            Console.ReadKey();
#endif
        }
Exemplo n.º 9
0
        public void CrcThreadSafteyTest()
        {
            var serializer = new BinarySerializer();
            var frame      = new Frame {
                Payload = new Payload {
                    Number = 42, String = "Hello World"
                }
            };

            serializer.SerializeAsync(new MemoryStream(), new CrcWrap {
                Frame = frame
            }).ConfigureAwait(false).GetAwaiter()
            .GetResult();

            List <ushort> crcs = new List <ushort>();

            for (int i = 0; i < 50; i++)
            {
                ThreadPool.QueueUserWorkItem(state =>
                {
                    var frameStream = new MemoryStream();
#pragma warning disable 618
                    serializer.Serialize(frameStream, new CrcWrap {
                        Frame = frame
                    });
#pragma warning restore 618
                    var frameBytes = frameStream.ToArray();

                    Crc16 crc16 = new Crc16(0x1021, 0xffff);

                    crc16.Compute(frameBytes, 0, frameBytes.Length);

                    var crc = crc16.ComputeFinal();

                    crcs.Add(crc);
                });
            }

            Assert.All(crcs, crc => Assert.Equal(0, crc));
        }
Exemplo n.º 10
0
        private static byte[] FormatMessage(ref LowLevelRequestMessage message)
        {
            var bytes = new ByteArrayBuilder()
                        .Add(Bytes.SYN)
                        .Add(message.Command.acronym);

            if (!message.Parameters.Any())
            {
                message = message.With(parameters: new[] { string.Empty });
            }
            foreach (var parameter in message.Parameters)
            {
                bytes
                .Add(parameter.Length.ToString("000"))
                .Add(parameter);
            }
            bytes.Add(Bytes.ETB);
            var crc = Crc16.Compute(bytes.Skip(1));

            bytes.Add((byte)(crc / 256), (byte)(crc % 256));
            return(bytes.ToArray());
        }
Exemplo n.º 11
0
        protected override uint CreateHash(string value)
        {
            var computed = _crc16.Compute(SjisEncoding.GetBytes(value));

            return(BinaryPrimitives.ReadUInt32BigEndian(computed));
        }
Exemplo n.º 12
0
        public async Task <List <Roc809AlarmData> > GetAlarmData(Roc809 roc, IClient client)
        {
            var request = new byte[11];
            var data    = new List <Roc809AlarmData>();

            request[0] = (byte)roc.RocUnit;
            request[1] = (byte)roc.RocGroup;
            request[2] = (byte)roc.HostUnit;
            request[3] = (byte)roc.HostGroup;
            request[4] = 0x76;
            request[5] = 0x03;
            request[6] = 0x0a;
            request[7] = 0x00;
            request[8] = 0x00;

            var crc = Crc16.Compute(request, 9);

            request[9]  = crc[0];
            request[10] = crc[1];

            int startIndex = request.GetInt16(7);
            int totalIndex;

            var gprsClient = client as GprsClient;

            if (gprsClient != null)
            {
                await gprsClient.Connect(roc.Phone);
            }

            do
            {
                byte[] response;
                var    retries = client.Retries;
                var    valid   = false;
                do
                {
                    response = await client.GetData(roc, request);

                    var responseCrc = Crc16.Compute(response, 6 + response[5]);

                    if (response[6 + response[5]] == responseCrc[0] &&
                        response[6 + response[5] + 1] == responseCrc[1])
                    {
                        valid = true;
                        break;
                    }

                    retries--;
                } while (retries > 0);

                if (!valid)
                {
                    if (gprsClient != null)
                    {
                        await gprsClient.Disconnect(roc.Phone);
                    }

                    throw new Exception("Помилка читання даних через GPRS. Дані не є консистентними");
                }

                totalIndex = response.GetInt16(9);
                var alarmsToProcess = totalIndex - startIndex >= 10 ? 10 : totalIndex - startIndex;

                for (var i = 0; i < alarmsToProcess; i++)
                {
                    var offset = i * 23;

                    var record = new Roc809AlarmData();
                    var time   = new DateTime(1970, 1, 1, 0, 0, 0, 0);

                    record.SRBX      = (response[11 + offset] & (1 << 7)) != 0;
                    record.Condition = (response[11 + offset] & (1 << 6)) != 0;
                    record.Type      = response[11 + offset] & 63;

                    record.Time = time.AddSeconds(response.GetUInt32(12 + offset));

                    switch (record.Type)
                    {
                    case 0:
                        break;

                    case 1:
                        record.Code        = response[16 + offset];
                        record.T           = response[17 + offset];
                        record.L           = response[18 + offset];
                        record.P           = response[19 + offset];
                        record.Description = response.GetASCII(20 + offset, 10);
                        record.Value       = response.GetSingle(30 + offset).ToString(CultureInfo.InvariantCulture);
                        break;

                    case 2:
                        record.FST         = response[16 + offset];
                        record.Description = response.GetASCII(17 + offset, 13);
                        record.Value       = response.GetSingle(30 + offset).ToString(CultureInfo.InvariantCulture);
                        break;

                    case 3:
                        record.Description = response.GetASCII(16 + offset, 18);
                        break;

                    case 4:
                        record.Description = response.GetASCII(16 + offset, 14);
                        record.Value       = response.GetSingle(30 + offset).ToString(CultureInfo.InvariantCulture);
                        break;
                    }

                    data.Add(record);
                }

                startIndex = BitConverter.ToInt32(BitConverter.GetBytes(startIndex + 10), 0);

                request[7] = BitConverter.GetBytes(startIndex)[0];
                request[8] = BitConverter.GetBytes(startIndex)[1];

                crc = Crc16.Compute(request, 9);

                request[9]  = crc[0];
                request[10] = crc[1];
            } while (startIndex < totalIndex);

            if (gprsClient != null)
            {
                await gprsClient.Disconnect(roc.Phone);
            }
            return(data);
        }
Exemplo n.º 13
0
        public async Task <List <ROC809PeriodicDataModel> > GetPeriodicData(Roc809 roc, Roc809MeasurePoint point, RocHistoryType historyType, IClient client)
        {
            var request = new byte[15];

            request[0]  = (byte)roc.RocUnit;
            request[1]  = (byte)roc.RocGroup;
            request[2]  = (byte)roc.HostUnit;
            request[3]  = (byte)roc.HostGroup;
            request[4]  = 0x88;
            request[5]  = 0x07;
            request[6]  = (byte)point.HistSegment;
            request[7]  = 0x00;
            request[8]  = 0x00;
            request[9]  = (byte)historyType;
            request[10] = (byte)(point.Number - 1);
            request[11] = 0x01;
            request[12] = 0x1e;

            var crc = Crc16.Compute(request, 13);

            request[13] = crc[0];
            request[14] = crc[1];

            int startIndex = request.GetInt16(7);
            int totalIndex;

            var data = new List <ROC809PeriodicDataModel>();

            var gprsClient = client as GprsClient;

            if (gprsClient != null)
            {
                await gprsClient.Connect(roc.Phone);
            }

            do
            {
                byte[] response;
                var    retries = client.Retries;
                var    valid   = false;
                do
                {
                    response = await client.GetData(roc, request);

                    var responseCrc = Crc16.Compute(response, 6 + response[5]);

                    if (response[6 + response[5]] == responseCrc[0] &&
                        response[6 + response[5] + 1] == responseCrc[1])
                    {
                        valid = true;
                        break;
                    }

                    retries--;
                } while (retries > 0);

                if (!valid)
                {
                    if (gprsClient != null)
                    {
                        await gprsClient.Disconnect(roc.Phone);
                    }

                    throw new Exception("Помилка читання даних через GPRS. Дані не є консистентними");
                }

                totalIndex = historyType == RocHistoryType.Minute ? 60 : response.GetInt16(9);

                int recordsToProcess;

                if (historyType == RocHistoryType.Minute)
                {
                    recordsToProcess = response[11] / 2 >= 30 ? 30 : response[11] / 2;
                }
                else
                {
                    recordsToProcess = totalIndex - startIndex >= 30 ? 30 : totalIndex - startIndex;
                }

                for (var j = 0; j < recordsToProcess; j++)
                {
                    var offset = j * 8;

                    var    period = new DateTime(1970, 1, 1, 0, 0, 0, 0);
                    double value  = 0;

                    for (var k = 0; k < 2; k++)
                    {
                        var dataOffset = k * 4 + offset;

                        if (k == 0)
                        {
                            period = period.AddSeconds(response.GetUInt32(12 + dataOffset));
                        }
                        else
                        {
                            value = response.GetSingle(12 + dataOffset);
                        }
                    }

                    data.Add(new ROC809PeriodicDataModel {
                        DatePeriod = period, Value = value
                    });
                }

                startIndex = BitConverter.ToInt32(BitConverter.GetBytes(startIndex + 30), 0);

                request[7] = BitConverter.GetBytes(startIndex)[0];
                request[8] = BitConverter.GetBytes(startIndex)[1];

                crc = Crc16.Compute(request, 13);

                request[13] = crc[0];
                request[14] = crc[1];
            } while (startIndex < totalIndex);

            if (gprsClient != null)
            {
                await gprsClient.Disconnect(roc.Phone);
            }
            return(data.Distinct().ToList());
        }
Exemplo n.º 14
0
        public async Task <List <Roc809EventData> > GetEventData(Roc809 roc, IClient client)
        {
            var request = new byte[11];

            request[0] = (byte)roc.RocUnit;
            request[1] = (byte)roc.RocGroup;
            request[2] = (byte)roc.HostUnit;
            request[3] = (byte)roc.HostGroup;
            request[4] = 0x77;
            request[5] = 0x03;
            request[6] = 0x0a;
            request[7] = 0x01;
            request[8] = 0x00;

            var crc = Crc16.Compute(request, 9);

            request[9]  = crc[0];
            request[10] = crc[1];

            int startIndex = request.GetInt16(7);
            int totalIndex;

            var data = new List <Roc809EventData>();

            var gprsClient = client as GprsClient;

            if (gprsClient != null)
            {
                await gprsClient.Connect(roc.Phone);
            }

            do
            {
                byte[] response;
                var    retries = client.Retries;
                var    valid   = false;
                do
                {
                    response = await client.GetData(roc, request);

                    var responseCrc = Crc16.Compute(response, 6 + response[5]);

                    if (response[6 + response[5]] == responseCrc[0] &&
                        response[6 + response[5] + 1] == responseCrc[1])
                    {
                        valid = true;
                        break;
                    }

                    retries--;
                } while (retries > 0);

                if (!valid)
                {
                    if (gprsClient != null)
                    {
                        await gprsClient.Disconnect(roc.Phone);
                    }

                    throw new Exception("Помилка читання даних через GPRS. Дані не є консистентними");
                }

                totalIndex = response.GetInt16(9);
                var eventsToProcess = totalIndex - startIndex >= 10 ? 10 : totalIndex - startIndex;

                for (var i = 0; i < eventsToProcess; i++)
                {
                    var offset = i * 22;

                    var record = new Roc809EventData();
                    var time   = new DateTime(1970, 1, 1, 0, 0, 0, 0);

                    record.Type = response[11 + offset];

                    record.Time = time.AddSeconds(response.GetUInt32(12 + offset));

                    switch (record.Type)
                    {
                    case 0:
                        break;

                    case 1:
                        record.OperatorId = response.GetASCII(16 + offset, 3);

                        record.T = response[19 + offset];
                        record.L = response[20 + offset];
                        record.P = response[21 + offset];

                        switch (response[22 + offset])
                        {
                        case 0:
                            record.NewValue = response.GetBool(23 + offset) ? "1" : "0";
                            record.OldValue = response.GetBool(27 + offset) ? "1" : "0";
                            break;

                        case 1:
                            record.NewValue = response[23 + offset].ToString();
                            record.OldValue = response[27 + offset].ToString();
                            break;

                        case 2:
                            record.NewValue = response.GetInt16(23 + offset).ToString();
                            record.OldValue = response.GetInt16(27 + offset).ToString();
                            break;

                        case 3:
                            record.NewValue = response.GetInt32(23 + offset).ToString();
                            record.OldValue = response.GetInt32(27 + offset).ToString();
                            break;

                        case 4:
                            record.NewValue = response[23 + offset].ToString();
                            record.OldValue = response[27 + offset].ToString();
                            break;

                        case 5:
                            record.NewValue = response.GetUInt16(23 + offset).ToString();
                            record.OldValue = response.GetUInt16(27 + offset).ToString();
                            break;

                        case 6:
                            record.NewValue = response.GetUInt32(23 + offset).ToString();
                            record.OldValue = response.GetUInt32(27 + offset).ToString();
                            break;

                        case 7:
                            record.NewValue = response.GetSingle(23 + offset).ToString(CultureInfo.InvariantCulture);
                            record.OldValue = response.GetSingle(27 + offset).ToString(CultureInfo.InvariantCulture);
                            break;

                        case 8:
                            record.NewValue = response.GetTLP(23 + offset);
                            record.OldValue = response.GetTLP(27 + offset);
                            break;

                        case 9:
                            record.NewValue = response.GetASCII(23 + offset, 3);
                            record.OldValue = response.GetASCII(27 + offset, 3);
                            break;

                        case 10:
                            record.NewValue = response.GetASCII(23 + offset, 7);
                            break;

                        case 11:
                            record.NewValue = response.GetASCII(23 + offset, 10);
                            break;

                        case 12:
                            record.NewValue = response.GetASCII(23 + offset, 10);
                            break;

                        case 13:
                            record.NewValue = response.GetASCII(23 + offset, 10);
                            break;

                        case 14:
                            record.NewValue = response.GetASCII(23 + offset, 10);
                            break;

                        case 15:
                            record.NewValue = response.GetASCII(23 + offset, 10);
                            break;

                        case 16:
                            record.NewValue = response.GetDouble(23 + offset).ToString(CultureInfo.InvariantCulture);
                            break;

                        case 17:
                            record.NewValue = time.AddSeconds(response.GetUInt32(23 + offset)).ToString("dd.MM.yyyy HH:mm:ss");
                            record.OldValue = time.AddSeconds(response.GetUInt32(27 + offset)).ToString("dd.MM.yyyy HH:mm:ss");
                            break;
                        }
                        break;

                    case 2:
                        record.Code        = response[16 + offset];
                        record.Description = response.GetASCII(17 + offset, 16);
                        break;

                    case 3:
                        record.FST   = response[16 + offset];
                        record.Value = response.GetSingle(17 + offset).ToString(CultureInfo.InvariantCulture);
                        break;

                    case 4:
                        record.OperatorId  = response.GetASCII(16 + offset, 3);
                        record.Code        = response[19 + offset];
                        record.Description = response.GetASCII(20 + offset, 13);
                        break;

                    case 5:
                        record.Value = time.AddSeconds(response.GetUInt32(16 + offset)).ToString("dd.MM.yyyy HH:mm:ss");
                        break;

                    case 6:
                        record.Value = time.AddSeconds(response.GetUInt32(16 + offset)).ToString("dd.MM.yyyy HH:mm:ss");
                        break;

                    case 7:
                        record.OperatorId      = response.GetASCII(16 + offset, 3);
                        record.T               = response[19 + offset];
                        record.L               = response[20 + offset];
                        record.P               = response[21 + offset];
                        record.RawValue        = response.GetSingle(22 + offset).ToString(CultureInfo.InvariantCulture);
                        record.CalibratedValue = response.GetSingle(26 + offset).ToString(CultureInfo.InvariantCulture);
                        break;
                    }

                    data.Add(record);
                }

                startIndex = BitConverter.ToInt32(BitConverter.GetBytes(startIndex + 10), 0);

                request[7] = BitConverter.GetBytes(startIndex)[0];
                request[8] = BitConverter.GetBytes(startIndex)[1];

                crc = Crc16.Compute(request, 9);

                request[9]  = crc[0];
                request[10] = crc[1];
            } while (startIndex < totalIndex);

            if (gprsClient != null)
            {
                await gprsClient.Disconnect(roc.Phone);
            }
            return(data);
        }
Exemplo n.º 15
0
        public static byte[] GenerateChecksum(string checksum, int offset, byte[] buffer, int eof = -1)
        {
            byte[] returnValue = null;
            switch (checksum)
            {
            case "Adler8 - {1Bytes}":
                returnValue = eof == -1 ? Adler8.Compute(offset, buffer) : Adler8.Compute(offset, buffer, eof);
                break;

            case "Adler16 - {2Bytes}":
                returnValue = eof == -1 ? Adler16.Compute(offset, buffer) : Adler16.Compute(offset, buffer, eof);
                break;

            case "Adler32 - {4Bytes}":
                returnValue = eof == -1 ? Adler32.Compute(offset, buffer) : Adler32.Compute(offset, buffer, eof);
                break;

            case "Checksum8 - {1Bytes}":
                returnValue = eof == -1 ? Checksum8.Compute(offset, buffer) : Checksum8.Compute(offset, buffer, eof);
                break;

            case "Checksum16 - {2Bytes}":
                returnValue = eof == -1 ? Checksum16.Compute(offset, buffer) : Checksum16.Compute(offset, buffer, eof);
                break;

            case "Checksum24 - {3Bytes}":
                returnValue = eof == -1 ? Checksum24.Compute(offset, buffer) : Checksum24.Compute(offset, buffer, eof);
                break;

            case "Checksum32 - {4Bytes}":
                returnValue = eof == -1 ? Checksum32.Compute(offset, buffer) : Checksum32.Compute(offset, buffer, eof);
                break;

            case "Checksum40 - {5Bytes}":
                returnValue = eof == -1 ? Checksum40.Compute(offset, buffer) : Checksum40.Compute(offset, buffer, eof);
                break;

            case "Checksum48 - {6Bytes}":
                returnValue = eof == -1 ? Checksum48.Compute(offset, buffer) : Checksum48.Compute(offset, buffer, eof);
                break;

            case "Checksum56 - {7Bytes}":
                returnValue = eof == -1 ? Checksum56.Compute(offset, buffer) : Checksum56.Compute(offset, buffer, eof);
                break;

            case "Checksum64 - {8Bytes}":
                returnValue = eof == -1 ? Checksum64.Compute(offset, buffer) : Checksum64.Compute(offset, buffer, eof);
                break;

            case "CRC16 - {2Bytes}":
                Crc16 crc16 = new Crc16();
                returnValue = eof == -1 ? crc16.Compute(offset, buffer) : crc16.Compute(offset, buffer, eof);
                break;

            case "CRC16 CCITT - {2Bytes}":
                Crc16ccitt crc16Ccitt = new Crc16ccitt();
                returnValue = eof == -1 ? crc16Ccitt.Compute(offset, buffer) : crc16Ccitt.Compute(offset, buffer, eof);
                break;

            case "CRC32 - {4Bytes}":
                returnValue = eof == -1 ? Crc32.Compute(offset, buffer) : Crc32.Compute(offset, buffer, eof);
                break;

            case "HMAC SHA 1 (128)  - {16Bytes}":
                returnValue = eof == -1 ? HmacSha1.Compute(offset, buffer) : HmacSha1.Compute(offset, buffer, eof);
                break;

            case "HMAC SHA 256 - {32Bytes}":
                returnValue = eof == -1 ? HmacSha256.Compute(offset, buffer) : HmacSha256.Compute(offset, buffer, eof);
                break;

            case "HMAC SHA 384 - {48Bytes}":
                returnValue = eof == -1 ? HmacSha384.Compute(offset, buffer) : HmacSha384.Compute(offset, buffer, eof);
                break;

            case "HMAC SHA 512 - {64Bytes}":
                returnValue = eof == -1 ? HmacSha512.Compute(offset, buffer) : HmacSha512.Compute(offset, buffer, eof);
                break;

            case "MD5 - {16Bytes}":
                returnValue = eof == -1 ? Md5.Compute(offset, buffer) : Md5.Compute(offset, buffer, eof);
                break;

            case "MD5 CNG - {16Bytes}":
                returnValue = eof == -1 ? Md5Cng.Compute(offset, buffer) : Md5Cng.Compute(offset, buffer, eof);
                break;
            }
            return(returnValue);
        }
 /// <summary>
 /// This is called one or more times by the framework to add data to the computation.
 /// </summary>
 /// <param name="buffer"></param>
 /// <param name="offset"></param>
 /// <param name="count"></param>
 protected override void Compute(byte[] buffer, int offset, int count)
 {
     _crc.Compute(buffer, offset, count);
 }