Mythosia.Integrity 1.2.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Mythosia.Integrity --version 1.2.1
                    
NuGet\Install-Package Mythosia.Integrity -Version 1.2.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Mythosia.Integrity" Version="1.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Mythosia.Integrity" Version="1.2.1" />
                    
Directory.Packages.props
<PackageReference Include="Mythosia.Integrity" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Mythosia.Integrity --version 1.2.1
                    
#r "nuget: Mythosia.Integrity, 1.2.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Mythosia.Integrity@1.2.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Mythosia.Integrity&version=1.2.1
                    
Install as a Cake Addin
#tool nuget:?package=Mythosia.Integrity&version=1.2.1
                    
Install as a Cake Tool

Mythosia.Integrity

CRC and 8-bit checksum calculation, frame encoding and error detection for byte sequences. Hash algorithms are provided by Mythosia.Security.Cryptography.

Version 1.2.1 improves initialization safety and calculation efficiency while preserving the public API and existing results. See the release notes.

Each C# block below is a complete, independent example for a .NET 8 console application referencing Mythosia.Integrity. Copy one block into Program.cs. All examples use the ASCII bytes of 123456789.

CRC extensions

Numeric extensions return a byte, ushort or uint for CRC8, CRC16 and CRC32, respectively. WithCRC8, WithCRC16 and WithCRC32 append the digest to the payload and return IEnumerable<byte>; use ToArray() to materialize a frame.

using System;
using System.Linq;
using System.Text;
using Mythosia.Integrity.CRC;

byte[] data = Encoding.ASCII.GetBytes("123456789");

Console.WriteLine($"CRC8 Classic: {data.CRC8(CRC8Type.Classic):X2}");          // F4
Console.WriteLine($"CRC8 Maxim: {data.CRC8(CRC8Type.Maxim):X2}");              // A1
Console.WriteLine($"CRC16 Classic: {data.CRC16(CRC16Type.Classic):X4}");       // BB3D
Console.WriteLine($"CRC16 Modbus: {data.CRC16(CRC16Type.Modbus):X4}");         // 4B37
Console.WriteLine($"CRC16 XModem: {data.CRC16(CRC16Type.CCITTxModem):X4}");    // 31C3
Console.WriteLine($"CRC16 DNP: {data.CRC16(CRC16Type.DNP):X4}");               // 82EA (legacy representation)
Console.WriteLine($"CRC32 Classic: {data.CRC32(CRC32Type.Classic):X8}");       // CBF43926

byte[] crc8Frame = data.WithCRC8(CRC8Type.Classic).ToArray();
byte[] crc16Frame = data.WithCRC16(CRC16Type.Modbus).ToArray();
byte[] crc32Frame = data.WithCRC32(CRC32Type.Classic).ToArray();

Console.WriteLine($"CRC8 frame valid: {!new CRC8(CRC8Type.Classic).IsError(crc8Frame)}");
Console.WriteLine($"CRC16 frame valid: {!new CRC16(CRC16Type.Modbus).IsError(crc16Frame)}");
Console.WriteLine($"CRC32 frame valid: {!new CRC32(CRC32Type.Classic).IsError(crc32Frame)}");
// All three frame checks print True.

The examples select each algorithm explicitly. The obsolete Basic enum members remain supported and calculate the same result as Classic. CRC16 and CRC32 extension methods retain Basic as their optional default; their constructors default to Classic.

CRC16Type.DNP preserves Mythosia's existing byte-swapped numeric representation: this input returns 0x82EA. The canonical CRC-16/DNP check value is 0xEA82, as listed in the CRC RevEng catalogue.

Checksum extensions

Use Checksum8, WithChecksum8 and Checksum8Type. The older CheckSum8, WithCheckSum8 and CheckSum8Type spellings remain supported as obsolete aliases.

using System;
using System.Linq;
using System.Text;
using Mythosia.Integrity.Checksum;

byte[] data = Encoding.ASCII.GetBytes("123456789");

