Skip to content

Instantly share code, notes, and snippets.

@jasny
Last active April 5, 2022 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasny/dc19d85fca14c2e3245201fe42b4f8ef to your computer and use it in GitHub Desktop.
Save jasny/dc19d85fca14c2e3245201fe42b4f8ef to your computer and use it in GitHub Desktop.
Recover LTO seed from known words
from lto.accounts import AccountFactoryED25519
from itertools import permutations
address = "3JzSs25zWMomDHmw3jA3v9rpqqxxzmCAd9Hs"
words = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o"]
factory = AccountFactoryED25519('L')
def find_insert_word():
print("Changing the position of each word")
for i in range(0, len(words)):
attempt = words.copy()
word = attempt.pop(i)
for j in range(0, len(attempt)):
seed = attempt.copy()
seed.insert(j, word)
account = factory.create_from_seed(" ".join(seed))
if (account.address == address):
return seed
return None
def find_swap_words():
print("All posibilities of swapping two words")
for i in range(0, len(words) - 2):
for j in range(i + 2, len(words)):
seed = words.copy()
seed.insert(j, seed.pop(i))
seed.insert(i, seed.pop(j - 1))
account = factory.create_from_seed(" ".join(seed))
if (account.address == address):
return seed
return None
def try_permutations(before, change, after):
print("Permutations {} <{}> {}".format(before, change, after))
for attempt in permutations(change):
seed = [*before, *attempt, *after]
account = factory.create_from_seed(" ".join(seed))
if (account.address == address):
return seed
return None
def find_partly_correct(nr_correct):
delta = len(words) - nr_correct
for i in range(0, nr_correct + 1):
seed = try_permutations(words[:i], words[i:i+delta], words[i+delta:])
if (seed):
return seed
return None
def try_insert_permutations(keep, change):
print("Insert permutations {} <{}>".format(keep, change))
for attempt in permutations(change):
for i in range(0, len(attempt)):
seed = [*attempt[:i], *keep, *attempt[i:]]
account = factory.create_from_seed(" ".join(seed))
if (account.address == address):
return seed
return None
def find_sequence_correct(nr_correct):
for i in range(0, nr_correct + 1):
seed = try_insert_permutations(words[i:i+nr_correct], [*words[:i], *words[i+nr_correct:]])
if (seed):
return seed
return None
found = find_insert_word() or find_swap_words() or find_partly_correct(7) or find_sequence_correct(10)
if found:
print(" ".join(found))
else:
print("No seed found that matches address %s :-(" % address)
from lto.accounts import AccountFactoryED25519
from itertools import permutations
address = "3JzSs25zWMomDHmw3jA3v9rpqqxxzmCAd9Hs"
words = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o"]
factory = AccountFactoryED25519('L')
def brute_force():
for seed in permutations(words):
account = factory.create_from_seed(" ".join(seed))
if (account.address == address):
return seed
return None
found = brute_force()
if found:
print(" ".join(found))
else:
print("No seed found that matches address %s :-(" % address)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment