-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.sage
49 lines (32 loc) · 869 Bytes
/
utils.sage
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
46
47
48
49
from sage.all import *
def random_curve_values(E, n):
return [E.random_element() for i in range(n)]
def random_field_values(F, n):
return [F.random_element() for i in range(n)]
def inner_product_vec(a, b):
assert len(a) == len(b)
res = 0
for i in range(len(a)):
res += a[i] * b[i]
return res
def inner_product_point(a, b):
assert len(a) == len(b)
c = 0
for i in range(len(a)):
c = c + (a[i]) * b[i]
return c
def scalar_mul_field(f, v, n):
res = [None] * n
for i in range(n):
res[i] = f[i] * v
return res
def scalar_mul_point(g, v, n):
r = [None] * len(g)
for i in range(len(g)):
r[i] = g[i] * (v)
return r
def add_vectors(a, b):
assert len(a) == len(b)
return [x + y for x, y in zip(a, b)]
def powers_of(x, n):
return [x ^ i for i in range(n)]