Last active
June 7, 2020 15:29
-
-
Save SomberNight/a53257cf9e05ac07fd47ce0821b2a1fb to your computer and use it in GitHub Desktop.
Electrum: bruteforce a single missing word for a seed
This file contains 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
#!/usr/bin/python3 | |
import os | |
import copy | |
import imp | |
#imp.load_source('electrum', './electrum') | |
import electrum | |
from electrum import bitcoin | |
wordlist = [] | |
seed_type = '' | |
def init_wordlist(): | |
global wordlist | |
wordlist = electrum.mnemonic.load_wordlist('english.txt') | |
def is_possible_electrum_seed(seed_words): | |
return bitcoin.seed_type(seed_words) == seed_type | |
def seed_found(seed_words): | |
print("possible seed found: " + seed_words) | |
def test_seed_candidate(seed_words): | |
if is_possible_electrum_seed(seed_words): | |
seed_found(seed_words) | |
def fuzz_seed_insert_one_word(seed_words_split, pos, word): | |
swlist = copy.deepcopy(seed_words_split) | |
swlist.insert(pos, word) | |
sw = " ".join(swlist) | |
test_seed_candidate(sw) | |
def fuzz_seed(seed_words_split): | |
for pos in range(0,len(seed_words_split)): | |
for word in wordlist: | |
fuzz_seed_insert_one_word(seed_words_split, pos, word) | |
def main(): | |
init_wordlist() | |
print("Word list read.") | |
global seed_type | |
# ----- CHANGE HERE ----- | |
given_seed = 'couch wish parrot stomach squirrel race bright upper sheriff wrong park' | |
seed_type = 'segwit' | |
# correct seed is | |
# couch wish parrot stomach squirrel unable race bright upper sheriff wrong park | |
given_seed_split = given_seed.split() | |
assert seed_type in ['segwit', '2fa'] | |
# note that 'standard' seeds should work too but there would be too many false positives | |
fuzz_seed(given_seed_split) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
AttributeError: module 'electrum.bitcoin' has no attribute 'seed_type'