public static Strength mostGuessableMatchSequence(String password, List<Match> matches) { return mostGuessableMatchSequence(password, matches, false); }
private static void bruteforceUpdate(String password, int k, Optimal optimal, boolean excludeAdditive) { Match m = makeBruteforceMatch(password, 0, k); update(password, m, 1, optimal, excludeAdditive); for (int i = 1; i <= k; i++) { m = makeBruteforceMatch(password, i, k); for (Map.Entry<Integer, Match> entry : optimal.m.get(i - 1).entrySet()) { int l = entry.getKey(); Match last_m = entry.getValue(); if (last_m.pattern == Pattern.Bruteforce) { continue; } else { update(password, m, l + 1, optimal, excludeAdditive); } } } }
for(Map.Entry<Integer, Match> entry : optimal.m.get(m.i - 1).entrySet()) { int l = entry.getKey(); update(password, m, l + 1, optimal, excludeAdditive); update(password, m, 1, optimal, excludeAdditive); bruteforceUpdate(password, k, optimal, excludeAdditive); List<Match> optimalMatchSequence = unwind(n, optimal); Integer optimalL = optimalMatchSequence.size(); double guesses = password.length() == 0 ? 1 : optimal.g.get(n - 1).get(optimalL); strength.setPassword(password); strength.setGuesses(guesses); strength.setGuessesLog10(log10(guesses)); strength.setSequence(optimalMatchSequence); return strength;
@Override public double exec(Match match) { if (match.guesses != null) return match.guesses; int minGuesses = 1; if (match.token.length() < password.length()) { minGuesses = match.token.length() == 1 ? MIN_SUBMATCH_GUESSES_SINGLE_CHAR : MIN_SUBMATCH_GUESSES_MULTI_CHAR; } final Guess guess; switch (match.pattern) { case Bruteforce: guess = new BruteforceGuess(); break; case Dictionary: guess = new DictionaryGuess(); break; case Spatial: guess = new SpatialGuess(); break; case Repeat: guess = new RepeatGuess(); break; case Sequence: guess = new SequenceGuess(); break; case Regex: guess = new RegexGuess(); break; case Date: guess = new DateGuess(); break; default: guess = null; break; } double guesses = guess != null ? guess.exec(match) : 0; match.guesses = Math.max(guesses, minGuesses); match.guessesLog10 = Scoring.log10(match.guesses); return match.guesses; } }
pi = Double.MAX_VALUE; double g = factorial(l) * pi; if (Double.isInfinite(g)) { g = Double.MAX_VALUE;
for(Map.Entry<Integer, Match> entry : optimal.m.get(m.i - 1).entrySet()) { int l = entry.getKey(); update(password, m, l + 1, optimal, excludeAdditive); update(password, m, 1, optimal, excludeAdditive); bruteforceUpdate(password, k, optimal, excludeAdditive); List<Match> optimalMatchSequence = unwind(n, optimal); Integer optimalL = optimalMatchSequence.size(); double guesses = password.length() == 0 ? 1 : optimal.g.get(n - 1).get(optimalL); strength.setPassword(password); strength.setGuesses(guesses); strength.setGuessesLog10(log10(guesses)); strength.setSequence(optimalMatchSequence); return strength;
@Override public double exec(Match match) { if (match.guesses != null) return match.guesses; int minGuesses = 1; if (match.token.length() < password.length()) { minGuesses = match.token.length() == 1 ? MIN_SUBMATCH_GUESSES_SINGLE_CHAR : MIN_SUBMATCH_GUESSES_MULTI_CHAR; } final Guess guess; switch (match.pattern) { case Bruteforce: guess = new BruteforceGuess(); break; case Dictionary: guess = new DictionaryGuess(); break; case Spatial: guess = new SpatialGuess(); break; case Repeat: guess = new RepeatGuess(); break; case Sequence: guess = new SequenceGuess(); break; case Regex: guess = new RegexGuess(); break; case Date: guess = new DateGuess(); break; default: guess = null; break; } double guesses = guess != null ? guess.exec(match) : 0; match.guesses = Math.max(guesses, minGuesses); match.guessesLog10 = Scoring.log10(match.guesses); return match.guesses; } }
pi = Double.MAX_VALUE; double g = factorial(l) * pi; if (Double.isInfinite(g)) { g = Double.MAX_VALUE;
public static Strength mostGuessableMatchSequence(String password, List<Match> matches) { return mostGuessableMatchSequence(password, matches, false); }
private static void bruteforceUpdate(String password, int k, Optimal optimal, boolean excludeAdditive) { Match m = makeBruteforceMatch(password, 0, k); update(password, m, 1, optimal, excludeAdditive); for (int i = 1; i <= k; i++) { m = makeBruteforceMatch(password, i, k); for (Map.Entry<Integer, Match> entry : optimal.m.get(i - 1).entrySet()) { int l = entry.getKey(); Match last_m = entry.getValue(); if (last_m.pattern == Pattern.Bruteforce) { continue; } else { update(password, m, l + 1, optimal, excludeAdditive); } } } }
Strength baseAnalysis = Scoring.mostGuessableMatchSequence(baseToken, new Matching(new ArrayList<String>()).omnimatch(baseToken)); List<Match> baseMatches = baseAnalysis.getSequence(); double baseGuesses = baseAnalysis.getGuesses();
Strength baseAnalysis = Scoring.mostGuessableMatchSequence(baseToken, new Matching(new ArrayList<String>()).omnimatch(baseToken)); List<Match> baseMatches = baseAnalysis.getSequence(); double baseGuesses = baseAnalysis.getGuesses();
public Strength measure(String password, List<String> sanitizedInputs) { if (password == null) { throw new IllegalArgumentException("Password is null."); } List<String> lowerSanitizedInputs; if (sanitizedInputs != null && !sanitizedInputs.isEmpty()) { lowerSanitizedInputs = new ArrayList<>(sanitizedInputs.size()); for (String sanitizedInput : sanitizedInputs) { lowerSanitizedInputs.add(sanitizedInput.toLowerCase()); } } else { lowerSanitizedInputs = Collections.emptyList(); } long start = time(); Matching matching = createMatching(lowerSanitizedInputs); List<Match> matches = matching.omnimatch(password); Strength strength = Scoring.mostGuessableMatchSequence(password, matches); strength.setCalcTime(time() - start); AttackTimes attackTimes = TimeEstimates.estimateAttackTimes(strength.getGuesses()); strength.setCrackTimeSeconds(attackTimes.getCrackTimeSeconds()); strength.setCrackTimesDisplay(attackTimes.getCrackTimesDisplay()); strength.setScore(attackTimes.getScore()); strength.setFeedback(Feedback.getFeedback(strength.getScore(), strength.getSequence())); return strength; }
public Strength measure(String password, List<String> sanitizedInputs) { if (password == null) { throw new IllegalArgumentException("Password is null."); } List<String> lowerSanitizedInputs; if (sanitizedInputs != null && !sanitizedInputs.isEmpty()) { lowerSanitizedInputs = new ArrayList<>(sanitizedInputs.size()); for (String sanitizedInput : sanitizedInputs) { lowerSanitizedInputs.add(sanitizedInput.toLowerCase()); } } else { lowerSanitizedInputs = Collections.emptyList(); } long start = time(); Matching matching = createMatching(lowerSanitizedInputs); List<Match> matches = matching.omnimatch(password); Strength strength = Scoring.mostGuessableMatchSequence(password, matches); strength.setCalcTime(time() - start); AttackTimes attackTimes = TimeEstimates.estimateAttackTimes(strength.getGuesses()); strength.setCrackTimeSeconds(attackTimes.getCrackTimeSeconds()); strength.setCrackTimesDisplay(attackTimes.getCrackTimesDisplay()); strength.setScore(attackTimes.getScore()); strength.setFeedback(Feedback.getFeedback(strength.getScore(), strength.getSequence())); return strength; }
@Test public void testRepeatGuesses() throws Exception { double baseGuesses = Scoring.mostGuessableMatchSequence( baseToken, new Matching().omnimatch(baseToken)).getGuesses(); Match match = new Match.Builder(Pattern.Repeat, 0, 0, token) .baseToken(baseToken) .baseGuesses(baseGuesses) .repeatCount(repeatCount) .build(); double expectedGuesses = baseGuesses * repeatCount; String msg = String.format("the repeat pattern '%s' has guesses of %s", token, expectedGuesses); assertEquals(msg, expectedGuesses, new RepeatGuess().exec(match), 0.0); }