@ 2014-06-04T15:29:55Z <?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
print_r('key:::::'.$key)
$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]['yum']);
$test->__set('secret' , $secret[$secret[$secret]]);
// 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.040 0.063 19.06 5.4.28 0.020 0.077 19.17 5.4.27 0.030 0.067 19.10 5.4.26 0.033 0.047 18.85 5.4.25 0.030 0.047 19.08 5.4.24 0.027 0.057 19.03 5.4.23 0.037 0.053 19.19 5.4.22 0.030 0.073 19.09 5.4.21 0.027 0.057 19.22 5.4.20 0.027 0.050 19.09 5.4.19 0.020 0.033 19.30 5.4.18 0.023 0.033 19.15 5.4.17 0.027 0.030 19.14 5.4.16 0.020 0.040 19.13 5.4.15 0.027 0.030 19.07 5.4.14 0.010 0.043 16.52 5.4.13 0.020 0.033 16.35 5.4.12 0.020 0.073 16.35 5.4.11 0.020 0.067 16.37 5.4.10 0.013 0.053 16.35 5.4.9 0.017 0.037 16.39 5.4.8 0.017 0.037 16.52 5.4.7 0.017 0.037 16.50 5.4.6 0.027 0.027 16.48 5.4.5 0.020 0.033 16.24 5.4.4 0.017 0.037 16.54 5.4.3 0.020 0.033 16.42 5.4.2 0.020 0.040 16.48 5.4.1 0.020 0.040 16.24 5.4.0 0.020 0.037 15.86 5.3.28 0.027 0.067 14.51 5.3.27 0.017 0.040 14.53 5.3.26 0.017 0.040 14.52 5.3.25 0.020 0.040 14.68 5.3.24 0.020 0.043 14.66 5.3.23 0.020 0.033 14.61 5.3.22 0.020 0.043 14.69 5.3.21 0.017 0.040 14.67 5.3.20 0.027 0.060 14.58 5.3.19 0.020 0.073 14.65 5.3.18 0.020 0.043 14.68 5.3.17 0.020 0.033 14.62 5.3.16 0.020 0.037 14.72 5.3.15 0.013 0.043 14.79 5.3.14 0.027 0.033 14.72 5.3.13 0.020 0.043 14.64 5.3.12 0.020 0.040 14.53 5.3.11 0.027 0.030 14.67 5.3.10 0.017 0.037 14.05 5.3.9 0.020 0.033 14.01 5.3.8 0.023 0.030 13.99 5.3.7 0.013 0.040 13.99 5.3.6 0.020 0.033 14.02 5.3.5 0.013 0.040 13.87 5.3.4 0.023 0.030 13.85 5.3.3 0.023 0.027 14.14 5.3.2 0.030 0.023 13.78 5.3.1 0.017 0.037 13.70 5.3.0 0.013 0.037 13.56
preferences:dark mode live preview
147.57 ms | 1394 KiB | 7 Q