forked from tprest/falcon.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.py
executable file
·45 lines (33 loc) · 915 Bytes
/
common.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""This file contains methods and objects which are reused through multiple files."""
"""q is the integer modulus which is used in Falcon."""
q = 12 * 1024 + 1
def split(f):
"""Split a polynomial f in two polynomials.
Args:
f: a polynomial
Format: coefficient
"""
n = len(f)
f0 = [f[2 * i + 0] for i in range(n // 2)]
f1 = [f[2 * i + 1] for i in range(n // 2)]
return [f0, f1]
def merge(f_list):
"""Merge two polynomials into a single polynomial f.
Args:
f_list: a list of polynomials
Format: coefficient
"""
f0, f1 = f_list
n = 2 * len(f0)
f = [0] * n
for i in range(n // 2):
f[2 * i + 0] = f0[i]
f[2 * i + 1] = f1[i]
return f
def sqnorm(v):
"""Compute the square euclidean norm of the vector v."""
res = 0
for elt in v:
for coef in elt:
res += coef ** 2
return res