mod on coefficients in R

42 views Asked by At

Various Homomorphic Encryption (FHE) schema that use Ring-Learning With Errors (RLWE) problems (and post-quantum, lattice-based cryptography in general) need to perform a polynomial modulo and then a scalar modulo on the coefficients.

I use the polynom package for the polynomials and the polynomial modulo.

Is there a way to perform the scalar modulo on the coefficients?

1

There are 1 answers

0
Bastiaan Quast On

There is no way in polynom. This is a simple workaround

# define a helper function
CoefMod <- function(x, k)
  polynom::polynomial(as.vector(x)%%k)

# create a polynomial
library(polynom)
polynomial = polynomial(c(5, 3, 6))

# apply the helper function (mod 5)
CoefMod(polynomial, 5)

I've create a small R package that also makes the function available:

install.packages('remotes')
remotes::install_github('bquast/HEtools')