Simplified a few lines of code in constructor of ReedSolomonGenerator in all language versions.

pull/11/head
Project Nayuki 8 years ago
parent 5d1069a93c
commit 50c1a6b8af

@ -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);
}
}

@ -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<uint8_t>(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);
}
}

@ -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);
}
}

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

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

Loading…
Cancel
Save