Files
SnowLuma/.pnpm-store/v11/files/b0/4813a1d7ee55620575366fa4d9acd2c167e9ff112f63be9cb2501648cca0bb25a9df1621fb6a658b8c3c5399b85a02cdf5b27e628974870a6b82a2c7fc9e41
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

77 lines
2.6 KiB
Plaintext

'use strict';
var _const = require('../data/const.cjs');
var utils = require('./utils.cjs');
var scoring$8 = require('../matcher/bruteforce/scoring.cjs');
var scoring$7 = require('../matcher/date/scoring.cjs');
var scoring$6 = require('../matcher/dictionary/scoring.cjs');
var scoring$5 = require('../matcher/regex/scoring.cjs');
var scoring$4 = require('../matcher/repeat/scoring.cjs');
var scoring$3 = require('../matcher/sequence/scoring.cjs');
var scoring$2 = require('../matcher/spatial/scoring.cjs');
var scoring$1 = require('../matcher/separator/scoring.cjs');
var scoring = require('../matcher/wordSequence/scoring.cjs');
const getMinGuesses = (match, password) => {
let minGuesses = 1;
if (match.token.length < password.length) {
if (match.token.length === 1) {
minGuesses = _const.MIN_SUBMATCH_GUESSES_SINGLE_CHAR;
} else {
minGuesses = _const.MIN_SUBMATCH_GUESSES_MULTI_CHAR;
}
}
return minGuesses;
};
const matchers = {
bruteforce: scoring$8,
date: scoring$7,
dictionary: scoring$6,
regex: scoring$5,
repeat: scoring$4,
sequence: scoring$3,
spatial: scoring$2,
separator: scoring$1,
wordSequence: scoring
};
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)
};
};
module.exports = estimateGuesses;
//# sourceMappingURL=estimate.cjs.map