DILSHAD737 commited on
Commit
25b31ba
·
1 Parent(s): a41694f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -39
app.py CHANGED
@@ -16,17 +16,19 @@ USE_BIP39 = True
16
  BIP39_PASSPHRASE = ""
17
  HD_DERIVATION = True
18
  ADDRESS_INDEX = 0
19
- CHECK_BIP39_CHECKSUM = True
20
  ADDRESSES_FILE = "12730802_addresses.csv"
21
  MATCHED_FILE = f"matched_keys_{PHRASE_MODE}.txt"
22
- BATCH_SIZE = 500
23
  NUM_WORKERS = 96
24
  # ============================================================
25
 
 
26
  # ---------- secp256k1 ----------
27
  _SECP256K1_N = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
28
  _HARDENED = 0x80000000
29
 
 
30
  def _bip32_derive_child_priv(parent_priv, parent_chain, index):
31
  if index >= _HARDENED:
32
  data = b'\x00' + parent_priv + index.to_bytes(4, 'big')
@@ -39,6 +41,7 @@ def _bip32_derive_child_priv(parent_priv, parent_chain, index):
39
  raise ValueError("Invalid child key")
40
  return child_int.to_bytes(32, 'big'), I[32:]
41
 
 
42
  def seed_to_privkey_hd(seed, address_index=0):
43
  I = hmac.new(b"Bitcoin seed", seed, hashlib.sha512).digest()
44
  key, chain = I[:32], I[32:]
@@ -47,6 +50,7 @@ def seed_to_privkey_hd(seed, address_index=0):
47
  key, chain = _bip32_derive_child_priv(key, chain, idx)
48
  return key
49
 
 
50
  # ---------- BIP39 ----------
51
  try:
52
  import bip39 as _bip39_rust
@@ -78,7 +82,8 @@ def phrase_to_seed(phrase):
78
  return _bip39_rust.bip39_mnemonic_to_seed(phrase, BIP39_PASSPHRASE)
79
  return _get_mnemonic().to_seed(phrase, passphrase=BIP39_PASSPHRASE)
80
 
81
- # ---------- Address file ----------
 
82
  def load_addresses(path):
83
  s = set()
84
  with open(path, "r", encoding="utf-8") as f:
@@ -96,6 +101,7 @@ def normalize(addr):
96
  a = a[2:]
97
  return a
98
 
 
99
  # ---------- Generator ----------
100
  def generate_phrases():
101
  n = len(words)
@@ -119,6 +125,7 @@ def count_total():
119
  if PHRASE_MODE == "replace": return n * n
120
  if PHRASE_MODE == "subset": return 2**n - 1
121
 
 
122
  # ---------- Worker ----------
123
  _KNOWN = None
124
 
@@ -126,24 +133,13 @@ def init_worker(known):
126
  global _KNOWN
127
  _KNOWN = known
128
  _get_mnemonic()
129
- # ✅ DEBUG: worker init confirm
130
- print(f"🔧 Worker init: known size = {len(known):,}")
131
- target = "3f0482fc3e9132c3d3acb5f588e980d7b3a5af07"
132
- print(f" target in known: {target in known}")
133
 
134
  def process_batch(batch):
135
  hits = []
136
  known = _KNOWN
137
  m = _get_mnemonic()
138
  for phrase in batch:
139
- # ✅ DEBUG: har phrase print (sirf pehle 5, taake output flood na ho)
140
- if process_batch.counter < 5:
141
- print(f"🔍 Process phrase: {phrase}")
142
- process_batch.counter += 1
143
-
144
  if CHECK_BIP39_CHECKSUM and not is_valid_bip39_fast(phrase):
145
- if process_batch.counter <= 5:
146
- print(f" ❌ Checksum fail: {phrase}")
147
  continue
148
  try:
149
  seed = phrase_to_seed(phrase)
@@ -153,28 +149,12 @@ def process_batch(batch):
153
  priv = seed[:32]
154
  pub = coincurve.PrivateKey(priv).public_key.format(compressed=False)[1:]
155
  addr = to_checksum_address(keccak(pub)[-20:])
156
- except Exception as e:
157
- if process_batch.counter <= 5:
158
- print(f" ❌ Error: {e}")
159
  continue
160
-
161
- normalized = normalize(addr)
162
- if process_batch.counter <= 5:
163
- print(f" addr: {addr}")
164
- print(f" normalized: {normalized}")
165
- print(f" in known: {normalized in known}")
166
- if phrase == "lesson cushion crane affair federal decline limb spend reunion chief cart zebra":
167
- target = "3f0482fc3e9132c3d3acb5f588e980d7b3a5af07"
168
- print(f" target: {target}")
169
- print(f" equal: {normalized == target}")
170
-
171
- if normalized in known:
172
  hits.append((phrase, priv.hex(), addr))
173
  return hits
174
 
175
- # Counter attribute (multiprocessing mein kaam karega? nahi, lekin debug ke liye)
176
- process_batch.counter = 0
177
-
178
  def batch_generator():
179
  batch = []
180
  for phrase in generate_phrases():
@@ -185,6 +165,7 @@ def batch_generator():
185
  if batch:
186
  yield batch
187
 
 
188
  # ---------- Main ----------
189
  def main():
190
  if not os.path.exists(ADDRESSES_FILE):
@@ -197,12 +178,6 @@ def main():
197
  known = load_addresses(ADDRESSES_FILE)
