<?php $lang = array('en' => array('help' => 'Usage: %CMD% <integer>. Usage: %CMD% <integer>. Predict the next sequential integer polled from GWF_Random::rand(). Predict 20 in a row and i send you $100.', 'good' => 'Well done!', 'wrong' => 'You predicted %s but the outcome was %s.')); $plugin = Dog::getPlugin(); $argv = $plugin->argv(); if (count($argv) !== 1 || !Common::isNumeric($argv[0])) { return $plugin->showHelp(); } $predicted = (int) $argv[0]; $rand = GWF_Random::rand(); if ($rand === $predicted) { $plugin->rply('good'); } else { $plugin->rply('wrong', array($predicted, $rand)); }
public static function nextPrimeBetween($lo = self::LO_MAX, $hi = self::HI_MAX) { # Sanitize PHP Bullfrogs $lo = preg_replace("[^0-9]", '', "{$lo}"); $hi = preg_replace("[^0-9]", '', "{$hi}"); if ($lo == $hi) { return $lo; } else { if ($lo < $hi || $hi > $lo) { # Swappish Sanity $t = $lo; $lo = $hi; $hi = $t; } } # Still unused :) if ($lo < self::LO_MAX || $hi > self::HI_MAX) { # Your prime is not in range! return self::NO_NO_NOOOO; } # Check how cool you are switch (GWF_Random::rand(0, 4)) { case 0: return self::NO_PRIME; case 1: return self::NO_CLUE; # case 2: return self::NO_NEO; # case 2: return self::NO_NEO; case 3: return self::NO_NO_NO; case 4: case 2: # Good Enough :) $the_value = '1'; while ($the_value < self::HI_MAX) { $the_value = gmp_strval(gmp_nextprime(gmp_random(2))); } return $the_value; } }
$ttr = new TTR_Form(); $form = $ttr->getForm($chall, $csrf); if (isset($_POST['reset'])) { echo ttr_request($chall, $form); } elseif (isset($_POST['solve'])) { ttr_submit($chall); } echo GWF_Website::getDefaultOutput(); echo GWF_Box::box($chall->lang('info', array('index.php?show=source', 'index.php?highlight=christmas')), $chall->lang('title')); if (Common::getGetString('highlight') === 'christmas') { $source = '[PHP title=TimeToReset]' . trim(file_get_contents('challenge/time_to_reset/index.php')) . '[/PHP]'; echo GWF_Box::box(GWF_BBCode::decode($source)); } echo $form->templateY($chall->lang('ft_reset'), GWF_WEB_ROOT . 'challenge/time_to_reset/index.php'); formSolutionbox($chall); srand(GWF_Random::rand()); # Reset seed to something more secure. (thx noother) (thx Mart) # Print Challenge Footer echo $chall->copyrightFooter(); # Print end of website require_once 'challenge/html_foot.php'; ################# ### FUNCTIONS ### ################# function ttr_random($len, $alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') { $alphalen = strlen($alpha) - 1; $key = ''; for ($i = 0; $i < $len; $i++) { $key .= $alpha[rand(0, $alphalen)]; }
<?php $lang = array('en' => array('help' => 'Usage: %CMD%. Pick a random primenumber out of some.', 'out_no_prime' => 'Your input does not belong to a prime number.', 'out_no_clue' => 'The prime you have called is temporarily not available.', 'out_no_neo' => 'Prime Exit dialed. Please call again later!', 'out_no_error' => 'Your input does not belong to a prime number.', 'out_your_number' => "Your %s prime number is: %s.", 'out_no' => 'winnning', 'out_no_no' => 'lòósing')); $plugin = Dog::getPlugin(); $primus = GWF_Prime::nextPrimeBetween(); switch ($primus) { case GWF_Prime::NO_PRIME: $massage = $plugin->lang('out_no_prime'); break; case GWF_Prime::NO_CLUE: $massage = $plugin->lang('out_no_clue'); break; case GWF_Prime::NO_NEO: $massage = $plugin->lang('out_no_neo'); break; case GWF_Prime::NO_NO_NO: $massage = $plugin->lang('out_no_error'); break; case GWF_Prime::NO_NO_NOOOO: $massage = $plugin->lang('out_your_number'); break; default: $yo = GWF_Random::rand(0, 1) ? 'out_no' : 'out_no_no'; $yo = $plugin->lang($yo); $massage = $plugin->lang('out_your_number', array($yo, $primus)); } $plugin->reply($massage);
function GenerateCode($challenge = true) { if ($challenge !== true) { $this->sCode = $challenge; return; } // reset code $this->sCode = ''; // loop through and generate the code letter by letter for ($i = 0; $i < $this->iNumChars; $i++) { if (count($this->aCharSet) > 0) { // select random character and add to code string $this->sCode .= $this->aCharSet[GWF_Random::arrayItem($this->aCharSet)]; } else { // select random character and add to code string $this->sCode .= chr(GWF_Random::rand(65, 90)); } } // save code in session variable if ($this->bCaseInsensitive) { GWF_Session::set(CAPTCHA_SESSION_ID, strtoupper($this->sCode)); } else { GWF_Session::set(CAPTCHA_SESSION_ID, $this->sCode); } }