Esempio n. 1
0
	def test_simple_convolution(self):
		mod = 673
		root = 326
		vec0 = ntt.transform([4, 1, 4, 2, 1, 3, 5, 6], root, mod)
		vec1 = ntt.transform([6, 1, 8, 0, 3, 3, 9, 8], root, mod)
		vec2 = [(x * y % mod) for (x, y) in zip(vec0, vec1)]
		actual = ntt.inverse_transform(vec2, root, mod)
		expect = [123, 120, 106, 92, 139, 144, 140, 124]
		self.assertEqual(expect, actual)
Esempio n. 2
0
	def test_transform_linearity_randomly(self):
		TRIALS = 100
		for _ in range(TRIALS):
			veclen = random.randrange(100) + 1
			maxval = random.randrange(100) + 1
			vec0 = [random.randrange(maxval + 1) for _ in range(veclen)]
			vec1 = [random.randrange(maxval + 1) for _ in range(veclen)]
			out0, root, mod = ntt.find_params_and_transform(vec0, maxval + 1)
			out1 = ntt.transform(vec1, root, mod)
			out01 = [(x + y) % mod for (x, y) in zip(out0, out1)]
			vec2 = [(x + y) % mod for (x, y) in zip(vec0, vec1)]
			out2 = ntt.transform(vec2, root, mod)
			self.assertEqual(out2, out01)
Esempio n. 3
0
	def test_forward_transform(self):
		actual = ntt.transform([6, 0, 10, 7, 2], 3, 11)
		expect = [3, 7, 0, 5, 4]
		self.assertEqual(expect, actual)