Reed_Solomon

An error-correction implementation for Deno.

Reed-Solomon error correction is used in 2D barcodes, CDs and so on. See ZXing’s implementation

// @ts-ignore
import { GaloisField, ReedSolomonEncoder, ReedSolomonDecoder } from "https://deno.land/x/reed_solomon@v2.1.0/mod.ts";

// QR CODE
// new GaloisField(0x11d, 0x100, 1);

// MAXICODE
// new GaloisField( 0x43,  0x40, 2);

// AZTEC
// new GaloisField(  0x13,   0x10, 2);
// new GaloisField(  0x43,   0x40, 2);
// new GaloisField( 0x12d,  0x100, 2);
// new GaloisField( 0x409,  0x400, 2);
// new GaloisField(0x1069, 0x1000, 2);

// DATA MATRIX
// new GaloisField(0x12d, 0x100, 2);

// EXAMPLE
const field = new GaloisField(0x10, 0x13, 2);

const array = [8, 6, 7, 5, 3, 0, 9];

const BLOCKS_LENGTH = 15;
const BLOCKS_DATA = array.length;
const BLOCKS_ECC = BLOCKS_LENGTH - BLOCKS_DATA;

const rse = new ReedSolomonEncoder(field, BLOCKS_ECC);

const encoded = rse.encode(array);

encoded[0] = 1;
encoded[1] = 1;
encoded[2] = 3
console.log('\nBefore Restoration:');;
console.log(encoded);

ReedSolomonDecoder(field, encoded, BLOCKS_ECC);

console.log('\nAfter Restoration:');
console.log(encoded);