WEB开发网
开发学院WEB开发ASP.NET 暴力破解算法 阅读

暴力破解算法

 2012-05-18 17:03:48 来源:WEB开发网   
核心提示:static void Main(string[] args) { Console.WriteLine(DateTime.Now.Ticks); int maxLength = 10; CrackPass(maxLength);
static void Main(string[] args)
       {
           Console.WriteLine(DateTime.Now.Ticks);
           int maxLength = 10;
           CrackPass(maxLength);
           Console.WriteLine(DateTime.Now.Ticks);
           Console.Read();

       }

       static char[] charSource = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',  
                                   'n',  'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
       static int sLength = charSource.Length;
       private static void Crack(char[] list, int len)
       {
           if (len == 0)
           {
              Console.WriteLine(ArrayToString(list));
           }
           else
           {
               for (int i = 0; i < sLength; i++)
               {
                   list[len - 1] = charSource[i];
                   Crack(list, len - 1);
               }
           }        
       }
       private static string ArrayToString(char[] list)
       {
           if (list == null||list.Length == 0)
               return string.Empty;
           StringBuilder buider = new StringBuilder(list.Length*2);
           for (int i = 0; i < list.Length; i++)
           {
               buider.Append(list[i]);
           }
           return buider.ToString();

       }
       public static void CrackPass(int maxLength)
       {
           for (int i = 0; i < maxLength; i++)
           { 
               char[] list =new char[i];
               Crack(list, i);
           }
       
       }

Tags:暴力 算法

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接