3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Model { /** * Calculate the encryption give a static OTP */ public static function encrypt($string) { // Static pad $pad = 'aBcdefghijklmnopqrstuvwxyzabcdefghijklmno'; $encrypted_string = ""; for ($i = 0; $i < strlen($string); $i++) { $char = $string[$i]; if ($i < strlen($pad) && preg_match("/[a-z]/i", $char)) { $shift_char = $pad[$i]; $ord_shift = ctype_upper($shift_char) ? 65 : 97; $shift_amount = ord($shift_char) - $ord_shift; if ($shift_amount) { $ord_char = ord($char) + $shift_amount; while ($ord_char > $ord_shift + 26) { $ord_char -= 26; } $char = chr($ord_char); } } $encrypted_string .= $char; } return $encrypted_string; } } echo Model::encrypt('thiS is a test');

preferences:
53.08 ms | 402 KiB | 5 Q