3v4l.org

run code in 500+ PHP versions simultaneously
<?php class CTFCodec { private string $key; // ----------------------------------------------------- // Constructeur : on dérive la clé en SHA256 (32 octets) // ----------------------------------------------------- public function __construct(string $key) { $this->key = hash("sha256", $key, true); } // ----------------------------------------------------- // Rotation gauche sur 8 bits // ----------------------------------------------------- private function rotl(int $b, int $n): int { return (($b << $n) & 0xFF) | ($b >> (8 - $n)); } // ----------------------------------------------------- // Rotation droite sur 8 bits // ----------------------------------------------------- private function rotr(int $b, int $n): int { return (($b >> $n) | ($b << (8 - $n))) & 0xFF; } // ----------------------------------------------------- // Masque pseudo-aléatoire dépendant clé + seed + index // ----------------------------------------------------- private function mask(int $i, int $seed): int { $h = hash("sha256", $this->key . chr($seed) . pack("N", $i), true); return ord($h[$i % 32]); } // ----------------------------------------------------- // Layer 1 : XOR + rotations // ----------------------------------------------------- private function L1E(string $data, int $seed): string { $out = ""; foreach (str_split($data) as $i => $c) { $b = ord($c); $b = $this->rotl($b, ($i + $seed) % 7); $b ^= $this->mask($i, $seed); $b = $this->rotr($b, ($seed + $i) % 5); $out .= chr($b); } return $out; } private function L1D(string $data, int $seed): string { $out = ""; foreach (str_split($data) as $i => $c) { $b = ord($c); $b = $this->rotl($b, ($seed + $i) % 5); $b ^= $this->mask($i, $seed); $b = $this->rotr($b, ($i + $seed) % 7); $out .= chr($b); } return $out; } // ----------------------------------------------------- // Layer 2 : shuffle pseudo-chaotique (inversible) // ----------------------------------------------------- private function L2E(string $data, int $seed): string { $a = str_split($data); $n = count($a); for ($i = 0; $i < $n; $i++) { $j = ($this->mask($i, $seed) + $seed) % $n; [$a[$i], $a[$j]] = [$a[$j], $a[$i]]; } return implode("", $a); } private function L2D(string $data, int $seed): string { $a = str_split($data); $n = count($a); for ($i = $n - 1; $i >= 0; $i--) { $j = ($this->mask($i, $seed) + $seed) % $n; [$a[$i], $a[$j]] = [$a[$j], $a[$i]]; } return implode("", $a); } // ----------------------------------------------------- // Encodage final : Base64URL stable // ----------------------------------------------------- private function b64u_encode(string $d): string { return rtrim(strtr(base64_encode($d), "+/", "-_"), "="); } private function b64u_decode(string $d): string { $pad = 4 - (strlen($d) % 4); if ($pad < 4) $d .= str_repeat("=", $pad); return base64_decode(strtr($d, "-_", "+/")); } // ----------------------------------------------------- // ENCODE // ----------------------------------------------------- public function encode(string $msg): string { $seed = random_int(0, 255); // seed mutation $msg = $this->L1E($msg, $seed); $msg = $this->L2E($msg, $seed); $msg = $this->b64u_encode($msg); return sprintf("%02X", $seed) . "." . $msg; } // ----------------------------------------------------- // DECODE // ----------------------------------------------------- public function decode(string $cipher): string { list($hex, $data) = explode(".", $cipher, 2); $seed = hexdec($hex); $data = $this->b64u_decode($data); $data = $this->L2D($data, $seed); $data = $this->L1D($data, $seed); return $data; } } /*********************************************** * TEST * ***********************************************/ $codec = new CTFCodec(""); $input = ""; $enc = $codec->encode($input); $dec = $codec->decode($enc); echo "Original : $input\n"; echo "Encodé : $enc\n"; echo "Décodé : $dec\n"; ?>

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).

VersionSystem time (s)User time (s)Memory (MiB)
8.5.30.0320.00916.73
8.5.20.0340.00616.73
8.5.10.0290.00516.73
8.5.00.0080.00416.76
8.4.180.0260.01019.81
8.4.170.0310.01019.80
8.4.160.0330.01019.69
8.4.150.0270.00619.85
8.4.140.0230.01017.83
8.4.130.0270.00517.56
8.4.120.0280.00517.99
8.4.110.0350.00917.77
8.4.100.0390.00617.79
8.4.90.0340.00817.94
8.4.80.0300.00817.91
8.4.70.0360.00917.89
8.4.60.0360.00818.00
8.4.50.0390.00717.97
8.4.40.0410.00817.62
8.4.30.0400.01017.69
8.4.20.0350.00517.83
8.4.10.0340.01217.75
8.3.300.0200.00518.45
8.3.290.0280.00918.44
8.3.280.0310.00918.29
8.3.270.0280.00816.85
8.3.260.0280.00816.75
8.3.250.0220.00616.83
8.3.240.0290.00716.82
8.3.230.0340.00616.88
8.3.220.0280.00716.76
8.3.210.0340.00616.75
8.3.200.0240.00816.83
8.3.190.0320.00716.73
8.3.180.0310.00916.82
8.3.170.0290.00816.81
8.3.160.0380.01116.75
8.3.150.0270.00616.81
8.3.140.0290.00616.85
8.3.130.0220.00516.80
8.3.120.0250.00516.79
8.3.110.0210.00516.81
8.3.100.0160.00516.96
8.3.90.0170.00516.86
8.3.80.0170.00416.89
8.3.70.0220.00216.83
8.3.60.0190.00516.85
8.3.50.0170.00416.81
8.3.40.0250.00718.00
8.3.30.0210.00717.90
8.3.20.0290.00518.09
8.3.10.0250.01018.10
8.3.00.0280.00918.10

preferences:
41.51 ms | 703 KiB | 5 Q