MCPcopy Create free account
hub / github.com/TactilityProject/Tactility / ReedSolomonGenerator

Method ReedSolomonGenerator

Libraries/QRCode/tests/QrCode.cpp:567–589  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

565
566
567qrcodegen::QrCode::ReedSolomonGenerator::ReedSolomonGenerator(int degree) :
568 coefficients() {
569 if (degree < 1 || degree > 255)
570 throw "Degree out of range";
571
572 // Start with the monomial x^0
573 coefficients.resize(degree);
574 coefficients.at(degree - 1) = 1;
575
576 // Compute the product polynomial (x - r^0) * (x - r^1) * (x - r^2) * ... * (x - r^{degree-1}),
577 // drop the highest term, and store the rest of the coefficients in order of descending powers.
578 // Note that r = 0x02, which is a generator element of this field GF(2^8/0x11D).
579 int root = 1;
580 for (int i = 0; i < degree; i++) {
581 // Multiply the current product by (x - r^i)
582 for (size_t j = 0; j < coefficients.size(); j++) {
583 coefficients.at(j) = multiply(coefficients.at(j), static_cast<uint8_t>(root));
584 if (j + 1 < coefficients.size())
585 coefficients.at(j) ^= coefficients.at(j + 1);
586 }
587 root = (root << 1) ^ ((root >> 7) * 0x11D); // Multiply by 0x02 mod GF(2^8/0x11D)
588 }
589}
590
591
592std::vector<uint8_t> qrcodegen::QrCode::ReedSolomonGenerator::getRemainder(const std::vector<uint8_t> &data) const {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected