开发者

How to using bruteforce method list al possible combinations of an element?

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 开发者_C百科the 1st).

e.g.:

dhgi#msodd


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?


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