title: Best loop for cracking passwords
body: <p>I am creating a program that I will use to help my customers recover passwords placed on office documents like word and excel. The program works just fine but it is MUCH slower than similar products that you can download for free. I would like to use my own program because I feel like a lot of the ones you download for free aren't completely safe and lack some of the controls that I would like to have.</p>
  
  <p>More to the point... I need help figuring out why my program is so much slower. I created an excel document with a simple 3 letter password "TFX". The program I downloaded find the password almost as fast as I can let go of the mouse button after clicking on 'go'. My program takes 10 minutes. Here's the 3 character loop:</p>
  
  <pre><code>  private string ThreeCharPass(string file, Microsoft.Office.Interop.Excel.Application exApp, char[] combarr)
      {
          for (int three = 0; three &lt; combarr.Length; three++)
          {
              for (int two = 0; two &lt; combarr.Length; two++)
              {
                  for (int one = 0; one &lt; combarr.Length; one++)
                  {
                      try
                      {
                          string pass = combarr[three].ToString() + combarr[two].ToString() + combarr[one].ToString();
                          exApp.Workbooks.Open(file, false, true, Type.Missing, pass, Type.Missing, true, Type.Missing, Type.Missing, false, false, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                          return pass;
                      }
                      catch
                      {
                      }
                  }
              }
          }
          return string.Empty;
      }
  </code></pre>
  
  <p>The array 'combarr' is an array of chars containing all the possible characters in the password. It's generated earlier in the program based on user selected options. I'm thinking the issue has to be in the way I'm looping through the array to create the password combinations because just in this 3 character password method it spends more than 5 minutes where other 'professional' programs spend seconds. Any feedback would be greatly appreciated!!</p>