staafl

brute force timing

Aug 21st, 2013
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. static void Main()
  2. {
  3. var sw = Stopwatch.StartNew();
  4. int attempt = 0;
  5. foreach (var str in Strings(8)) {
  6. ++attempt;
  7. if (attempt > 1000*1000)
  8. break;
  9. PasswordCheck.IsCorrect(str);
  10. }
  11. sw.Stop();
  12.  
  13. // attempts per second
  14. Console.WriteLine(1000.0*1000 / sw.Elapsed.TotalSeconds);
  15.  
  16. }
  17.  
  18. static IEnumerable<string> Strings(int length, StringBuilder sb = null)
  19. {
  20. if (length == 0) {
  21. if (sb == null)
  22. yield return "";
  23. else
  24. yield return sb.ToString();
  25. yield break;
  26. }
  27. if (sb == null) {
  28. sb = new StringBuilder();
  29. }
  30. // password is not necessarily a-z!
  31. for (char ch = 'a'; ch <= 'z'; ++ch)
  32. {
  33. sb.Append(ch);
  34. foreach (var str in Strings(length - 1, sb)) {
  35. yield return str;
  36. }
  37. sb.Remove(sb.Length - 1, 1);
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment