jsschmitt Posted October 7, 2011 Share Posted October 7, 2011 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); } } } Quote Link to comment Share on other sites More sharing options...
requinix Posted October 7, 2011 Share Posted October 7, 2011 The recursive call needs a return too. Quote Link to comment Share on other sites More sharing options...
jsschmitt Posted October 7, 2011 Author Share Posted October 7, 2011 The recursive call needs a return too. Is the last part of: if($state==TRUE){ return $this->new_letters; } else { $trys++; $this->bruteForce($base, $state, $trys); } Not enough? Quote Link to comment Share on other sites More sharing options...
jcbones Posted October 7, 2011 Share Posted October 7, 2011 Going out on a limb here. else { $trys++; $this->letters .= $this->bruteForce($base, $state, $trys); } Quote Link to comment Share on other sites More sharing options...
jsschmitt Posted October 7, 2011 Author Share Posted October 7, 2011 Going out on a limb here. else { $trys++; $this->letters .= $this->bruteForce($base, $state, $trys); } My hero. Forgot about classes and global variables. Told you I was feeling stupid. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.