/// <summary> /// Estimates the attempts required to guess the password. /// </summary> /// <param name="match">The match.</param> /// <param name="password">The actual password.</param> /// <returns>The guesses estimate.</returns> public static double EstimateGuesses(Match match, string password) { if (match.Guesses != 0) { return(match.Guesses); } var minGuesses = 1.0; if (match.Token.Length < password.Length) { minGuesses = match.Token.Length == 1 ? BruteForceGuessesCalculator.MinSubmatchGuessesSingleCharacter : BruteForceGuessesCalculator.MinSubmatchGuessesMultiCharacter; } var guesses = 0.0; switch (match.Pattern) { case "bruteforce": guesses = BruteForceGuessesCalculator.CalculateGuesses(match as BruteForceMatch); break; case "date": guesses = DateGuessesCalculator.CalculateGuesses(match as DateMatch); break; case "dictionary": guesses = DictionaryGuessesCalculator.CalculateGuesses(match as DictionaryMatch); break; case "regex": guesses = RegexGuessesCalculator.CalculateGuesses(match as RegexMatch); break; case "repeat": guesses = RepeatGuessesCalculator.CalculateGuesses(match as RepeatMatch); break; case "sequence": guesses = SequenceGuessesCalculator.CalculateGuesses(match as SequenceMatch); break; case "spatial": guesses = SpatialGuessesCalculator.CalculateGuesses(match as SpatialMatch); break; } match.Guesses = Math.Max(guesses, minGuesses); return(match.Guesses); }
public void IsDelegatedToByEstimateGuesses() { var match = new SequenceMatch { Token = "ab", Ascending = true, i = 1, j = 2, SequenceName = "abc", SequenceSpace = 1, }; var actual = SequenceGuessesCalculator.CalculateGuesses(match); actual.Should().Be(8); }
public void CalculatesTheCorrectNumberOfGuesses(string token, bool ascending, int expected) { var match = new SequenceMatch { Token = token, Ascending = ascending, i = 1, j = 2, SequenceName = "abc", SequenceSpace = 1, }; var actual = SequenceGuessesCalculator.CalculateGuesses(match); actual.Should().Be(expected); }