Files
SnowLuma/.pnpm-store/v11/files/b2/c0ee48634f4e4dfd476271da2f9b3ffee84df272847a2a6261e67609380ec0874f5007a6008fe2c12dd2e68c8f21ab1397b4c8f6bdcf9ce4598c4497f50917
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

75 lines
2.7 KiB
Plaintext

import { MIN_SUBMATCH_GUESSES_SINGLE_CHAR, MIN_SUBMATCH_GUESSES_MULTI_CHAR } from '../data/const.mjs';
import utils from './utils.mjs';
import bruteforceMatcher from '../matcher/bruteforce/scoring.mjs';
import dateMatcher from '../matcher/date/scoring.mjs';
import dictionaryMatcher from '../matcher/dictionary/scoring.mjs';
import regexMatcher from '../matcher/regex/scoring.mjs';
import repeatMatcher from '../matcher/repeat/scoring.mjs';
import sequenceMatcher from '../matcher/sequence/scoring.mjs';
import spatialMatcher from '../matcher/spatial/scoring.mjs';
import separatorMatcher from '../matcher/separator/scoring.mjs';
import wordSequenceMatcher from '../matcher/wordSequence/scoring.mjs';
const getMinGuesses = (match, password) => {
let minGuesses = 1;
if (match.token.length < password.length) {
if (match.token.length === 1) {
minGuesses = MIN_SUBMATCH_GUESSES_SINGLE_CHAR;
} else {
minGuesses = MIN_SUBMATCH_GUESSES_MULTI_CHAR;
}
}
return minGuesses;
};
const matchers = {
bruteforce: bruteforceMatcher,
date: dateMatcher,
dictionary: dictionaryMatcher,
regex: regexMatcher,
repeat: repeatMatcher,
sequence: sequenceMatcher,
spatial: spatialMatcher,
separator: separatorMatcher,
wordSequence: wordSequenceMatcher
};
const getScoring = (options, name, match) => {
if (matchers[name]) {
return matchers[name](match, options);
}
if (options.matchers[name] && 'scoring' in options.matchers[name]) {
return options.matchers[name].scoring(match, options);
}
return 0;
};
// ------------------------------------------------------------------------------
// guess estimation -- one function per match pattern ---------------------------
// ------------------------------------------------------------------------------
var estimateGuesses = (options, match, password) => {
const extraData = {};
// a match's guess estimate doesn't change. cache it.
if ('guesses' in match && match.guesses != null) {
return match;
}
const minGuesses = getMinGuesses(match, password);
const estimationResult = getScoring(options, match.pattern, match);
let guesses = 0;
if (typeof estimationResult === 'number') {
guesses = estimationResult;
} else if (match.pattern === 'dictionary') {
guesses = estimationResult.calculation;
extraData.baseGuesses = estimationResult.baseGuesses;
extraData.uppercaseVariations = estimationResult.uppercaseVariations;
extraData.l33tVariations = estimationResult.l33tVariations;
}
const matchGuesses = Math.max(guesses, minGuesses);
return {
...match,
...extraData,
guesses: matchGuesses,
guessesLog10: utils.log10(matchGuesses)
};
};
export { estimateGuesses as default };
//# sourceMappingURL=estimate.mjs.map