-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathROS.sage.py
107 lines (77 loc) · 2.81 KB
/
ROS.sage.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# This file was *autogenerated* from the file ROS.sage
from sage.all_cmdline import * # import sage library
_sage_const_7 = Integer(7); _sage_const_103 = Integer(103); _sage_const_0 = Integer(0); _sage_const_16 = Integer(16); _sage_const_1 = Integer(1); _sage_const_2 = Integer(2)
import hashlib
import struct
from datetime import datetime
import math
import json
l = _sage_const_7
lambdaParameter = _sage_const_103
R = GF(lambdaParameter)['x0, x1, x2, x3, x4, x5, x6']; (x0, x1, x2, x3, x4, x5, x6,) = R._first_ngens(7)
def coeffs(p):
return [p.coefficient(x0),p.coefficient(x1),p.coefficient(x2),p.coefficient(x3),p.coefficient(x4),p.coefficient(x5),p.coefficient(x6),]
def encode(p):
p = coeffs(p)
result = b""
for i in range(_sage_const_0 , len(p)):
result = result + struct.pack('q', int(p[i]))
return result
def hash(x, aux = 'aux11'):
return R(int(hashlib.sha224(bytes(str(aux), "ascii")+bytes(str(x), "ascii")).hexdigest(),_sage_const_16 ))
X = [x0, x1, x2, x3, x4, x5, x6]
p0 = x0
p1 = x1
p2 = x2
p3 = x3
p4 = x4
p5 = x5
p6 = x6
# C = [hash(encode(roh0)), hash(encode(roh1)), hash(encode(p2)), hash(encode(p3)), hash(encode(p4)),hash(encode(p5)),hash(encode(p6))]
caux = {
"p0": [hash(encode(p0), _sage_const_0 ), hash(encode(p0), _sage_const_1 )],
"p1": [hash(encode(p1), _sage_const_0 ), hash(encode(p1), _sage_const_1 )],
"p2": [hash(encode(p2), _sage_const_0 ), hash(encode(p2), _sage_const_1 )],
"p3": [hash(encode(p3), _sage_const_0 ), hash(encode(p3), _sage_const_1 )],
"p4": [hash(encode(p4), _sage_const_0 ), hash(encode(p4), _sage_const_1 )],
"p5": [hash(encode(p5), _sage_const_0 ), hash(encode(p5), _sage_const_1 )],
"p6": [hash(encode(p6), _sage_const_0 ), hash(encode(p6), _sage_const_1 )],
}
p7 = _sage_const_0
print(caux)
for i in range(_sage_const_0 ,l):
a = X[i]-caux["p"+str(i)][_sage_const_0 ]
b = caux["p"+str(i)][_sage_const_1 ] - caux["p"+str(i)][_sage_const_0 ]
p7 += _sage_const_2 **i * (a / b)
print(p7)
hashp7 = int(hash(encode(p7)))
print(hashp7)
b = f'{hashp7:07b}'
print(b)
B = []
for i in range(_sage_const_1 , l+_sage_const_1 ):
B.append(b[i-_sage_const_1 :i])
B.reverse()
C = []
for i in range(_sage_const_0 ,l):
C.append(caux['p'+str(i)][int(B[i])])
print(B)
print(caux)
print(C)
for i in range(_sage_const_0 ,l):
print('p'+str(i)+" with varibal list above evaluates to: "+str(int(X[i](C)))+' and hashes to: '+str(int(hash(encode(X[i]), B[i]))))
print("p7 with varibal list above evaluates to: "+str(int(p7(C)))+' and hashes to: '+str(int(hash(encode(p7)))))
# for i in range(0, l):
# hashp7 = hash(encode(p7), '')
# print(hashp7)
# b = []
# a = 0
# for i in range(0,l):
# power = 2^i
# intager = int(str(C[i])[:],10)
# a += (power*intager)
# b.append((power*intager) % lambdaParameter)
# print(b)
# print(a % lambdaParameter)
# # newC = C[:]
# print(evaluate(p7, b))