DILSHAD737 commited on
Commit
e641c7a
Β·
1 Parent(s): 88e28f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -65
app.py CHANGED
@@ -11,7 +11,6 @@ except Exception:
11
  import gradio as gr
12
  import hashlib, hmac, os, time, math, random, gc
13
  from itertools import permutations, combinations
14
- from multiprocessing import Pool
15
  from mnemonic import Mnemonic
16
  import coincurve
17
  from eth_utils import keccak, to_checksum_address
@@ -21,8 +20,6 @@ import spaces
21
  def _noop():
22
  return "ok"
23
 
24
- # ============================================================
25
- # Global state
26
  # ============================================================
27
  _MNEMONIC = None
28
  def _get_mnemonic():
@@ -114,39 +111,6 @@ def generate_phrases_for_words(wordlist, mode):
114
  for combo in combinations(wordlist, r):
115
  yield " ".join(combo)
116
 
117
- # ---------- Worker ----------
118
- _KNOWN = None
119
- def init_worker(known):
120
- global _KNOWN
121
- _KNOWN = known
122
- _get_mnemonic()
123
-
124
- def process_batch(args):
125
- batch, passphrase, address_index, hd, checksum = args
126
- hits = []
127
- known = _KNOWN
128
- for phrase in batch:
129
- if checksum and not is_valid_bip39(phrase):
130
- continue
131
- try:
132
- seed = phrase_to_seed(phrase, passphrase)
133
- priv = seed_to_privkey_hd(seed, address_index) if hd else seed[:32]
134
- pub = coincurve.PrivateKey(priv).public_key.format(compressed=False)[1:]
135
- addr = to_checksum_address(keccak(pub)[-20:])
136
- except Exception:
137
- continue
138
- if normalize(addr) in known:
139
- hits.append((phrase, priv.hex(), addr))
140
- return hits
141
-
142
- def batch_generator_for_words(wordlist, mode, batch_size):
143
- batch = []
144
- for phrase in generate_phrases_for_words(wordlist, mode):
145
- batch.append(phrase)
146
- if len(batch) >= batch_size:
147
- yield batch
148
- batch = []
149
-
150
  # ============================================================
151
  # Gradio functions
152
  # ============================================================
@@ -157,8 +121,8 @@ def generate_random_phrase():
157
 
158
 
159
  def run_scan_sync(phrase, addresses_file, phrase_mode, address_index,
160
- passphrase, workers, batch_size):
161
- """Synchronous scan β€” Gradio ke liye fast."""
162
  if not os.path.exists(addresses_file):
163
  return f"❌ File nahi mili: {addresses_file}", ""
164
 
