diff --git a/c/qrcodegen.c b/c/qrcodegen.c index a1466d0..45373e8 100644 --- a/c/qrcodegen.c +++ b/c/qrcodegen.c @@ -433,15 +433,15 @@ testable void calcReedSolomonGenerator(int degree, uint8_t result[]) { // Compute the product polynomial (x - r^0) * (x - r^1) * (x - r^2) * ... * (x - r^{degree-1}), // drop the highest term, and store the rest of the coefficients in order of descending powers. // Note that r = 0x02, which is a generator element of this field GF(2^8/0x11D). - int root = 1; + uint8_t root = 1; for (int i = 0; i < degree; i++) { // Multiply the current product by (x - r^i) for (int j = 0; j < degree; j++) { - result[j] = finiteFieldMultiply(result[j], (uint8_t)root); + result[j] = finiteFieldMultiply(result[j], root); if (j + 1 < degree) result[j] ^= result[j + 1]; } - root = (root << 1) ^ ((root >> 7) * 0x11D); // Multiply by 0x02 mod GF(2^8/0x11D) + root = finiteFieldMultiply(root, 0x02); } } diff --git a/cpp/QrCode.cpp b/cpp/QrCode.cpp index 8448c14..579c30f 100644 --- a/cpp/QrCode.cpp +++ b/cpp/QrCode.cpp @@ -580,15 +580,15 @@ QrCode::ReedSolomonGenerator::ReedSolomonGenerator(int degree) : // Compute the product polynomial (x - r^0) * (x - r^1) * (x - r^2) * ... * (x - r^{degree-1}), // drop the highest term, and store the rest of the coefficients in order of descending powers. // Note that r = 0x02, which is a generator element of this field GF(2^8/0x11D). - int root = 1; + uint8_t root = 1; for (int i = 0; i < degree; i++) { // Multiply the current product by (x - r^i) for (size_t j = 0; j < coefficients.size(); j++) { - coefficients.at(j) = multiply(coefficients.at(j), static_cast(root)); + coefficients.at(j) = multiply(coefficients.at(j), root); if (j + 1 < coefficients.size()) coefficients.at(j) ^= coefficients.at(j + 1); } - root = (root << 1) ^ ((root >> 7) * 0x11D); // Multiply by 0x02 mod GF(2^8/0x11D) + root = multiply(root, 0x02); } } diff --git a/java/io/nayuki/qrcodegen/QrCode.java b/java/io/nayuki/qrcodegen/QrCode.java index 27befd5..0b8646c 100644 --- a/java/io/nayuki/qrcodegen/QrCode.java +++ b/java/io/nayuki/qrcodegen/QrCode.java @@ -811,7 +811,7 @@ public final class QrCode { if (j + 1 < coefficients.length) coefficients[j] ^= coefficients[j + 1]; } - root = (root << 1) ^ ((root >>> 7) * 0x11D); // Multiply by 0x02 mod GF(2^8/0x11D) + root = multiply(root, 0x02); } } diff --git a/javascript/qrcodegen.js b/javascript/qrcodegen.js index 405432e..09b7ad0 100644 --- a/javascript/qrcodegen.js +++ b/javascript/qrcodegen.js @@ -932,7 +932,7 @@ var qrcodegen = new function() { if (j + 1 < coefficients.length) coefficients[j] ^= coefficients[j + 1]; } - root = (root << 1) ^ ((root >>> 7) * 0x11D); // Multiply by 0x02 mod GF(2^8/0x11D) + root = ReedSolomonGenerator.multiply(root, 0x02); } // Computes and returns the Reed-Solomon error correction codewords for the given sequence of data codewords. diff --git a/python/qrcodegen.py b/python/qrcodegen.py index 7edb2b3..4a0c59a 100644 --- a/python/qrcodegen.py +++ b/python/qrcodegen.py @@ -779,7 +779,7 @@ class _ReedSolomonGenerator(object): self.coefficients[j] = _ReedSolomonGenerator.multiply(self.coefficients[j], root) if j + 1 < degree: self.coefficients[j] ^= self.coefficients[j + 1] - root = (root << 1) ^ ((root >> 7) * 0x11D) # Multiply by 0x02 mod GF(2^8/0x11D) + root = _ReedSolomonGenerator.multiply(root, 0x02) def get_remainder(self, data):