Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep token order #439

Merged
merged 3 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions btcrecover/btcrpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -2760,6 +2760,8 @@ class WalletDogechain(object):
_savepossiblematches = True
_possible_passwords_file = "possible_passwords.log"

matchStrings = b"\"guid\"|\"sharedKey\"|\"keys\""

_dump_privkeys_file = None
_dump_wallet_file = None
_using_extract = False
Expand Down Expand Up @@ -5752,6 +5754,8 @@ def parse_arguments(effective_argv, wallet = None, base_iterator = None,
help="enforce a min # of tokens included per guess")
parser.add_argument("--seedgenerator", action="store_true",
help=argparse.SUPPRESS) # Flag to be able to indicate to generators that we are doing seed generation, not password generation
parser.add_argument("--keep-tokens-order", action="store_true",
help="try tokens in the order in which they are listed in the file, without trying their permutations")
parser.add_argument("--mnemonic-length", type=int,
help=argparse.SUPPRESS) # Argument used for generators in seed generation, not password generation
parser.add_argument("--seed-transform-wordswaps", type=int,
Expand Down Expand Up @@ -7435,15 +7439,6 @@ def tokenlist_base_password_generator():
l_seed_generator = args.seedgenerator
l_mnemonic_length = args.mnemonic_length

# Temporary Fix for the "--keep-tokens-order" argument.
# Hasn't been fully tested in BTCRecover.py and breaks seedrecover...
try:
if args.keep_tokens_order:
pass
except:
if l_seed_generator:
args.keep_tokens_order = False

# Choose between the custom duplicate-checking and the standard itertools permutation
# functions for the outer loop unless the custom one has been specifically disabled
# with three (or more) --no-dupcheck options.
Expand Down
8 changes: 7 additions & 1 deletion btcrecover/btcrseed.py
Original file line number Diff line number Diff line change
Expand Up @@ -2958,7 +2958,7 @@ def replace_wrong_word(mnemonic_ids, i):
# full word list, and significantly increases the search time
# min_typos - min number of mistakes to apply to each guess
num_inserts = num_deletes = 0
def run_btcrecover(typos, big_typos = 0, min_typos = 0, is_performance = False, extra_args = [], tokenlist = None, passwordlist = None, listpass = None, min_tokens = None, max_tokens = None, mnemonic_length = None, seed_transform_wordswaps = None):
def run_btcrecover(typos, big_typos = 0, min_typos = 0, is_performance = False, extra_args = [], tokenlist = None, passwordlist = None, listpass = None, min_tokens = None, max_tokens = None, mnemonic_length = None, seed_transform_wordswaps = None, keep_tokens_order = False):
if typos < 0: # typos == 0 is silly, but causes no harm
raise ValueError("typos must be >= 0")
if big_typos < 0:
Expand Down Expand Up @@ -2994,6 +2994,9 @@ def run_btcrecover(typos, big_typos = 0, min_typos = 0, is_performance = False,
btcr_args += " --seedgenerator"
btcr_args += " --mnemonic-length " + str(mnemonic_length)

if keep_tokens_order:
btcr_args += " --keep-tokens-order"

if passwordlist:
btcr_args += " --passwordlist " + str(passwordlist)
btcr_args += " --seedgenerator"
Expand Down Expand Up @@ -3182,6 +3185,8 @@ def main(argv):
parser.add_argument("--version","-v",action="store_true", help="show full version information and exit")
parser.add_argument("--disablesecuritywarnings", "--dsw", action="store_true", help="Disable Security Warning Messages")
parser.add_argument("--tokenlist", metavar="FILE", help="The list of BIP39 words to be searched, formatted as a tokenlist")
parser.add_argument("--keep-tokens-order", action="store_true",
help="try tokens in the order in which they are listed in the file, without trying their permutations")
parser.add_argument("--max-tokens", type=int, help="The max number of tokens use to create potential seeds from the tokenlist")
parser.add_argument("--min-tokens", type=int, help="The minimum number of tokens use to create potential seeds from the tokenlist")
parser.add_argument("--seedlist", metavar="FILE", nargs="?", const="-",
Expand Down Expand Up @@ -3379,6 +3384,7 @@ def main(argv):
phase["max_tokens"] = args.max_tokens
phase["min_tokens"] = args.min_tokens
phase["mnemonic_length"] = args.mnemonic_length
phase["keep_tokens_order"] = args.keep_tokens_order

if args.tokenlist:
phase["tokenlist"] = args.tokenlist
Expand Down
5 changes: 5 additions & 0 deletions btcrecover/test/test_passwords.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ def test_password_repeats_x3(self):
["one", "oneone", "oneoneone"],
"--password-repeats-posttypos --max-password-repeats 3")

def test_keep_tokens_order(self):
self.do_generator_test(["one", "two", "three"],
['one', 'two', 'onetwo', 'three', 'onethree', 'twothree', 'onetwothree'],
"--keep-tokens-order")

def test_empty_file(self):
self.do_generator_test([], [], test_passwordlist=True)
def test_one_char_file(self):
Expand Down
Loading