Simplified and clarified a few bits of code, without changing behavior.

pull/62/head
Project Nayuki 5 years ago
parent ee5e4ca121
commit b7c9ccfff9

@ -569,8 +569,8 @@ vector<uint8_t> QrCode::reedSolomonComputeRemainder(const vector<uint8_t> &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;
}

@ -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--) {

@ -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].

Loading…
Cancel
Save