def generate_key(params=Standard()): f = params.gen_fPoly() g = params.gen_gPoly() fp = invert_in_p(f, params.get_N()) fq = invert_in_2tor(f, params.get_N(), 8) h = fq * g return NTRUKey(params, h, f, g, fp, fq)
def test_full_run(self): x = Standard() f = x.gen_fPoly() g = x.gen_gPoly() fp = invert_in_p(f, x.get_N()) fq = invert_in_2tor(f, x.get_N(), 8) h = fq * g m = Polynomial( [-1, 0, 1, 1, 1, -1, 0, 0, 0, 0, -1, 1, 1, 0, 1, 1, 0, -1, 1], x.get_N()) r = x.gen_rPoly() e = (r.scale(x.get_p()) * h + m) % x.get_q() a = (f * e) % x.get_q() b = (fp * a) % x.get_p() self.assertEqual(b, m)
from parameters import Standard, TransportModelType, ReflectiveBoundaries parser = Standard() parser.setFEPolynomialDegree(4) parser.setSpatialMax([1, 2, 3, 4, 5]) parser.setSpatialDimension(2) parser.snapshot() parser.setTransportModel(TransportModelType.SAAF) parser.setOutputFilenameBase("howdy") parser.saveAs("temp/inputSamples")
def test_fiq(self): x = Standard() f = x.gen_fPoly() f_i = invert_in_2tor(f, x.get_N(), 8) self.assertTrue((f * f_i) % 256 == Polynomial([1], x.get_N()), 8)
def test_fip(self): x = Standard() f = x.gen_fPoly() f_i = invert_in_p(f, x.get_N()) self.assertTrue((f * f_i) % 3 == Polynomial([1], x.get_N()))
def test_fPoly(self): s = Standard() fp = s.gen_fPoly() self.assertEqual(fp._coeff.count(1), 216) self.assertEqual(fp._coeff.count(-1), 215)
def test_toString(self): s = Standard() p_string = str(s) self.assertEqual(p_string, "503,3,256,215,72,55")
def test_rPoly(self): s = Standard() fr = s.gen_rPoly() self.assertEqual(fr._coeff.count(1), 55) self.assertEqual(fr._coeff.count(-1), 55)
def test_gPoly(self): s = Standard() fg = s.gen_gPoly() self.assertEqual(fg._coeff.count(1), 72) self.assertEqual(fg._coeff.count(-1), 72)