From 0408ab8857cd13fddf4ea84f722558dbb1fdef17 Mon Sep 17 00:00:00 2001 From: Steven Charles Davis Date: Fri, 17 Jan 2014 20:50:04 -0600 Subject: [PATCH] Issue #2 - provisional resolution to RFC3339 date encoding Fixes an issue where a GF(256) remainder used for reed-solomon error correction bytes is a codeword short on return from division. This may not be the final resolution to the wider issue. --- src/qrcode_reedsolomon.erl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/qrcode_reedsolomon.erl b/src/qrcode_reedsolomon.erl index 62edfaf..8a4cda8 100644 --- a/src/qrcode_reedsolomon.erl +++ b/src/qrcode_reedsolomon.erl @@ -25,9 +25,14 @@ encode(Bin, Degree) when Degree > 0 -> Data = binary_to_list(Bin), Coeffs = gf256:monomial_product(Field, Data, 1, Degree), {_Quotient, Remainder} = gf256:divide(Field, Coeffs, Generator), - ErrorCorrectionBytes = list_to_binary(Remainder), + Remainder0 = zero_pad(Degree, Remainder), + ErrorCorrectionBytes = list_to_binary(Remainder0), <>. +zero_pad(Length, R) when length(R) < Length -> + zero_pad(Length, [0|R]); +zero_pad(_, R) -> + R. %% bch_code(Byte, Poly) -> MSB = msb(Poly),