Table of Contents

Pearson Class

Definition

Namespace
Bodu.IO.Hashing
Assembly
Bodu.IO.Hashing.dll
Package
Bodu.IO.Hashing 1.0.0
Source
Pearson.Tables.cs

Computes the hash for the input data using the Pearson hash algorithm. This variant applies a non-cryptographic permutation-based transformation using a 256-byte lookup table to produce compact hash values. This class cannot be inherited.

public sealed class Pearson : NonCryptographicHashAlgorithm
Inheritance
Pearson
Inherited Members
Extension Methods

Remarks

The Pearson hashing algorithm, introduced by Peter K. Pearson in 1990, computes a fixed-size hash (typically 8-bit or larger) by transforming each byte of the input using a 256-element permutation table.

When computing multi-byte hashes (for example a 64-bit digest), the algorithm is repeated for each byte of the result, using a different initialization for each output byte to reduce collisions.

When to choose Pearson. Pearson is interesting in two niches: extremely small lookup tables - a Pearson byte is the cheapest way to hash a key into a 256-bucket index - and resource-poor embedded targets where a 256-byte permutation table is small enough to fit in cache and a 64-bit-sized hash can be assembled from eight independent 8-bit hashes without ever needing wide-integer arithmetic. For modern hash-table workloads with realistic key spaces, prefer Fnv1a32 / Fnv1a64 or MurmurHash3; Pearson's per-byte distribution is weaker than those alternatives.

Output and lifecycle. Output size is set by the constructor's hashSize argument (a multiple of 8 bits, typically 8, 16, 32, or 64). The digest is emitted in little-endian byte order. GetCurrentHash() is non-destructive; instances are not thread-safe.

important

This algorithm is not cryptographically secure and should not be used for password hashing, digital signatures, or integrity validation in security-sensitive applications.

using Bodu.IO.Hashing;
using Bodu.IO.Hashing.Extensions;

8-byte (64-bit) Pearson digest assembled from eight permutation passes,
using one of the canonical lookup tables.
var pearson = new Pearson(hashSizeBits: 64, PearsonTableType.Pearson);
byte[] digest = pearson.ComputeHash(System.Text.Encoding.UTF8.GetBytes("payload"));

Constructors

Pearson()

Initializes a new instance of the Pearson class with an 8-bit hash size and the canonical Pearson permutation table.

public Pearson()

Pearson(int, PearsonTableType)

Initializes a new instance of the Pearson class with the specified hash size and a predefined permutation table.

public Pearson(int hashSizeBits, Pearson.PearsonTableType tableType)

Parameters

hashSizeBits int

The size of the produced digest in bits. Must be a multiple of 8 in the inclusive range [ MinHashSizeBits, MaxHashSizeBits].

tableType Pearson.PearsonTableType

One of the predefined permutation tables. To supply a custom permutation, use the Pearson(int, byte[]) overload instead.

Exceptions

ArgumentOutOfRangeException

hashSizeBits is outside the inclusive range [MinHashSizeBits, MaxHashSizeBits] or is not a multiple of 8.

ArgumentException

tableType is UserDefined.

Pearson(int, byte[])

Initializes a new instance of the Pearson class with the specified hash size and a caller-supplied permutation table.

public Pearson(int hashSizeBits, byte[] permutationTable)

Parameters

hashSizeBits int

The size of the produced digest in bits. Must be a multiple of 8 in the inclusive range [ MinHashSizeBits, MaxHashSizeBits].

permutationTable byte[]

A 256-byte permutation containing every byte value 0..255 exactly once.

Exceptions

ArgumentNullException

permutationTable is null.

ArgumentException

permutationTable is not a 256-element permutation of 0..255.

ArgumentOutOfRangeException

hashSizeBits is outside the inclusive range [MinHashSizeBits, MaxHashSizeBits] or is not a multiple of 8.

Fields

MaxHashSizeBits

The maximum allowable hash size in bits.

public const int MaxHashSizeBits = 2048

Field Value

int

MinHashSizeBits

The minimum allowable hash size in bits.

public const int MinHashSizeBits = 8

Field Value

int

Properties

Table

Gets a copy of the 256-byte permutation table currently in use.

public byte[] Table { get; }

Property Value

byte[]

TableType

Gets the permutation table preset selected for this instance.

public Pearson.PearsonTableType TableType { get; }

Property Value

Pearson.PearsonTableType

Methods

Append(ReadOnlySpan<byte>)

When overridden in a derived class, appends the contents of source to the data already processed for the current hash computation.

public override void Append(ReadOnlySpan<byte> source)

Parameters

source ReadOnlySpan<byte>

The data to process.

GetCurrentHashCore(Span<byte>)

When overridden in a derived class, writes the computed hash value to destination without modifying accumulated state.

protected override void GetCurrentHashCore(Span<byte> destination)

Parameters

destination Span<byte>

The buffer that receives the computed hash value.

Reset()

When overridden in a derived class, resets the hash computation to the initial state.

public override void Reset()

Applies to

ProductVersions
.NET8, 10