0

How to list all possible combinations of:

String (4 characters, only lowercase no numbers or special signs), # sign, String (5 chars, the same rue as for the 1st).

e.g.:

dhgi#msodd

Neil
  • 5,762
  • 24
  • 36
bijou
  • 51
  • 1
  • 1
  • 6
  • 2
    why do you need this? what are you trying to do? – SilentGhost Feb 03 '11 at 14:35
  • 1
    @SilentGhost: He's trying to do [the same thing as yesterday](http://stackoverflow.com/questions/4874256/list-all-possible-combinations-of-letters-8-up-to-64-bit-long-string), just tricking us with asking for an extraneous hash this time. – mario Feb 03 '11 at 14:38
  • 1
    @mario: It wasn't clear to **why** he's doing this yesterday too. – SilentGhost Feb 03 '11 at 14:39
  • This has got homework written all over it imo. – Neil Feb 03 '11 at 14:40
  • @Neil - even teachers don't generally set such stupid homework as this. Personally, I think he's a script kiddie wannabee... look at previous questions like http://stackoverflow.com/questions/4863029/how-to-extract-text-from-an-image-using-php for how to crack a captcha – Mark Baker Feb 03 '11 at 14:42
  • @SilentGhost: I'm assuming it's about his original [URL shortening question](http://stackoverflow.com/questions/4862802/php-implementation-for-an-url-shortening-algorithm). Maybe Google blocks [search results](http://www.google.com/search?q=php+url+shortening+script) about that for him. – mario Feb 03 '11 at 14:42
  • @Mark I would not want to be him. Looks like his approach to everything is brute force, including his approach to programming. – Neil Feb 03 '11 at 14:48
  • 2
    @Neil - It's why I'm happy to give a brute-force answer. If his approach is always going to be brute force, rather than real hacking, he's one less threat to any of my sites – Mark Baker Feb 03 '11 at 14:49

2 Answers2

6

Assumption: English alphabet

for($firstPart = 'aaaa'; $firstPart != 'aaaaa'; $firstPart++) {
   for($secondPart = 'aaaaa'; $secondPart != 'aaaaaa'; $secondPart++) {
      echo $firstPart,'#',$secondPart,'<br />';
   }
}

Though why you'd want to do this, I don't know.

Is this related to your previous question?

Community
  • 1
  • 1
Mark Baker
  • 209,507
  • 32
  • 346
  • 385
0

powered by recursion

  function bruteforce($data)
{
    $storage = array();
    tryCombination($data,'',$storage);
    return $storage;
}


function tryCombination($input,$output,&$storage)
{
    if($input == "")
    {

        if(!in_array($output,$storage))
        array_push($storage,$output);

    }else {
        for($i = 0 ; $i < strlen($input) ; $i++)
        {
            $next = $output  . $input[$i];
            $remaining = substr($input,0,$i)  . substr($input,$i + 1);
            tryCombination($remaining,$next,$storage);
        }
    }


}

$final = bruteforce('yourData');
echo count($final);
print_r($final);
Mr Coder
  • 8,169
  • 5
  • 45
  • 74