Spaces:
Runtime error
Runtime error
Commit Β·
e12a5db
1
Parent(s): 45d8cd1
Update app.py
Browse files
app.py
CHANGED
|
@@ -129,11 +129,11 @@ def generate_phrases_for_words(wordlist, mode):
|
|
| 129 |
yield " ".join(combo)
|
| 130 |
|
| 131 |
# ============================================================
|
| 132 |
-
#
|
| 133 |
# ============================================================
|
| 134 |
|
| 135 |
-
def
|
| 136 |
-
|
| 137 |
|
| 138 |
if not os.path.exists(addresses_file):
|
| 139 |
return f"β File nahi mili: {addresses_file}", ""
|
|
@@ -160,33 +160,30 @@ def run_scan_sync(my_phrase, num_phrases, addresses_file, phrase_mode,
|
|
| 160 |
for _ in range(num_phrases):
|
| 161 |
phrases.append(mnemo.generate(strength=128))
|
| 162 |
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
f"π Index range: {start_index}β{end_index}",
|
| 167 |
-
f"π Total phrases: {len(phrases)}",
|
| 168 |
-
"",
|
| 169 |
-
"**Phrases:**",
|
| 170 |
-
]
|
| 171 |
-
for i, p in enumerate(phrases, 1):
|
| 172 |
-
tag = " **(AAPKI)**" if i == 1 and len(my_words) == 12 else ""
|
| 173 |
-
log_lines.append(f"{i}. `{p}`{tag}")
|
| 174 |
|
| 175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
matches = []
|
| 178 |
start = time.time()
|
| 179 |
total_phrases = len(phrases)
|
| 180 |
|
| 181 |
for p_idx, phrase in enumerate(phrases, 1):
|
| 182 |
-
|
| 183 |
words = phrase.strip().split()
|
| 184 |
|
| 185 |
if len(words) != 12:
|
| 186 |
-
|
| 187 |
continue
|
| 188 |
|
| 189 |
for idx in range(start_index, end_index + 1):
|
|
|
|
| 190 |
for phrase_str in generate_phrases_for_words(words, phrase_mode):
|
| 191 |
if not is_valid_bip39(phrase_str):
|
| 192 |
continue
|
|
@@ -199,79 +196,52 @@ def run_scan_sync(my_phrase, num_phrases, addresses_file, phrase_mode,
|
|
| 199 |
continue
|
| 200 |
|
| 201 |
if normalize(addr) in known:
|
| 202 |
-
match_line = (
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
f"**Index:** {idx}\n"
|
| 206 |
-
f"**Key:** `{priv.hex()}`\n"
|
| 207 |
-
f"**Addr:** `{addr}`\n"
|
| 208 |
-
)
|
| 209 |
-
log_lines.append(match_line)
|
| 210 |
-
matches.append((phrase_str, idx, priv.hex(), addr))
|
| 211 |
|
| 212 |
elapsed = time.time() - start
|
| 213 |
-
|
| 214 |
-
log_lines.append(f"**=== DONE ===**")
|
| 215 |
-
log_lines.append(f"**Total time:** {elapsed:.1f}s")
|
| 216 |
-
log_lines.append(f"**Total matches:** {len(matches)}")
|
| 217 |
|
| 218 |
-
matches_text = "\n
|
| 219 |
-
f"**Phrase:** `{p}`\n**Index:** {i}\n**Key:** `{k}`\n**Addr:** `{a}`"
|
| 220 |
-
for p, i, k, a in matches
|
| 221 |
-
) if matches else "Koi match nahi mila"
|
| 222 |
|
| 223 |
-
|
| 224 |
-
return "\n\n".join(log_lines), matches_text
|
| 225 |
|
| 226 |
# ============================================================
|
| 227 |
-
#
|
| 228 |
# ============================================================
|
| 229 |
-
with gr.Blocks(title="Phrase Scanner"
|
| 230 |
gr.Markdown("# π Phrase Scanner")
|
| 231 |
-
|
| 232 |
-
|
| 233 |
with gr.Row():
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
with gr.Column(scale=2):
|
| 261 |
-
gr.Markdown("### Output")
|
| 262 |
-
# gr.Markdown handles long text and scrolls perfectly
|
| 263 |
-
log_output = gr.Markdown(
|
| 264 |
-
value="Scan shuru karne ke liye button dabayein.",
|
| 265 |
-
elem_classes="log-box"
|
| 266 |
-
)
|
| 267 |
-
gr.Markdown("### Matches")
|
| 268 |
-
matches_output = gr.Markdown(
|
| 269 |
-
value="Matches yahan dikhenge.",
|
| 270 |
-
elem_classes="log-box"
|
| 271 |
-
)
|
| 272 |
|
| 273 |
run_btn.click(
|
| 274 |
-
fn=
|
| 275 |
inputs=[my_phrase, num_phrases, addresses_file, phrase_mode,
|
| 276 |
start_index, end_index, passphrase],
|
| 277 |
outputs=[log_output, matches_output],
|
|
|
|
| 129 |
yield " ".join(combo)
|
| 130 |
|
| 131 |
# ============================================================
|
| 132 |
+
# Scan Function (No Generators, No Yields)
|
| 133 |
# ============================================================
|
| 134 |
|
| 135 |
+
def run_scan(my_phrase, num_phrases, addresses_file, phrase_mode,
|
| 136 |
+
start_index, end_index, passphrase):
|
| 137 |
|
| 138 |
if not os.path.exists(addresses_file):
|
| 139 |
return f"β File nahi mili: {addresses_file}", ""
|
|
|
|
| 160 |
for _ in range(num_phrases):
|
| 161 |
phrases.append(mnemo.generate(strength=128))
|
| 162 |
|
| 163 |
+
log_text = f"β
Loaded {len(known):,} addresses\n"
|
| 164 |
+
log_text += f"π§ Mode: {phrase_mode} | π Index: {start_index}-{end_index}\n"
|
| 165 |
+
log_text += f"π Total phrases: {len(phrases)}\n\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
+
log_text += "Phrases:\n"
|
| 168 |
+
for i, p in enumerate(phrases, 1):
|
| 169 |
+
tag = " (AAPKI)" if i == 1 and len(my_words) == 12 else ""
|
| 170 |
+
log_text += f" {i}. {p}{tag}\n"
|
| 171 |
+
log_text += "\n--- Scanning ---\n"
|
| 172 |
|
| 173 |
matches = []
|
| 174 |
start = time.time()
|
| 175 |
total_phrases = len(phrases)
|
| 176 |
|
| 177 |
for p_idx, phrase in enumerate(phrases, 1):
|
| 178 |
+
log_text += f"\nπ [{p_idx}/{total_phrases}] Checking: {phrase}\n"
|
| 179 |
words = phrase.strip().split()
|
| 180 |
|
| 181 |
if len(words) != 12:
|
| 182 |
+
log_text += " β οΈ Skipped (not 12 words)\n"
|
| 183 |
continue
|
| 184 |
|
| 185 |
for idx in range(start_index, end_index + 1):
|
| 186 |
+
log_text += f" - Index {idx}...\n"
|
| 187 |
for phrase_str in generate_phrases_for_words(words, phrase_mode):
|
| 188 |
if not is_valid_bip39(phrase_str):
|
| 189 |
continue
|
|
|
|
| 196 |
continue
|
| 197 |
|
| 198 |
if normalize(addr) in known:
|
| 199 |
+
match_line = f"π MATCH!\nPhrase: {phrase_str}\nIndex: {idx}\nKey: {priv.hex()}\nAddr: {addr}\n"
|
| 200 |
+
log_text += match_line
|
| 201 |
+
matches.append(match_line)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
|
| 203 |
elapsed = time.time() - start
|
| 204 |
+
log_text += f"\n=== DONE ===\nTotal time: {elapsed:.1f}s\nTotal matches: {len(matches)}\n"
|
|
|
|
|
|
|
|
|
|
| 205 |
|
| 206 |
+
matches_text = "\n".join(matches) if matches else "Koi match nahi mila"
|
|
|
|
|
|
|
|
|
|
| 207 |
|
| 208 |
+
return log_text, matches_text
|
|
|
|
| 209 |
|
| 210 |
# ============================================================
|
| 211 |
+
# Simple, Flat UI (No Columns, No Layout Bugs)
|
| 212 |
# ============================================================
|
| 213 |
+
with gr.Blocks(title="Phrase Scanner") as demo:
|
| 214 |
gr.Markdown("# π Phrase Scanner")
|
| 215 |
+
|
|
|
|
| 216 |
with gr.Row():
|
| 217 |
+
my_phrase = gr.Textbox(
|
| 218 |
+
label="π Apni Phrase (optional)",
|
| 219 |
+
value="lesson cushion crane affair federal decline limb spend reunion chief cart zebra",
|
| 220 |
+
lines=2,
|
| 221 |
+
)
|
| 222 |
+
|
| 223 |
+
with gr.Row():
|
| 224 |
+
num_phrases = gr.Number(label="Kitni Random Phrases Check Karein?", value=10, precision=0, minimum=0)
|
| 225 |
+
addresses_file = gr.Textbox(label="Addresses File", value="12730802_addresses.csv")
|
| 226 |
+
|
| 227 |
+
with gr.Row():
|
| 228 |
+
phrase_mode = gr.Radio(choices=["replace", "order", "subset"], value="replace", label="Phrase Mode")
|
| 229 |
+
start_index = gr.Number(label="Start Index", value=0, precision=0, minimum=0)
|
| 230 |
+
end_index = gr.Number(label="End Index", value=20, precision=0, minimum=0)
|
| 231 |
+
|
| 232 |
+
with gr.Row():
|
| 233 |
+
passphrase = gr.Textbox(label="BIP39 Passphrase (khali chhod dein)", value="", type="password")
|
| 234 |
+
|
| 235 |
+
run_btn = gr.Button("π Scan Shuru Karein", variant="primary")
|
| 236 |
+
|
| 237 |
+
gr.Markdown("### Output")
|
| 238 |
+
log_output = gr.Textbox(lines=15, interactive=False, show_label=False)
|
| 239 |
+
|
| 240 |
+
gr.Markdown("### Matches")
|
| 241 |
+
matches_output = gr.Textbox(lines=8, interactive=False, show_label=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
|
| 243 |
run_btn.click(
|
| 244 |
+
fn=run_scan,
|
| 245 |
inputs=[my_phrase, num_phrases, addresses_file, phrase_mode,
|
| 246 |
start_index, end_index, passphrase],
|
| 247 |
outputs=[log_output, matches_output],
|