@@ -166,8 +130,6 @@ def run_scan_sync(phrase, addresses_file, phrase_mode, address_index,
166
  if len(words) != 12:
167
  return f"❌ Phrase 12 words ki nahi hai ({len(words)} words)", ""
168
 
169
- workers = int(workers)
170
- batch_size = int(batch_size)
171
  address_index = int(address_index)
172
 
173
  try:
@@ -182,7 +144,7 @@ def run_scan_sync(phrase, addresses_file, phrase_mode, address_index,
182
 
183
  log_lines = [
184
  f"βœ… Loaded {len(known):,} addresses",
185
- f"πŸ”§ Mode: {phrase_mode} | Workers: {workers} | Batch: {batch_size}",
186
  f"πŸ”‘ Address index: {address_index} | Passphrase: {'(set)' if passphrase else '(empty)'}",
187
  f"πŸ“ Phrase: {phrase}",
188
  f"πŸ”’ Total combinations: {total:,}",
@@ -192,21 +154,20 @@ def run_scan_sync(phrase, addresses_file, phrase_mode, address_index,
192
  matches = []
193
  start = time.time()
194
 
195
- with Pool(processes=workers,
196
- initializer=init_worker,
197
- initargs=(known,)) as pool:
198
- for hits in pool.imap_unordered(
199
- process_batch,
200
- (
201
- (batch, passphrase, address_index, True, True)
202
- for batch in batch_generator_for_words(words, phrase_mode, batch_size)
203
- ),
204
- chunksize=4,
205
- ):
206
- for phrase_str, key_hex, addr in hits:
207
- match_line = f"πŸŽ‰ MATCH!\nPhrase: {phrase_str}\nKey: {key_hex}\nAddr: {addr}\n"
208
- log_lines.append(match_line)
209
- matches.append((phrase_str, key_hex, addr))
210
 
211
  elapsed = time.time() - start
212
  log_lines.append(f"=== DONE ===")
@@ -255,14 +216,6 @@ with gr.Blocks(title="Phrase Scanner") as demo:
255
  value="",
256
  type="password",
257
  )
258
- workers = gr.Slider(
259
- label="Workers",
260
- minimum=1, maximum=32, value=8, step=1,
261
- )
262
- batch_size = gr.Slider(
263
- label="Batch Size",
264
- minimum=100, maximum=10000, value=5000, step=100,
265
- )
266
  run_btn = gr.Button("πŸš€ Scan Shuru Karein", variant="primary")
267
 
268
  with gr.Column(scale=2):
@@ -285,7 +238,7 @@ with gr.Blocks(title="Phrase Scanner") as demo:
285
  run_btn.click(
286
  fn=run_scan_sync,
287
  inputs=[phrase, addresses_file, phrase_mode, address_index,
288
- passphrase, workers, batch_size],
289
  outputs=[log_output, matches_output],
290
  )
291
 
 
11
  import gradio as gr
12
  import hashlib, hmac, os, time, math, random, gc
13
  from itertools import permutations, combinations
 
14
  from mnemonic import Mnemonic
15
  import coincurve
16
  from eth_utils import keccak, to_checksum_address
 
20
  def _noop():
21
  return "ok"
22
 
 
 
23
  # ============================================================
24
  _MNEMONIC = None
25
  def _get_mnemonic():
 
111
  for combo in combinations(wordlist, r):
112
  yield " ".join(combo)
113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  # ============================================================
115
  # Gradio functions
116
  # ============================================================
 
121
 
122
 
123
  def run_scan_sync(phrase, addresses_file, phrase_mode, address_index,
124
+ passphrase):
125
+ """Bina Pool ke, single process scan β€” sirf 144 combos."""
126
  if not os.path.exists(addresses_file):
127
  return f"❌ File nahi mili: {addresses_file}", ""
128
 
 
130
  if len(words) != 12:
131
  return f"❌ Phrase 12 words ki nahi hai ({len(words)} words)", ""
132
 
 
 
133
  address_index = int(address_index)
134
 
135
  try:
 
144
 
145
  log_lines = [
146
  f"βœ… Loaded {len(known):,} addresses",
147
+ f"πŸ”§ Mode: {phrase_mode}",
148
  f"πŸ”‘ Address index: {address_index} | Passphrase: {'(set)' if passphrase else '(empty)'}",
149
  f"πŸ“ Phrase: {phrase}",
150
  f"πŸ”’ Total combinations: {total:,}",
 
154
  matches = []
155
  start = time.time()
156
 
157
+ for phrase_str in generate_phrases_for_words(words, phrase_mode):
158
+ if not is_valid_bip39(phrase_str):
159
+ continue
160
+ try:
161
+ seed = phrase_to_seed(phrase_str, passphrase)
162
+ priv = seed_to_privkey_hd(seed, address_index)
163
+ pub = coincurve.PrivateKey(priv).public_key.format(compressed=False)[1:]
164
+ addr = to_checksum_address(keccak(pub)[-20:])
165
+ except Exception:
166
+ continue
167
+ if normalize(addr) in known:
168
+ match_line = f"πŸŽ‰ MATCH!\nPhrase: {phrase_str}\nKey: {priv.hex()}\nAddr: {addr}\n"
169
+ log_lines.append(match_line)
170
+ matches.append((phrase_str, priv.hex(), addr))
 
171
 
172
  elapsed = time.time() - start
173
  log_lines.append(f"=== DONE ===")
 
216
  value="",
217
  type="password",
218
  )
 
 
 
 
 
 
 
 
219
  run_btn = gr.Button("πŸš€ Scan Shuru Karein", variant="primary")
220
 
221
  with gr.Column(scale=2):
 
238
  run_btn.click(
239
  fn=run_scan_sync,
240
  inputs=[phrase, addresses_file, phrase_mode, address_index,
241
+ passphrase],
242
  outputs=[log_output, matches_output],
243
  )
244