title: How to write a brute-force algorithm?
body: <p>I'm currently looking for a bruteforce algorithm and I just can't find a good/simple one.<br>
  So I tried to write one myself, but I failed. I'm just too bad at math or whatever. :/<br>
  I don't need the algorithm in a specific programming language, if you have one, I can probably port it to the language I need it in.<br>
  I'm basically looking for something as simple as this:<br>
  (my attempt to write a bruteforce function)  </p>
  
  <pre><code>function BruteForce(chars,minLen,maxLen)
      curCharArray = {}
      for i=1, maxLen do
        curCharArray[i] = 0
      end
      generatedString = ""
      for currentLength = minLen, maxLen, 1 do
          curCharArray[currentLength] = 1
          Pos=currentLength
          while Pos&gt;0 do
  
              if string.len(generatedString) &lt; 1 then 
                  generatedString= string.sub(chars,curCharArray[Pos],curCharArray[Pos])
              else
                  generatedString= string.sub(generatedString,1,Pos-1) .. string.sub(chars,curCharArray[Pos],curCharArray[Pos])
              end
  
                  print(generatedString)
  
              curCharArray[Pos] = curCharArray[Pos]+1
              Pos = currentLength
              while curCharArray[Pos]==string.len(chars)+1 do
                  curCharArray[Pos]=1
                  Pos = Pos-1
              end
          end
      end
  end
  
  BruteForceAttack("abc",2,3)
  </code></pre>
  
  <p>It's written in Lua, you can run the code online here: <a href="http://www.lua.org/cgi-bin/demo" rel="nofollow">http://www.lua.org/cgi-bin/demo</a>
  The output is:</p>
  
  <pre><code>a
  ab
  ac
  
  a
  ab
  ac
  a
  aa
  ab
  ac
  b
  ba
  bb
  bc
  c
  ca
  cb
  cc
  cca
  ccb
  ccc
  ca
  caa
  cab
  cac
  cb
  cba
  cbb
  cbc
  cc
  cca
  ccb
  ccc
  a
  aa
  aab
  aac
  aa
  aaa
  aab
  aac
  ab
  aba
  abb
  abc
  ac
  aca
  acb
  acc
  b
  ba
  bab
  bac
  ba
  baa
  bab
  bac
  bb
  bba
  bbb
  bbc
  bc
  bca
  bcb
  bcc
  c
  ca
  cab
  cac
  ca
  caa
  cab
  cac
  cb
  cba
  cbb
  cbc
  cc
  cca
  ccb
  ccc
  </code></pre>
  
  <p>As you can see some outputs are the same and the minimum length is not being considered. Also, the order is wrong.
  I wanted the output to be:</p>
  
  <pre><code>aa
  ab
  ac
  ba
  bb
  bc
  ca
  cb
  cc
  aaa
  aab
  aac
  aba
  abb
  abc
  aca
  acb
  acc
  baa
  bab
  bac
  bba
  bbb
  bbc
  bca
  bcb
  bcc
  caa
  cab
  cac
  cba
  cbb
  cbc
  cca
  ccb
  ccc
  </code></pre>