DILSHAD737 commited on
Commit
551ac1f
Β·
1 Parent(s): 5786039

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -74
app.py CHANGED
@@ -76,19 +76,8 @@ def phrase_to_seed(phrase, passphrase=""):
76
  return _seed_fn(phrase, passphrase)
77
  return _get_mnemonic().to_seed(phrase, passphrase=passphrase)
78
 
79
- # ---------- Address Cache ----------
80
- _ADDRESS_CACHE = {}
81
-
82
- def load_addresses_cached(path):
83
- if path in _ADDRESS_CACHE:
84
- cached_mtime, cached_set = _ADDRESS_CACHE[path]
85
- try:
86
- current_mtime = os.path.getmtime(path)
87
- if current_mtime == cached_mtime:
88
- return cached_set
89
- except OSError:
90
- pass
91
-
92
  s = set()
93
  with open(path, "r", encoding="utf-8") as f:
94
  for line in f:
@@ -97,12 +86,6 @@ def load_addresses_cached(path):
97
  a = a[2:]
98
  if a and len(a) == 40:
99
  s.add(a)
100
-
101
- try:
102
- mtime = os.path.getmtime(path)
103
- except OSError:
104
- mtime = 0
105
- _ADDRESS_CACHE[path] = (mtime, s)
106
  return s
107
 
108
  def normalize(addr):
@@ -133,21 +116,20 @@ def generate_phrases_for_words(wordlist, mode):
133
  # ============================================================
134
 
135
  def generate_random_phrase():
136
- return _get_mnemonic().generate(strength=128)
 
 
137
 
138
 
139
- def run_multi_phrase_scan(num_phrases, addresses_file, phrase_mode,
140
- start_index, end_index, passphrase):
141
- """
142
- User se poocha gaya number of phrases generate karta hai,
143
- phir ek ek karke scan karta hai.
144
- """
145
  if not os.path.exists(addresses_file):
146
  return f"❌ File nahi mili: {addresses_file}", ""
147
 
148
- num_phrases = int(num_phrases)
149
- if num_phrases < 1:
150
- return "❌ Kam az kam 1 phrase chahiye", ""
151
 
152
  start_index = int(start_index)
153
  end_index = int(end_index)