Console.WriteLine($"XOR: {data.Checksum8(Checksum8Type.Xor):X2}");                        // 31
Console.WriteLine($"NMEA: {data.Checksum8(Checksum8Type.NMEA):X2}");                      // 31
Console.WriteLine($"Modulo 256: {data.Checksum8(Checksum8Type.Modulo256):X2}");            // DD
Console.WriteLine($"Two's complement: {data.Checksum8(Checksum8Type.TwosComplement):X2}"); // 23

byte[] frame = data.WithChecksum8(Checksum8Type.Xor).ToArray();
var detector = new Checksum8(Checksum8Type.Xor);
Console.WriteLine($"Checksum frame valid: {!detector.IsError(frame)}"); // True

Checksum8Type.NMEA applies XOR to the supplied bytes. It does not parse an NMEA sentence or add $, * or hexadecimal ASCII checksum characters.

Common API: compute, encode and validate

All detectors inherit from ErrorDetection:

Method Result
Compute(source) Digest bytes for the payload.
Encode(source) Payload followed by the digest bytes.
IsError(frame) true when the frame is too short or its digest does not match.
Decode(frame) Original payload for a valid frame; an empty sequence for an invalid frame.

Pass the payload to Compute; there is no parameterless overload. The following example uses the same API with checksum and CRC detectors, then changes one digest bit to demonstrate error detection.

using System;
using System.Linq;
using System.Text;
using Mythosia.Integrity;
using Mythosia.Integrity.Checksum;
using Mythosia.Integrity.CRC;

byte[] content = Encoding.ASCII.GetBytes("123456789");
ErrorDetection[] detectors =
{
    new Checksum8(Checksum8Type.Xor),
    new Checksum8(Checksum8Type.Modulo256),
    new CRC8(CRC8Type.Classic),
    new CRC16(CRC16Type.Classic),
    new CRC32(CRC32Type.Classic)
};

foreach (ErrorDetection detector in detectors)
{
    byte[] digest = detector.Compute(content).ToArray();
    byte[] encoded = detector.Encode(content).ToArray();
    byte[] decoded = detector.Decode(encoded).ToArray();

    Console.WriteLine($"{detector.GetType().Name}/{detector.GetDetectionType()}: " +
        $"digest={Convert.ToHexString(digest)}, " +
        $"valid={!detector.IsError(encoded)}, decoded={decoded.SequenceEqual(content)}");

    byte[] damaged = (byte[])encoded.Clone();
    damaged[damaged.Length - 1] ^= 0x01;
    Console.WriteLine($"Damaged frame: {detector.IsError(damaged)}");
}
// Every detector prints valid=True, decoded=True and Damaged frame: True.

Input and byte order

Use a non-empty payload. Empty-input behavior differs by algorithm: CRC8 and Checksum8 return an empty digest, and their numeric extensions and Encode throw for empty inputs. CRC16 and CRC32 can produce digest-only frames, but IsError rejects those frames and Decode returns an empty sequence.

Inputs must support repeated enumeration. Materialize a stream or one-shot iterator into a byte array before calling these APIs.

CRC16 and CRC32 digest bytes use the current machine's native byte order. For example, new CRC16(CRC16Type.Classic).Compute(data) produces 3D BB on a little-endian machine and BB 3D on a big-endian machine. A protocol that specifies a fixed byte order needs explicit serialization for that protocol.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.3.0 485 10/14/2026
1.2.1 101 10/14/2026
1.2.0 3,277 8/13/2023
1.1.1 303 6/25/2023
1.1.0 349 6/24/2023
1.0.0 303 6/19/2023

1.2.1
- Make CRC16 and CRC32 lookup-table initialization safe during concurrent first use.
- Reduce repeated enumeration, redundant frame-length checks and CRC8/CRC16 byte-array traversal overhead.
- Remove boxing, marshaling and temporary serialization buffers from CRC16/CRC32 digest packing.
- Preserve the public API, existing calculation results, native byte order and legacy DNP representation.
- Add independent correctness, compatibility and initialization tests, Windows/Linux Debug/Release CI, and corrected executable README examples.
Full release notes: https://github.com/AJ-comp/Mythosia/blob/master/Mythosia.Integrity/RELEASE_NOTES.md