198
  print(f"Loaded {len(known):,} lowercase addresses\n")
199
 
200
- # ✅ DEBUG: pehla phrase check
201
- first_phrase = next(generate_phrases())
202
- print(f"First phrase generated: {first_phrase}")
203
- print(f"Target phrase: {repr('lesson cushion crane affair federal decline limb spend reunion chief cart zebra')}")
204
- print(f"Match: {first_phrase == 'lesson cushion crane affair federal decline limb spend reunion chief cart zebra'}\n")
205
-
206
  matches = []
207
  done = 0
208
  start = time.time()
@@ -227,7 +202,7 @@ def main():
227
  f.write(f"{phrase} | {key_hex} | {addr}\n")
228
 
229
  now = time.time()
230
- if now - last_log >= 2:
231
  elapsed = now - start
232
  rate = done / elapsed if elapsed else 0
233
  eta = (total - done) / rate if rate else 0
@@ -237,5 +212,6 @@ def main():
237
  elapsed = time.time() - start
238
  print(f"\nDone {elapsed:.1f}s. {len(matches)} match(es).")
239
 
 
240
  if __name__ == "__main__":
241
  main()
 
16
  BIP39_PASSPHRASE = ""
17
  HD_DERIVATION = True
18
  ADDRESS_INDEX = 0
19
+ CHECK_BIP39_CHECKSUM = False
20
  ADDRESSES_FILE = "12730802_addresses.csv"
21
  MATCHED_FILE = f"matched_keys_{PHRASE_MODE}.txt"
22
+ BATCH_SIZE = 5000
23
  NUM_WORKERS = 96
24
  # ============================================================
25
 
26
+
27
  # ---------- secp256k1 ----------
28
  _SECP256K1_N = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
29
  _HARDENED = 0x80000000
30
 
31
+
32
  def _bip32_derive_child_priv(parent_priv, parent_chain, index):
33
  if index >= _HARDENED:
34
  data = b'\x00' + parent_priv + index.to_bytes(4, 'big')
 
41
  raise ValueError("Invalid child key")
42
  return child_int.to_bytes(32, 'big'), I[32:]
43
 
44
+
45
  def seed_to_privkey_hd(seed, address_index=0):
46
  I = hmac.new(b"Bitcoin seed", seed, hashlib.sha512).digest()
47
  key, chain = I[:32], I[32:]
 
50
  key, chain = _bip32_derive_child_priv(key, chain, idx)
51
  return key
52
 
53
+
54
  # ---------- BIP39 ----------
55
  try:
56
  import bip39 as _bip39_rust
 
82
  return _bip39_rust.bip39_mnemonic_to_seed(phrase, BIP39_PASSPHRASE)
83
  return _get_mnemonic().to_seed(phrase, passphrase=BIP39_PASSPHRASE)
84
 
85
+
86
+ # ---------- Address file (lowercase) ----------
87
  def load_addresses(path):
88
  s = set()
89
  with open(path, "r", encoding="utf-8") as f:
 
101
  a = a[2:]
102
  return a
103
 
104
+
105
  # ---------- Generator ----------
106
  def generate_phrases():
107
  n = len(words)
 
125
  if PHRASE_MODE == "replace": return n * n
126
  if PHRASE_MODE == "subset": return 2**n - 1
127
 
128
+
129
  # ---------- Worker ----------
130
  _KNOWN = None
131
 
 
133
  global _KNOWN
134
  _KNOWN = known
135
  _get_mnemonic()
 
 
 
 
136
 
137
  def process_batch(batch):
138
  hits = []
139
  known = _KNOWN
140
  m = _get_mnemonic()
141
  for phrase in batch:
 
 
 
 
 
142
  if CHECK_BIP39_CHECKSUM and not is_valid_bip39_fast(phrase):
 
 
143
  continue
144
  try:
145
  seed = phrase_to_seed(phrase)
 
149
  priv = seed[:32]
150
  pub = coincurve.PrivateKey(priv).public_key.format(compressed=False)[1:]
151
  addr = to_checksum_address(keccak(pub)[-20:])
152
+ except Exception:
 
 
153
  continue
154
+ if normalize(addr) in known:
 
 
 
 
 
 
 
 
 
 
 
155
  hits.append((phrase, priv.hex(), addr))
156
  return hits
157
 
 
 
 
158
  def batch_generator():
159
  batch = []
160
  for phrase in generate_phrases():
 
165
  if batch:
166
  yield batch
167
 
168
+
169
  # ---------- Main ----------
170
  def main():
171
  if not os.path.exists(ADDRESSES_FILE):
 
178
  known = load_addresses(ADDRESSES_FILE)
179
  print(f"Loaded {len(known):,} lowercase addresses\n")
180
 
 
 
 
 
 
 
181
  matches = []
182
  done = 0
183
  start = time.time()
 
202
  f.write(f"{phrase} | {key_hex} | {addr}\n")
203
 
204
  now = time.time()
205
+ if now - last_log >= 5:
206
  elapsed = now - start
207
  rate = done / elapsed if elapsed else 0
208
  eta = (total - done) / rate if rate else 0
 
212
  elapsed = time.time() - start
213
  print(f"\nDone {elapsed:.1f}s. {len(matches)} match(es).")
214
 
215
+
216
  if __name__ == "__main__":
217
  main()