-
Notifications
You must be signed in to change notification settings - Fork 143
/
Copy pathPOLYNONCE.py
53 lines (46 loc) · 1.66 KB
/
POLYNONCE.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
with open("SignatureRSZ.csv") as myfile:
#listfile="\n".join(line.rstrip()[+3:-70] for line in myfile)
listfile="\n".join(f'{line.rstrip()[+5:-5]}' for line in myfile)
f = open("NoncesHEX.txt", 'w')
f.write("" + listfile + "" + "\n")
f.close()
N = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141
def rrr(i):
tmpstr = hex(i)
hexstr = tmpstr.replace('0x','').replace('L','').replace(' ','').zfill(64)
return hexstr
def extended_gcd(aa, bb):
lastremainder, remainder = abs(aa), abs(bb)
x, lastx, y, lasty = 0, 1, 1, 0
while remainder:
lastremainder, (quotient, remainder) = remainder, divmod(lastremainder, remainder)
x, lastx = lastx - quotient*x, x
y, lasty = lasty - quotient*y, y
return lastremainder, lastx * (-1 if aa < 0 else 1), lasty * (-1 if bb < 0 else 1)
def modinv(a, m):
g, x, y = extended_gcd(a, m)
return x % m
def load(file):
signatures=[]
import csv
with open(file,'r') as csv_file:
csv_reader = csv.reader(csv_file,delimiter=",")
line = 0
for row in csv_reader:
r=int(row[0],16)
s=int(row[1],16)
z=int(row[2],16)
t=tuple([r,s,z])
signatures.append(t)
line+=1
return signatures
signatures = load("NoncesHEX.txt")
nn = len(signatures)
for a in range(0,nn):
mm = signatures[a][2]
rr = signatures[a][0]
ss = signatures[a][1]
PrivKey = 0x00db251a1ab7cfa7679dfe61271d0af4bb9c68595178cf4c9237478eab2dba1d
zrx = ((mm + rr * PrivKey) % N)
key = ((zrx * modinv(ss,N)) % N)
print("POLYNONCE >> "+rrr(key)+"")