From b7c9ccfff91c750b0f8cf686de40cc784063c421 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Sun, 14 Jul 2019 17:11:28 +0000 Subject: [PATCH] Simplified and clarified a few bits of code, without changing behavior. --- cpp/QrCode.cpp | 4 ++-- java/src/main/java/io/nayuki/qrcodegen/QrCode.java | 2 +- python/qrcodegen.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cpp/QrCode.cpp b/cpp/QrCode.cpp index 56a3e3f..4630752 100644 --- a/cpp/QrCode.cpp +++ b/cpp/QrCode.cpp @@ -569,8 +569,8 @@ vector QrCode::reedSolomonComputeRemainder(const vector &data, uint8_t factor = b ^ result.at(0); result.erase(result.begin()); result.push_back(0); - for (size_t j = 0; j < result.size(); j++) - result.at(j) ^= reedSolomonMultiply(divisor.at(j), factor); + for (size_t i = 0; i < result.size(); i++) + result.at(i) ^= reedSolomonMultiply(divisor.at(i), factor); } return result; } diff --git a/java/src/main/java/io/nayuki/qrcodegen/QrCode.java b/java/src/main/java/io/nayuki/qrcodegen/QrCode.java index b82ee1f..f7d8ab7 100644 --- a/java/src/main/java/io/nayuki/qrcodegen/QrCode.java +++ b/java/src/main/java/io/nayuki/qrcodegen/QrCode.java @@ -768,7 +768,7 @@ public final class QrCode { // Returns the product of the two given field elements modulo GF(2^8/0x11D). The arguments and result // are unsigned 8-bit integers. This could be implemented as a lookup table of 256*256 entries of uint8. private static int reedSolomonMultiply(int x, int y) { - assert x >>> 8 == 0 && y >>> 8 == 0; + assert x >> 8 == 0 && y >> 8 == 0; // Russian peasant multiplication int z = 0; for (int i = 7; i >= 0; i--) { diff --git a/python/qrcodegen.py b/python/qrcodegen.py index 0b567b2..6ada1aa 100644 --- a/python/qrcodegen.py +++ b/python/qrcodegen.py @@ -567,7 +567,7 @@ class QrCode(object): def _reed_solomon_compute_divisor(degree): """Returns a Reed-Solomon ECC generator polynomial for the given degree. This could be implemented as a lookup table over all possible parameter values, instead of as an algorithm.""" - if degree < 1 or degree > 255: + if not (1 <= degree <= 255): raise ValueError("Degree out of range") # Polynomial coefficients are stored from highest to lowest power, excluding the leading term which is always 1. # For example the polynomial x^3 + 255x^2 + 8x + 93 is stored as the uint8 array [255, 8, 93].