/// <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 MakesBaseGuessesEqualTheRank() { var match = new DictionaryMatch { Token = "aaaaa", Rank = 32, DictionaryName = "dic", i = 1, j = 2, L33t = false, MatchedWord = "a", Reversed = false, }; var expected = 32; var actual = DictionaryGuessesCalculator.CalculateGuesses(match); actual.Should().Be(expected); }
public void AddsExtraGuessesForCapitilization() { var match = new DictionaryMatch { Token = "AAAaaa", Rank = 32, DictionaryName = "dic", i = 1, j = 2, L33t = false, MatchedWord = "a", Reversed = false, }; var expected = 32 * DictionaryGuessesCalculator.UppercaseVariations(match.Token); var actual = DictionaryGuessesCalculator.CalculateGuesses(match); actual.Should().Be(expected); }
public void AddsDoubleGuessesForReversedWords() { var match = new DictionaryMatch { Token = "aaaaa", Rank = 32, DictionaryName = "dic", i = 1, j = 2, L33t = false, MatchedWord = "a", Reversed = true, }; var expected = 32 * 2; var actual = DictionaryGuessesCalculator.CalculateGuesses(match); actual.Should().Be(expected); }
public void AddsExtraGuessesForCommonL33tSubstitutions() { var match = new DictionaryMatch { Token = "aaa@@@", Rank = 32, DictionaryName = "dic", i = 1, j = 2, L33t = true, MatchedWord = "a", Reversed = false, L33tSubs = new Dictionary <char, char> { { '@', 'a' } }, }; var expected = 32 * DictionaryGuessesCalculator.L33tVariations(match); var actual = DictionaryGuessesCalculator.CalculateGuesses(match); actual.Should().Be(expected); }
public void IgnoresCapitilizationForL33tVariations() { var expected = 21; var match = new DictionaryMatch { Token = "Aa44aA", Rank = 32, DictionaryName = "dic", i = 1, j = 2, L33t = true, MatchedWord = "a", Reversed = false, L33tSubs = new Dictionary <char, char>() { { '4', 'a' } }, }; var actual = DictionaryGuessesCalculator.L33tVariations(match); actual.Should().Be(expected); }
public void GetsCorrectUppercaseVariantsMultipler(string word, int expected) { var actual = DictionaryGuessesCalculator.UppercaseVariations(word); actual.Should().Be(expected); }
public void GetsCorrectL33tVariantsForWord() { var expected = 1; var match = new DictionaryMatch { Token = string.Empty, Rank = 32, DictionaryName = "dic", i = 1, j = 2, L33t = false, MatchedWord = "a", Reversed = false, L33tSubs = new Dictionary <char, char>(), }; var actual = DictionaryGuessesCalculator.L33tVariations(match); actual.Should().Be(expected); expected = 1; match = new DictionaryMatch { Token = "a", Rank = 32, DictionaryName = "dic", i = 1, j = 2, L33t = false, MatchedWord = "a", Reversed = false, L33tSubs = new Dictionary <char, char>(), }; actual = DictionaryGuessesCalculator.L33tVariations(match); actual.Should().Be(expected); expected = 1; match = new DictionaryMatch { Token = "abcet", Rank = 32, DictionaryName = "dic", i = 1, j = 2, L33t = false, MatchedWord = "a", Reversed = false, L33tSubs = new Dictionary <char, char>(), }; actual = DictionaryGuessesCalculator.L33tVariations(match); actual.Should().Be(expected); expected = 2; match = new DictionaryMatch { Token = "4", Rank = 32, DictionaryName = "dic", i = 1, j = 2, L33t = true, MatchedWord = "a", Reversed = false, L33tSubs = new Dictionary <char, char>() { { '4', 'a' } }, }; actual = DictionaryGuessesCalculator.L33tVariations(match); actual.Should().Be(expected); expected = 2; match = new DictionaryMatch { Token = "4pple", Rank = 32, DictionaryName = "dic", i = 1, j = 2, L33t = true, MatchedWord = "a", Reversed = false, L33tSubs = new Dictionary <char, char>() { { '4', 'a' } }, }; actual = DictionaryGuessesCalculator.L33tVariations(match); actual.Should().Be(expected); expected = 2; match = new DictionaryMatch { Token = "4bcet", Rank = 32, DictionaryName = "dic", i = 1, j = 2, L33t = true, MatchedWord = "a", Reversed = false, L33tSubs = new Dictionary <char, char>() { { '4', 'a' } }, }; actual = DictionaryGuessesCalculator.L33tVariations(match); actual.Should().Be(expected); expected = 2; match = new DictionaryMatch { Token = "a8cet", Rank = 32, DictionaryName = "dic", i = 1, j = 2, L33t = true, MatchedWord = "a", Reversed = false, L33tSubs = new Dictionary <char, char>() { { '8', 'b' } }, }; actual = DictionaryGuessesCalculator.L33tVariations(match); actual.Should().Be(expected); expected = 2; match = new DictionaryMatch { Token = "abce+", Rank = 32, DictionaryName = "dic", i = 1, j = 2, L33t = true, MatchedWord = "a", Reversed = false, L33tSubs = new Dictionary <char, char>() { { '+', 't' } }, }; actual = DictionaryGuessesCalculator.L33tVariations(match); actual.Should().Be(expected); expected = 4; match = new DictionaryMatch { Token = "48cet", Rank = 32, DictionaryName = "dic", i = 1, j = 2, L33t = true, MatchedWord = "a", Reversed = false, L33tSubs = new Dictionary <char, char>() { { '4', 'a' }, { '8', 'b' } }, }; actual = DictionaryGuessesCalculator.L33tVariations(match); actual.Should().Be(expected); expected = 21; match = new DictionaryMatch { Token = "a4a4aa", Rank = 32, DictionaryName = "dic", i = 1, j = 2, L33t = true, MatchedWord = "a", Reversed = false, L33tSubs = new Dictionary <char, char>() { { '4', 'a' } }, }; actual = DictionaryGuessesCalculator.L33tVariations(match); actual.Should().Be(expected); expected = 21; match = new DictionaryMatch { Token = "4a4a44", Rank = 32, DictionaryName = "dic", i = 1, j = 2, L33t = true, MatchedWord = "a", Reversed = false, L33tSubs = new Dictionary <char, char>() { { '4', 'a' } }, }; actual = DictionaryGuessesCalculator.L33tVariations(match); actual.Should().Be(expected); expected = 30; match = new DictionaryMatch { Token = "a44att+", Rank = 32, DictionaryName = "dic", i = 1, j = 2, L33t = true, MatchedWord = "a", Reversed = false, L33tSubs = new Dictionary <char, char>() { { '4', 'a' }, { '+', 't' } }, }; actual = DictionaryGuessesCalculator.L33tVariations(match); actual.Should().Be(expected); }