Primitive binary BCH coding, shortened decoding and checksummed block recovery in pure MoonBit.
moon test --target js
moon run cmd/main --target js -- encode 4 2 1010101
moon run cmd/main --target js -- decode 4 2 001010111100100
moon run cmd/main --target js -- protect 8 2 input.bin protected.mbch
moon run cmd/main --target js -- recover damaged.mbch recovered.binlet code = @bch.Bch::new(4, 2)
let word = code.encode([1, 0, 1, 0, 1, 0, 1])
word[0] = word[0] ^ 1
let fixed = code.decode(word)
// fixed.message = [1,0,1,0,1,0,1], fixed.corrected_positions = [0]pub(all) suberror BchError {
InvalidParameters
InvalidBit(Int)
InvalidLength
Uncorrectable
InvalidFrame
ChecksumMismatch
}Install
Download zipPrimitive binary BCH coding, shortened decoding and checksummed block recovery in pure MoonBit.