DILSHAD737 commited on
Commit
a52cbb4
·
1 Parent(s): b8d88cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -157
app.py CHANGED
@@ -98,160 +98,4 @@ def phrase_to_seed(phrase):
98
  return _seed_fn(phrase, BIP39_PASSPHRASE)
99
  return _get_mnemonic().to_seed(phrase, passphrase=BIP39_PASSPHRASE)
100
 
101
- # ---------- Address file ----------
102
- def load_addresses(path):
103
- s = set()
104
- with open(path, "r", encoding="utf-8") as f:
105
- for line in f:
106
- a = line.strip().strip('"').strip("'").lstrip("\ufeff").lower()
107
- if a.startswith("0x"):
108
- a = a[2:]
109
- if a and len(a) == 40:
110
- s.add(a)
111
- return frozenset(s)
112
-
113
- def normalize(addr):
114
- a = addr.strip().lower()
115
- if a.startswith("0x"):
116
- a = a[2:]
117
- return a
118
-
119
- # ---------- Generator ----------
120
- def generate_phrases_for_words(wordlist):
121
- n = len(wordlist)
122
- if PHRASE_MODE == "order":
123
- for perm in permutations(wordlist):
124
- yield " ".join(perm)
125
- elif PHRASE_MODE == "replace":
126
- for i in range(n):
127
- for w in wordlist:
128
- new = wordlist.copy()
129
- new[i] = w
130
- yield " ".join(new)
131
- elif PHRASE_MODE == "subset":
132
- for r in range(1, n + 1):
133
- for combo in combinations(wordlist, r):
134
- yield " ".join(combo)
135
-
136
- # ---------- Worker ----------
137
- _KNOWN = None
138
- def init_worker(known):
139
- global _KNOWN
140
- _KNOWN = known
141
- _get_mnemonic()
142
-
143
- def process_batch(batch):
144
- hits = []
145
- known = _KNOWN
146
- for phrase in batch:
147
- if CHECK_BIP39_CHECKSUM and not is_valid_bip39(phrase):
148
- continue
149
- try:
150
- seed = phrase_to_seed(phrase)
151
- if HD_DERIVATION:
152
- priv = seed_to_privkey_hd(seed, ADDRESS_INDEX)
153
- else:
154
- priv = seed[:32]
155
- pub = coincurve.PrivateKey(priv).public_key.format(compressed=False)[1:]
156
- addr = to_checksum_address(keccak(pub)[-20:])
157
- except Exception:
158
- continue
159
- if normalize(addr) in known:
160
- hits.append((phrase, priv.hex(), addr))
161
- return hits
162
-
163
- def batch_generator_for_words(wordlist):
164
- batch = []
165
- for phrase in generate_phrases_for_words(wordlist):
166
- batch.append(phrase)
167
- if len(batch) >= BATCH_SIZE:
168
- yield batch
169
- batch = []
170
- if batch:
171
- yield batch
172
-
173
- # ---------- Progress bar helper ----------
174
- def make_bar(idx, total, tag=""):
175
- bar_len = 30
176
- filled = int(bar_len * idx / total)
177
- bar = "█" * filled + "░" * (bar_len - filled)
178
- pct = int(100 * idx / total)
179
- return f" Progress: [{bar}] {idx}/{total} ({pct}%){tag}"
180
-
181
- # ---------- Main ----------
182
- def main():
183
- if not os.path.exists(ADDRESSES_FILE):
184
- raise SystemExit(f"File nahi mili: {ADDRESSES_FILE}")
185
-
186
- known = load_addresses(ADDRESSES_FILE)
187
-
188
- # ========================================================
189
- # ✅ Settings Table
190
- # ========================================================
191
- print("\n" + "=" * 55)
192
- print(" SCAN SETTINGS")
193
- print("=" * 55)
194
- print(f" {'Phrase Mode':<22}: {PHRASE_MODE}")
195
- print(f" {'HD Derivation':<22}: {HD_DERIVATION}")
196
- print(f" {'Address Index':<22}: {ADDRESS_INDEX}")
197
- print(f" {'Passphrase':<22}: {'(set)' if BIP39_PASSPHRASE else '(empty)'}")
198
- print(f" {'Checksum Prefilter':<22}: {CHECK_BIP39_CHECKSUM}")
199
- print(f" {'Rust BIP39':<22}: {_USE_RUST_BIP39}")
200
- print(f" {'Seed Function':<22}: {_seed_fn.__name__ if _USE_RUST_BIP39 and _seed_fn else 'fallback'}")
201
- print(f" {'Addresses File':<22}: {ADDRESSES_FILE}")
202
- print(f" {'Loaded Addresses':<22}: {len(known):,}")
203
- print(f" {'Workers':<22}: {NUM_WORKERS}")
204
- print(f" {'Batch Size':<22}: {BATCH_SIZE:,}")
205
- print(f" {'Chunk Size':<22}: {CHUNK_SIZE}")
206
- print(f" {'Total Phrases':<22}: {len(RANDOM_PHRASES)}")
207
- print(f" {'Output File':<22}: {MATCHED_FILE}")
208
- print("=" * 55 + "\n")
209
-
210
- with open(MATCHED_FILE, "w", encoding="utf-8") as f:
211
- f.write("")
212
-
213
- total_matches = []
214
- all_start = time.time()
215
- total_phrases = len(RANDOM_PHRASES)
216
-
217
- for idx, wordlist in enumerate(RANDOM_PHRASES, 1):
218
- tag = " (AAPKI)" if (idx == 1 and len(my_words) == 12) else ""
219
- current_bar = make_bar(idx, total_phrases, tag)
220
-
221
- # ✅ Progress bar print (same line)
222
- print(f"\r{current_bar}", end="", flush=True)
223
-
224
- gc.collect()
225
- gc.freeze()
226
-
227
- with Pool(processes=NUM_WORKERS,
228
- initializer=init_worker,
229
- initargs=(known,)) as pool:
230
- for hits in pool.imap_unordered(
231
- process_batch,
232
- batch_generator_for_words(wordlist),
233
- chunksize=CHUNK_SIZE
234
- ):
235
- for phrase, key_hex, addr in hits:
236
- # ✅ Match print (progress bar ke baad, nayi line pe)
237
- print(f"\n\n✅ MATCH: {phrase}\n priv: {key_hex}\n addr: {addr}\n")
238
- matches_entry = (phrase, key_hex, addr)
239
- total_matches.append(matches_entry)
240
- with open(MATCHED_FILE, "a", encoding="utf-8") as f:
241
- f.write(f"{phrase} | {key_hex} | {addr}\n")
242
- f.flush()
243
- os.fsync(f.fileno())
244
-
245
- # ✅ Match ke baad progress bar DOBARA same line pe restore karein
246
- print(f"\r{current_bar}", end="", flush=True)
247
-
248
- all_elapsed = time.time() - all_start
249
- print(f"\n\n=== DONE ===")
250
- print(f"Total time: {all_elapsed/60:.2f} min")
251
- print(f"Total matches: {len(total_matches)}")
252
- if total_matches:
253
- print(f"Results: {MATCHED_FILE}")
254
-
255
-
256
- if __name__ == "__main__":
257
- main()
 
98
  return _seed_fn(phrase, BIP39_PASSPHRASE)
99
  return _get_mnemonic().to_seed(phrase, passphrase=BIP39_PASSPHRASE)
100
 
101
+ # ---------- Address file ---------