Jump to content

Recursive Function, Return Array not working


jsschmitt
 Share

Recommended Posts

I'm trying to return to array of letters that bruteForce finally decides upon. However, I can't seem to pass the array to librarySolve.

 

I'm feeling dumb, any help?

 

function librarySolve($string){
$temp = $this->bruteForce($string, FALSE, 0);
return $temp;
}

function bruteForce($string, $state, $trys){
$base = $string;
$state = $state;
$new_letters = array();

if($trys <= 6000){
	$this->new_letters = $this->generateRandomCipher();
	$string = preg_replace('/[^a-zA-Z0-9-\s]/', '', $string);

	for($a=0;$a<=strlen($string);$a++){
		$letter = substr($string, $a, 1);
		$pattern = "/[A-Z]/";

		if(preg_match($pattern, $letter)!=0){
			$new_letter = $this->new_letters[$letter];
		} else if(preg_match($pattern, $letter)==0) {
				$new_letter = $letter;
		}
		$decipher .= $new_letter;
	}

	$word_array = explode(" ", $decipher);

	$count = 0;
	for($a=0;$a<count($word_array);$a++){
		$do = $this->checkWord($word_array[$a]);
		if(!empty($do)){
			$count++;
		}
	}

	if($count>=2){ $state = TRUE; } else { $state = FALSE; }

	if($state==TRUE){
		return $this->new_letters;
	} else {
		$trys++;
		$this->bruteForce($base, $state, $trys);
	}
}
}

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.