@ 2014-06-04T13:41:40Z <?php
/*
Challenge 1: Modify Test::$secret before it's output.
Rules::
1. No use of Reflection API / runkit extension
2. No stopping execution before Test::run()
3. No Exceptions or PHP errors / warnings notices allowed
Hints:
1. Caesar
2. Magic methods
3. Requires a new feature of PHP 5.4
*/
class Test
{
private $secret = 'Nyy lbhe Onfr ner orybat gb hf.';
private $callback;
final public function run()
{
call_user_func($this->callback);
return $this->secret . PHP_EOL;
}
public function __set($k, $v)
{
$key = $v[($v[$v])]; // $v is some kind of weird array
$value = $v(); // and a callback!
$this->{$key} = $value;
}
}
$test = new Test;
// start editing here
/*
function decode($N,$alphabet,$msg){
// Initialization
$M = count($alphabet);
$decrypt = array();
$decode = array();
$encrypted = preg_split("//",$msg, -1, PREG_SPLIT_NO_EMPTY);
// Compute the decoding map
$decode[' '] = ' ';
foreach ($alphabet as $n=>$v){
$decode[$v] = $alphabet[($M+($n-$N)) % $M]; // Compute the decoding map for $v
}
foreach ($encrypted as $v){
$decrypt[] = $decode[$v];
}
return join('',$decrypt);
}
$array = (array) $test;
reset($array);
$first_key = key($array);
print_r($array[$first_key]);
//used this to figure out the count:
// http://rumkin.com/tools/cipher/caesar.php
$key = decode(13,26, $array[$first_key]);
*/
function caesar($str, $n) {
$ret = "";
for($i = 0, $l = strlen($str); $i < $l; ++$i) {
$c = ord($str[$i]);
if (97 <= $c && $c < 123) {
$ret.= chr(($c + $n + 7) % 26 + 97);
} else if(65 <= $c && $c < 91) {
$ret.= chr(($c + $n + 13) % 26 + 65);
} else {
$ret.= $str[$i];
}
}
return $ret;
}
$array = (array) $test;
reset($array);
$first_key = key($array);
print_r($array[$first_key]);
$secret = caesar($array[$first_key],13);
print_r('the secret is:'.$secret);
$test->__set($secret , $secret[($secret['yummy'])];);
// end editing here
echo $test->run();
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 5.4.29 0.011 0.049 12.50 5.4.28 0.014 0.060 12.41 5.4.27 0.014 0.064 12.41 5.4.26 0.007 0.058 12.40 5.4.25 0.007 0.065 12.40 5.4.24 0.013 0.084 12.40 5.4.23 0.006 0.086 12.40 5.4.22 0.009 0.066 12.40 5.4.21 0.007 0.066 12.40 5.4.20 0.011 0.054 12.39 5.4.19 0.010 0.067 12.39 5.4.18 0.006 0.056 12.39 5.4.17 0.009 0.051 12.40 5.4.16 0.015 0.072 12.39 5.4.15 0.006 0.053 12.39 5.4.14 0.007 0.056 12.08 5.4.13 0.010 0.047 12.06 5.4.12 0.008 0.051 12.03 5.4.11 0.009 0.065 12.02 5.4.10 0.009 0.047 12.03 5.4.9 0.012 0.054 12.02 5.4.8 0.012 0.048 12.02 5.4.7 0.005 0.053 12.02 5.4.6 0.008 0.059 12.02 5.4.5 0.010 0.051 12.01 5.4.4 0.010 0.047 12.00 5.4.3 0.011 0.047 12.00 5.4.2 0.009 0.051 11.99 5.4.1 0.010 0.045 12.00 5.4.0 0.004 0.057 11.49 5.3.28 0.011 0.049 12.71 5.3.27 0.013 0.049 12.72 5.3.26 0.011 0.055 12.72 5.3.25 0.012 0.047 12.72 5.3.24 0.006 0.047 12.72 5.3.23 0.008 0.053 12.71 5.3.22 0.012 0.051 12.68 5.3.21 0.011 0.045 12.68 5.3.20 0.011 0.044 12.68 5.3.19 0.007 0.052 12.68 5.3.18 0.010 0.045 12.67 5.3.17 0.008 0.039 12.66 5.3.16 0.005 0.039 12.67 5.3.15 0.012 0.047 12.67 5.3.14 0.007 0.039 12.66 5.3.13 0.009 0.044 12.65 5.3.12 0.007 0.047 12.66 5.3.11 0.007 0.042 12.66 5.3.10 0.008 0.036 12.13 5.3.9 0.005 0.043 12.11 5.3.8 0.011 0.037 12.11 5.3.7 0.003 0.043 12.10 5.3.6 0.007 0.044 12.09 5.3.5 0.007 0.052 12.04 5.3.4 0.006 0.058 12.04 5.3.3 0.014 0.046 12.00 5.3.2 0.006 0.052 11.78 5.3.1 0.008 0.058 11.74 5.3.0 0.008 0.055 11.73
preferences:dark mode live preview
136.57 ms | 1394 KiB | 7 Q