private static void Main(string[] args) > { > Stopwatch watch = new Stopwatch(); > watch.Start(); > foreach (string s in GetValidPasswordList()) > { > Console.WriteLine(s); > } > Console.WriteLine(watch.Elapsed); > Console.ReadLine(); > } > > public static IEnumerable<string> GetValidPasswordList() > { > int total = 0; > for (int x = 1; x<63; x++) > { > for (int y = 1; y<63; y++) > { > for (int z = 0; z < ((y < 53 && x < 53) ? 63 : 11); z++) //24 seconds > //for (int z = 0; z < 63; z++ ) // 31 seconds > { > yield return string.Format("{0}.{1}.{2} (Total:{3})", x, y, z, total++); > } > } > } > }>Couldn't be bothered with real chars but the principle's the same. 24 seconds v 31
delegate IEnumerable<string> TheMethod(); public static class AClass { static long Total = 0L; static string AlphaDigit = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; static string Alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; public static void Main() { string s = null; TheMethod[] list = { GetValidPasswordList, Possibilities, ListPossibilities }; foreach (TheMethod method in list) { foreach (string x in method()) { s = x; } Console.WriteLine("Method {0} {1}", method.GetInvocationList()[0].Method.Name, s); } Console.WriteLine("password 6 with at least one upper and at least one lower {0}", Password6()); Console.ReadLine(); } static IEnumerable<string> Possibilities() { Total = 0; // 1- 10 is digit // 11 - 62 is a-zA-Z for (int i = 1; i < 63; i++) for (int j = 1; j < 63; j++) for (int k = 1; k < 63; k++) if (i > 10 && j > 10 && k > 10) continue; else yield return String.Format("{0} {1} {2} Total {3}", i, j, k, ++Total); } static IEnumerable<string> ListPossibilities() { Total = 0; int len = AlphaDigit.Length ; Debug.Assert(AlphaDigit.Length == 62); char a, b, c ; for( int i = 0; i < len; i++ ) { a = AlphaDigit[i]; for( int j = 0; j < len; j++ ) { b = AlphaDigit[j]; for (int k = 0; k < len; k++) { c = AlphaDigit[k]; if (!Char.IsDigit(a) && !Char.IsDigit(b) && !Char.IsDigit(c)) continue; else yield return String.Format("{0} {1} {2} Total {3}", a, b, c, ++Total); } } } } public static IEnumerable<string> GetValidPasswordList() { Total = 0; for (int x = 1; x < 63; x++) { for (int y = 1; y < 63; y++) { for (int z = 0; z < ((y < 53 && x < 53) ? 63 : 11); z++) //24 seconds //for (int z = 0; z < 63; z++ ) // 31 seconds { yield return string.Format("{0}.{1}.{2} (Total:{3})", x, y, z, ++Total); } } } } static double Password6() { decimal total = 0m; int len = Alpha.Length; for (int l1 = len; --l1 >= 0; ) { char c1 = Alpha[l1]; Console.WriteLine(l1); for (int l2 = len; --l2 >= 0; ) { char c2 = Alpha[l2]; for (int l3 = len; --l3 >= 0; ) { char c3 = Alpha[l3]; for (int l4 = len; --l4 >= 0; ) { char c4 = Alpha[l4]; for (int l5 = len; --l5 >= 0; ) { char c5 = Alpha[l5]; for (int l6 = len; --l6 >= 0; ) { char c6 = Alpha[l6]; if (!Char.IsLower(c1) && !Char.IsLower(c2) && !Char.IsLower(c3) && !Char.IsLower(c4) && !Char.IsLower(c5) && !Char.IsLower(c6) ) continue; if (!Char.IsUpper(c1) && !Char.IsUpper(c2) && !Char.IsUpper(c3) && !Char.IsUpper(c4) && !Char.IsUpper(c5) && !Char.IsUpper(c6) ) continue; total++; } } } } } } return (double)total; } }