0

I am trying to write a script that creates all permutations of words, with a few in set positions. I'm basically trying to recover my 12 word mnemonic seed, in which i have a few extra letters but I know the position of a few for example, I know that word 1 is wild and word 5 is script and the last word is hurt. and I have 15 words that I want to try permutations on, so that I get

wild permword1 permword2 permword3 script permword6 permword7 permword8 permword9 permword10 permword11 hurt

` I have basic knowledge of python. I only know how to just print all the permutations of the words, however that takes longer and also prints some that wouldn't even be a possibility because one of the permutations has word 5 at a different position. I have my list of words, I'm just trying to recover my mnemonic seed in a much more efficient way, because I'm ending up creating so many permutations that my laptop runs out of space. I'm not looking to be reccomended btcrecover as I have a few issues with it.

Ideally I'd get a list like,

wild permword1 permword2 permword3 script permword6 permword7 permword8 permword9 permword10 permword11 hurt

wild permword1 permword2 permword3 script permword6 permword7 permword8 permword9 permword10 permword12 hurt

wild permword1 permword2 permword3 script permword6 permword7 permword8 permword9 permword10 permword13 hurt

I appreciate in advance!

just regular permutations, but i'm unsure of how to split ther words so that word 5 is always script.

  • 2
    If your "laptop runs out of space", you're likely doing it wrong. But hard to tell when you don't show your code. – Kelly Bundy Feb 23 '23 at 16:34
  • Also, it seems like you've found the seed phrase to a wallet but you do not know the position of the words yet. – suchislife Feb 24 '23 at 02:10

1 Answers1

2

Generators

I guess that the reason your computer is running out of "space" is that you keep all created permutations in memory at once. This is a perfect use case for generators in python. You can think of generators as rules to create some value given an index value, instead of creating everything at once. See for example here: Understanding generators in Python

Set values in permutations

As to the words at set positions, you can just create a list for each permutation and then insert your pre-set words.

Solution

I think the following code solves your problem. In the last line, I print the permutation, you can replace this with whatever you want to do with each permutation.

import itertools

permwords = [f"permword{ind+1}" for ind in range(0,15)]

def produce_partially_set(worlist):
    worlist.insert(0, "wild")
    worlist.insert(4, "script")
    worlist.append("hurt")
    return worlist

indices_perm = itertools.permutations(range(0,12)) # 12 unknown words in "solution"
while True:
    indices = next(indices_perm)
    permutation = [permwords[x] for x in indices]
    mneumonic_seed = produce_partially_set(permutation)
    print(mneumonic_seed)

PS: the code will throw a "StopIteration", once it iterated through all possible permutations.

mafe
  • 76
  • 7
  • 1
    Doesn't make any sense to wrap the iterator in a generator. That just slows it down. And why not use a `for` loop instead of the `while` loop? – Kelly Bundy Feb 23 '23 at 17:30
  • I was not aware that itertools.permutations could be used directly and adapted my answer. Thanks for the insight! – mafe Feb 23 '23 at 17:47
  • 1
    why not do `for indices in itertools.permutations(range(0, 12))` instead of `while True:` – Tom McLean Feb 23 '23 at 17:54
  • I thought that this way the nature of generators is more explicit and clearer to OP, but you are right, that would be more concise and I guess also faster. – mafe Feb 23 '23 at 17:57
  • i did this but it did not go through all 15 words, the script produced permutations of 12 words as if I only had 12 and not 15 words to permutate through. Meaning that the later words weren't even included. – Dasher Love Feb 25 '23 at 15:30
  • Did you insert the known words at the position you know they are in as in the function `produce_partially_set()` ? Because all you need are permutations of 12 words and then insert your known words at their respective position – mafe Feb 26 '23 at 13:21
  • I have a total of 18 words, mnemonic seeds are 12 words long ( I have extra words, because I'm not sure if they are belong or not. I want all try all candidates (15 words) for the remaining 9 words in seed. Not sure if i was clear before. – Dasher Love Mar 01 '23 at 12:32