module

CrImage::Util::QRCode::ReedSolomon

Reed-Solomon encoder for QR codes Uses GF(2^8) with primitive polynomial x^8 + x^4 + x^3 + x^2 + 1 (0x11d)

Constants

EXP = begin exp = Array(Int32).new(512, 0) x = 1 256.times do |i| exp[i] = x x = x << 1 if x >= 256 x = x ^ 285 end end 256.times do |i| exp[i + 256] = exp[i % 255] end exp end

Pre-computed EXP (antilog) table

LOG = begin log = Array(Int32).new(256, 0) x = 1 255.times do |i| log[x] = i x = x << 1 if x >= 256 x = x ^ 285 end end log end

Pre-computed LOG table

Class methods

encode(data : Array(UInt8), nsym : Int32) : Array(UInt8)

Generate error correction codewords using polynomial division

Source
generator_polynomial(nsym : Int32) : Array(Int32)

Generate generator polynomial g(x) = (x - α^0)(x - α^1)...(x - α^(n-1)) Returns coefficients from highest to lowest degree

Source
gf_mul(a : Int32, b : Int32) : Int32

Multiply two numbers in GF(256)

Source