R/polynomialGenerator.R

Defines functions polynomialGenerator

Documented in polynomialGenerator

#' Function to generate polynomial
#'
#' @param ECcount error correction code word count
#'
#' @return polynomail to generate Error correction code
#'

polynomialGenerator <- function(ECcount) { #nolint
  logTable <- create_log_table()

  poly <- c(0, 0)
  for (p in 2:ECcount) {
    tempPoly <- rep(0L, p)
    for (i in seq_len(p)) {
      if (i == p) {
        #(i 2)
        tempPoly[i]  <- lookup_log(logTable, ((poly[i] + p - 1L) %% 255))
      } else {
        #(i 2)(i+1 1)
        tempPoly[i] <- bitwXor(
          lookup_log(logTable, poly[i + 1]),
          lookup_log(logTable, (poly[i] + p - 1L) %% 255)
        )
      }
    }
    tempPoly[tempPoly > 255] <- tempPoly[tempPoly > 255] %% 255
    poly <- c(0, lookup_exponent(logTable, tempPoly))
    poly <- poly[poly != 255]
  }
  return(poly)
}

Try the qrcode package in your browser

Any scripts or data that you put into this service are public.

qrcode documentation built on July 2, 2021, 5:06 p.m.