def encrypt(self, m, r=None): if self.h is None: raise ValueError("Public key not set.") if r is None: r = uniform_sample_T(self.N, self.d, self.d) blind = Polynomial(self.p).__mul__(self.h.__mul__(r, self.q), self.q) return (blind.__add__(m, self.q)).__mod__(self.poly_mod, self.q)
def cycle_index_sym_helper(n: int, memo: Dict[int, Polynomial]) -> Polynomial: """ A helper for the dp-style evaluation of the cycle index. The recurrence is given in: https://en.wikipedia.org/wiki/Cycle_index#Symmetric_group_Sn """ if n in memo: return memo[n] ans = Polynomial([Monomial({}, Fraction(0, 1))]) for t in range(1, n + 1): ans = ans.__add__( Polynomial([Monomial({t: 1}, Fraction(1, 1))]) * cycle_index_sym_helper(n - t, memo)) ans *= Fraction(1, n) memo[n] = ans return memo[n]