<commit_before>package brutedict

import (
	"log"
	"math/big"

	"github.com/aaronang/cong-the-ripper/lib"
)

type BruteDict struct {
	*lib.Task
	remaining   int
	currentComb *big.Int
}

func New(task *lib.Task) (bd *BruteDict) {
	bd = &BruteDict{
		Task:        task,
		remaining:   task.TaskLen,
		currentComb: lib.BytesToBigInt(task.Alphabet, task.Start),
	}

	if task.Progress != nil || len(task.Progress) > 0 {
		progressComb := lib.BytesToBigInt(task.Alphabet, task.Progress)
		progressLen := big.NewInt(0)
		progressLen.Sub(progressComb, bd.currentComb)

		bd.remaining = bd.remaining - int(progressLen.Int64())
		if bd.remaining < 0 {
			log.Panic("[brutedict] bd.remaining is negative!", bd.remaining)
		}
		bd.currentComb = progressComb
	}

	return
}

func (bd *BruteDict) Next() (candidate []byte) {
	if bd.remaining <= 0 {
		return nil
	}

	pwLen := len(bd.Start)
	byteArray, overflow := lib.BigIntToBytes(bd.Alphabet, bd.currentComb, pwLen)<commit_msg>Bug in progress computation condition<commit_after>package brutedict

import (
	"log"
	"math/big"

	"github.com/aaronang/cong-the-ripper/lib"
)

type BruteDict struct {
	*lib.Task
	remaining   int
	currentComb *big.Int
}

func New(task *lib.Task) (bd *BruteDict) {
	bd = &BruteDict{
		Task:        task,
		remaining:   task.TaskLen,
		currentComb: lib.BytesToBigInt(task.Alphabet, task.Start),
	}

	if len(task.Progress) > 0 {
		progressComb := lib.BytesToBigInt(task.Alphabet, task.Progress)
		progressLen := big.NewInt(0)
		progressLen.Sub(progressComb, bd.currentComb)

		bd.remaining = bd.remaining - int(progressLen.Int64())
		if bd.remaining < 0 {
			log.Panic("[brutedict] bd.remaining is negative!", bd.remaining)
		}
		bd.currentComb = progressComb
	}

	return
}

func (bd *BruteDict) Next() (candidate []byte) {
	if bd.remaining <= 0 {
		return nil
	}

	pwLen := len(bd.Start)
	byteArray, overflow := lib.BigIntToBytes(bd.Alphabet, bd.currentComb, pwLen)
{'fraction_non_alphanumeric': 0.137448132780083, 'fraction_numerical': 0.006224066390041493, 'mean_word_length': 3.9716494845360826, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2247699', 'n_tokens_mistral': 790, 'n_tokens_neox': 743, 'n_words': 145}