-
Notifications
You must be signed in to change notification settings - Fork 1
/
Xenc_test.py
40 lines (31 loc) · 890 Bytes
/
Xenc_test.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
from Xencoding import *
def main():
if a == 0:
print("Error: for curves with a=0, call Xenc_test_0.py instead.")
exit(-1)
E = EllipticCurve([0, 0, 0, a, b])
x,y = E.random_point().xy()
z = F.random_element()
x = x*z
print("+++PARAMETERS+++")
print("CURVE:\t"+sys.argv[2])
print("a=\t"+str(hex(int(a))))
print("b=\t"+str(hex(int(b))))
print("\n+++INITIAL POINT+++")
print("x=\t"+str(hex(int(x/z))))
init_counters()
u,t = Xencode(x,z)
print("\n+++ENCODING+++")
print("u=\t"+str(hex(int(u))))
print("t=\t"+str(hex(int(t))))
print("Encoding Cost:")
print_counters()
init_counters()
x1,z1 = Xdecode(u,t)
print("\n+++DECODING+++")
print("x=\t"+str(hex(int(x1/z1))))
print("Decoding Cost:")
print_counters()
assert(x/z == x1/z1)
if __name__ == "__main__":
main()