@@ -155,60 +137,52 @@ def run_multi_phrase_scan(num_phrases, addresses_file, phrase_mode,
155
  return "❌ Start index end index se bada nahi ho sakta", ""
156
 
157
  try:
158
- known = load_addresses_cached(addresses_file)
159
  except Exception as e:
160
  return f"❌ Addresses load fail: {e}", ""
161
 
162
  if not known:
163
  return "❌ Koi valid address file mein nahi mila", ""
164
 
165
- # Generate phrases
166
- mnemo = _get_mnemonic()
167
- phrases = [mnemo.generate(strength=128) for _ in range(num_phrases)]
168
 
169
  log_lines = [
170
- f"βœ… Loaded {len(known):,} addresses (cached)",
171
  f"πŸ”§ Mode: {phrase_mode}",
172
- f"πŸ”‘ Index range: {start_index}–{end_index}",
173
- f"πŸ“ Phrases to check: {num_phrases}",
 
 
174
  "",
175
- "Generated phrases:",
176
  ]
177
- for i, p in enumerate(phrases, 1):
178
- log_lines.append(f" {i}. {p}")
179
- log_lines.append("")
180
 
181
  matches = []
182
  start = time.time()
183
 
184
- for p_idx, phrase in enumerate(phrases, 1):
185
- log_lines.append(f"πŸ” [{p_idx}/{num_phrases}] Checking: {phrase}")
186
- words = phrase.strip().split()
187
- if len(words) != 12:
188
- log_lines.append(f" ⚠️ Skipped (not 12 words)")
189
- continue
190
-
191
- for idx in range(start_index, end_index + 1):
192
- for phrase_str in generate_phrases_for_words(words, phrase_mode):
193
- if not is_valid_bip39(phrase_str):
194
- continue
195
- try:
196
- seed = phrase_to_seed(phrase_str, passphrase)
197
- priv = seed_to_privkey_hd(seed, idx)
198
- pub = coincurve.PrivateKey(priv).public_key.format(compressed=False)[1:]
199
- addr = to_checksum_address(keccak(pub)[-20:])
200
- except Exception:
201
- continue
202
- if normalize(addr) in known:
203
- match_line = (
204
- f"πŸŽ‰ MATCH!\n"
205
- f"Phrase: {phrase_str}\n"
206
- f"Index: {idx}\n"
207
- f"Key: {priv.hex()}\n"
208
- f"Addr: {addr}\n"
209
- )
210
- log_lines.append(match_line)
211
- matches.append((phrase_str, idx, priv.hex(), addr))
212
 
213
  elapsed = time.time() - start
214
  log_lines.append(f"=== DONE ===")
@@ -227,15 +201,18 @@ def run_multi_phrase_scan(num_phrases, addresses_file, phrase_mode,
227
  # ============================================================
228
  with gr.Blocks(title="Phrase Scanner") as demo:
229
  gr.Markdown("# πŸ” Phrase Scanner")
230
- gr.Markdown("Kitni random phrases check karni hain? Phir index range ke saath scan karein.")
231
 
232
  with gr.Row():
233
  with gr.Column(scale=1):
234
  gr.Markdown("### Settings")
235
- num_phrases = gr.Number(
236
- label="Kitni Random Phrases Check Karein?",
237
- value=10, precision=0, minimum=1,
 
 
238
  )
 
239
  addresses_file = gr.Textbox(
240
  label="Addresses File",
241
  value="12730802_addresses.csv",
@@ -277,9 +254,10 @@ with gr.Blocks(title="Phrase Scanner") as demo:
277
  autoscroll=True,
278
  )
279
 
 
280
  run_btn.click(
281
- fn=run_multi_phrase_scan,
282
- inputs=[num_phrases, addresses_file, phrase_mode,
283
  start_index, end_index, passphrase],
284
  outputs=[log_output, matches_output],
285
  )
 
76
  return _seed_fn(phrase, passphrase)
77
  return _get_mnemonic().to_seed(phrase, passphrase=passphrase)
78
 
79
+ # ---------- Address file ----------
80
+ def load_addresses(path):
 
 
 
 
 
 
 
 
 
 
 
81
  s = set()
82
  with open(path, "r", encoding="utf-8") as f:
83
  for line in f:
 
86
  a = a[2:]
87
  if a and len(a) == 40:
88
  s.add(a)
 
 
 
 
 
 
89
  return s
90
 
91
  def normalize(addr):
 
116
  # ============================================================
117
 
118
  def generate_random_phrase():
119
+ """BIP39 valid phrase generate karta hai β€” checksum ke saath."""
120
+ mnemo = _get_mnemonic()
121
+ return mnemo.generate(strength=128) # 128 bits = 12 words
122
 
123
 
124
+ def run_scan_range(phrase, addresses_file, phrase_mode,
125
+ start_index, end_index, passphrase):
126
+ """0–20 index range scan β€” single process, fast."""
 
 
 
127
  if not os.path.exists(addresses_file):
128
  return f"❌ File nahi mili: {addresses_file}", ""
129
 
130
+ words = phrase.strip().split()
131
+ if len(words) != 12:
132
+ return f"❌ Phrase 12 words ki nahi hai ({len(words)} words)", ""
133
 
134
  start_index = int(start_index)
135
  end_index = int(end_index)
 
137
  return "❌ Start index end index se bada nahi ho sakta", ""
138
 
139
  try:
140
+ known = load_addresses(addresses_file)
141
  except Exception as e:
142
  return f"❌ Addresses load fail: {e}", ""
143
 
144
  if not known:
145
  return "❌ Koi valid address file mein nahi mila", ""
146
 
147
+ total_combos = len(words) * len(words) if phrase_mode == "replace" else math.factorial(len(words)) if phrase_mode == "order" else 2**len(words) - 1
148
+ index_count = end_index - start_index + 1
149
+ total_scans = total_combos * index_count
150
 
151
  log_lines = [
152
+ f"βœ… Loaded {len(known):,} addresses",
153
  f"πŸ”§ Mode: {phrase_mode}",
154
+ f"πŸ”‘ Index range: {start_index}–{end_index} ({index_count} indices)",
155
+ f"πŸ“ Phrase: {phrase}",
156
+ f"πŸ”’ Combinations per index: {total_combos:,}",
157
+ f"πŸ”’ Total scans: {total_scans:,}",
158
  "",
 
159
  ]
 
 
 
160
 
161
  matches = []
162
  start = time.time()
163
 
164
+ for idx in range(start_index, end_index + 1):
165
+ log_lines.append(f"πŸ” Checking index {idx}...")
166
+ for phrase_str in generate_phrases_for_words(words, phrase_mode):
167
+ if not is_valid_bip39(phrase_str):
168
+ continue
169
+ try:
170
+ seed = phrase_to_seed(phrase_str, passphrase)
171
+ priv = seed_to_privkey_hd(seed, idx)
172
+ pub = coincurve.PrivateKey(priv).public_key.format(compressed=False)[1:]
173
+ addr = to_checksum_address(keccak(pub)[-20:])
174
+ except Exception:
175
+ continue
176
+ if normalize(addr) in known:
177
+ match_line = (
178
+ f"πŸŽ‰ MATCH!\n"
179
+ f"Phrase: {phrase_str}\n"
180
+ f"Index: {idx}\n"
181
+ f"Key: {priv.hex()}\n"
182
+ f"Addr: {addr}\n"
183
+ )
184
+ log_lines.append(match_line)
185
+ matches.append((phrase_str, idx, priv.hex(), addr))
 
 
 
 
 
 
186
 
187
  elapsed = time.time() - start
188
  log_lines.append(f"=== DONE ===")
 
201
  # ============================================================
202
  with gr.Blocks(title="Phrase Scanner") as demo:
203
  gr.Markdown("# πŸ” Phrase Scanner")
204
+ gr.Markdown("Phrase daalein aur index range (0–20) ke saath address file se match karein.")
205
 
206
  with gr.Row():
207
  with gr.Column(scale=1):
208
  gr.Markdown("### Settings")
209
+ phrase = gr.Textbox(
210
+ label="πŸ”‘ 12-Word Phrase",
211
+ value="lesson cushion crane affair federal decline limb spend reunion chief cart zebra",
212
+ lines=2,
213
+ placeholder="lesson cushion crane ...",
214
  )
215
+ generate_btn = gr.Button("🎲 Random Phrase Generate Karein", variant="secondary")
216
  addresses_file = gr.Textbox(
217
  label="Addresses File",
218
  value="12730802_addresses.csv",
 
254
  autoscroll=True,
255
  )
256
 
257
+ generate_btn.click(fn=generate_random_phrase, outputs=[phrase])
258
  run_btn.click(
259
+ fn=run_scan_range,
260
+ inputs=[phrase, addresses_file, phrase_mode,
261
  start_index, end_index, passphrase],
262
  outputs=[log_output, matches_output],
263
  )