75 lines
2.7 KiB
Plaintext
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
|