qrmanual
Version:
Implementação de QR Code v2-L (25×25, correção L) em TypeScript
27 lines (26 loc) • 817 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.reedSolomon = reedSolomon;
const gf_1 = require("./gf");
function reedSolomon(data, degree) {
let poly = [1];
for (let i = 0; i < degree; i++) {
const next = new Array(poly.length + 1).fill(0);
for (let j = 0; j < poly.length; j++) {
next[j] ^= (0, gf_1.gfMul)(poly[j], gf_1.EXP_TABLE[i]);
next[j + 1] ^= poly[j];
}
poly = next;
}
const res = new Array(degree).fill(0);
for (const b of data) {
const factor = b ^ res.shift();
res.push(0);
if (factor !== 0) {
for (let i = 0; i < degree; i++) {
res[i] ^= (0, gf_1.gfMul)(poly[poly.length - 1 - i], factor);
}
}
}
return res;
}