Private/Checksum/Invoke-SecretSharingRs1024Polymod.ps1

function Invoke-SecretSharingRs1024Polymod {
    <#
    .SYNOPSIS
        Computes the RS1024 (SLIP-0039) Reed-Solomon polynomial modulus over a sequence
        of 10-bit words.
    .DESCRIPTION
        The same generalized Bech32-style checksum construction SLIP-0039 borrows,
        widened from 5-bit to 10-bit words: a Reed-Solomon code over GF(1024). A result
        of exactly 1 after appending a valid checksum indicates no detected error (any
        3 or fewer word errors are guaranteed to be detected).
    #>

    [CmdletBinding()]
    [OutputType([int])]
    param(
        [Parameter(Mandatory)]
        [int[]]$Value
    )

    $gen = @(
        0xE0E040, 0x1C1C080, 0x3838100, 0x7070200, 0xE0E0009,
        0x1C0C2412, 0x38086C24, 0x3090FC48, 0x21B1F890, 0x3F3F120
    )

    $checksum = 1
    foreach ($v in $Value) {
        $b = $checksum -shr 20
        $checksum = (($checksum -band 0xFFFFF) -shl 10) -bxor $v
        for ($i = 0; $i -lt 10; $i++) {
            if (($b -shr $i) -band 1) {
                $checksum = $checksum -bxor $gen[$i]
            }
        }
    }

    return $checksum
}