Last active
April 28, 2023 17:52
-
-
Save miketery/5f909001f7694c77d7e9beece81420ae to your computer and use it in GitHub Desktop.
100K sats Capture the Flag based on 256 bits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://twitter.com/w_s_bitcoin/status/1651779628619509765 | |
# Target pubkey: bc1q0navdwrt7jry46a0zzpekaf5ey8u9hzlfdtgtk | |
# Path: m/84'/0'/0'/0/0 | |
import hashlib | |
import bech32 | |
import numpy as np | |
from bip32 import BIP32, HARDENED_INDEX | |
from mnemonic import Mnemonic | |
TARGET = "bc1q0navdwrt7jry46a0zzpekaf5ey8u9hzlfdtgtk" | |
data = [ | |
"1010110010101010", | |
"1011010101101010", | |
"0101111010111100", | |
"1100010101100101", | |
"0101101110110111", | |
"1010010111010110", | |
"0000001100101111", | |
"1110101000110010", | |
"1000111011101010", | |
"1011011101011100", | |
"0000110110111011", | |
"1111001000100110", | |
"0101011010111100", | |
"1110111111001001", | |
"0000111011001110", | |
"1100111111111110" | |
] | |
# if we want to flip bits can do it here | |
x = np.array([["0" if bit == "0" else "1" for bit in i] for i in data]) | |
possibilities = [] | |
# 4 rotations | |
for i in range(4): | |
x = np.rot90(x) | |
possibilities += [x] | |
# mirror | |
x = np.flip(x, 1) | |
# 4 rotations | |
for i in range(4): | |
x = np.rot90(x) | |
possibilities += [x] | |
hex_positibilities = [] | |
for i in possibilities: | |
hex_positibilities += [hex(int("".join(i.flatten()),2))] | |
# convert to words | |
mnemo = Mnemonic("english") | |
words = [] | |
for i in hex_positibilities: | |
words.append(mnemo.to_mnemonic(bytes.fromhex(i[2:]))) | |
# see whether any of the combinations matches our taget | |
for i in words: | |
seed = mnemo.to_seed(i) | |
root = BIP32.from_seed(seed) | |
pub = root.get_pubkey_from_path('m/84h/0h/0h/0/0') | |
sha256_hash = hashlib.sha256(pub).digest() | |
ripemd160_hash = hashlib.new('ripemd160', sha256_hash).digest() | |
bech32_address = bech32.encode("bc", 0, ripemd160_hash) | |
if bech32_address == TARGET: | |
print("Found a match for address:", TARGET) | |
print("Associated words are:") | |
print(i) | |
exit(0) | |
print("No match found for address:", TARGET) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment