Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main()
- {
- var sw = Stopwatch.StartNew();
- int attempt = 0;
- foreach (var str in Strings(8)) {
- ++attempt;
- if (attempt > 1000*1000)
- break;
- PasswordCheck.IsCorrect(str);
- }
- sw.Stop();
- // attempts per second
- Console.WriteLine(1000.0*1000 / sw.Elapsed.TotalSeconds);
- }
- static IEnumerable<string> Strings(int length, StringBuilder sb = null)
- {
- if (length == 0) {
- if (sb == null)
- yield return "";
- else
- yield return sb.ToString();
- yield break;
- }
- if (sb == null) {
- sb = new StringBuilder();
- }
- // password is not necessarily a-z!
- for (char ch = 'a'; ch <= 'z'; ++ch)
- {
- sb.Append(ch);
- foreach (var str in Strings(length - 1, sb)) {
- yield return str;
- }
- sb.Remove(sb.Length - 1, 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment