-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbinary_bsgs_v1.py
143 lines (101 loc) · 3.46 KB
/
binary_bsgs_v1.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#@author: iceland, modified by @mcdouglasx
import secp256k1 as ice
import bit
import time
import random
import os
from fastecdsa import curve
from fastecdsa.point import Point
from bitstring import BitArray
import numpy as np
#Pk: 33185509 puzzle #30
Target = '03057fbea3a2623382628dde556b2a0698e32428d3cd225f3bd034dca82dd7455a'
start= 0
end= 33554431
m = 2000000 # Keys number in Binary Babystep
Add = 1
Add_pub= ice.scalar_multiplication(Add)
Cm= 64
public_key = ice.pub2upub(Target).hex()
bs_file = 'baby_steps__binary.bin'
def Pub2Point(public_key):
x = int(public_key[2:66],16)
if len(public_key) < 70:
y = bit.format.x_to_y(x, int(public_key[:2],16)%2)
else:
y = int(public_key[66:],16)
return Point(x, y, curve=curve.secp256k1)
Q = Pub2Point(public_key)
G = curve.secp256k1.G
#find baby step file
valid = os.path.isfile(bs_file)
if valid == True:
print('\nFound the Baby Steps Table file: '+bs_file+'. Will be used directly')
file = bytes(np.fromfile(bs_file))
baby_steps= BitArray(file)
if valid == False:
print('\nNot Found '+bs_file+'. you must Create This File Now.' )
k1 = random.randint(start, end)
#k1 =1
k2 = k1 + m*m
print('Checking {0} keys from {1}'.format(m*m, hex(k1)))
# m = math.floor(math.sqrt(k2-k1))
# start time
st = time.time()
k1G = k1 * G
mG = m * G
#find key
def findkey(onePoint):
S = onePoint - k1G
if S == Point.IDENTITY_ELEMENT: return k1 # Point at Infinity
found = False
step = 0
while found is False and step<(1+k2-k1):
Sx_0= ice.pub2upub("04"+(str(hex(int(str(S.x))))[2:])+(str(hex(int(str(S.y))))[2:]))
Sx_1= ice.point_sequential_increment(Cm, Sx_0)
binary = ''
for t in range (Cm):
h= (Sx_1[t*65:t*65+65]).hex()
hc= int(h[2:], 16)
if str(hc).endswith(('0','2','4','6','8')):
A="0"
binary+= ''.join(str(A))
if str(hc).endswith(('1','3','5','7','9')):
A="1"
binary+= ''.join(str(A))
b = BitArray(bin=binary)
c = bytes(b)
Sw =c
if b in baby_steps:
#
s = c
f = BitArray(baby_steps)
inx = f.find(s)
inx_1=str(inx).replace(",", "")
inx_0=str(inx_1).replace("(", "")
inx_2=str(inx_0).replace(")", "")
b = int(inx_2)
found = True
break
else:
# Giant step
S = S - mG
step = step + m
if found == True:
#print("k1:",k1)
#print("step:",step)
#print("b:",b)
final_key = (k1 + step + b + 1)-1
else:
final_key = -1
return final_key
final_key = findkey(Q)
if final_key >0:
print("BSGS FOUND PrivateKey :",str(final_key))
data= open("win.txt", "a")
data.write("private key = "+str(final_key)+"\n")
data.write(str("Time Spent : {0:.2f} seconds".format(time.time()-st))+ "\n")
data.close()
else:
print('PrivateKey Not Found')
print(str("Time Spent : {0:.2f} seconds".format(time.time()-st)))