3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function OTP($input, $pad) { $inputlen = strlen($input); $padlen = strlen($pad); $inputbytes = unpack("C*", $input); //Pack C* will convert a string into a byte array, such as 'abc' to Array(0x61, 0x62, 0x63) $padbytes = unpack("C*", $pad); $output = ""; for($i = 0; $i < $inputlen; $i++) //Loop through the input string $output .= chr($inputbytes[$i + 1] ^ $padbytes[$i % $padlen + 1]); return $output; } $result = OTP("This is a long sentence", "Abc"); var_dump(unpack("C*", $result)); var_dump($result);
based on rrKLU
Output for 4.3.0 - 7.2.0
array(23) { [1]=> int(21) [2]=> int(10) [3]=> int(10) [4]=> int(50) [5]=> int(66) [6]=> int(10) [7]=> int(50) [8]=> int(66) [9]=> int(2) [10]=> int(97) [11]=> int(14) [12]=> int(12) [13]=> int(47) [14]=> int(5) [15]=> int(67) [16]=> int(50) [17]=> int(7) [18]=> int(13) [19]=> int(53) [20]=> int(7) [21]=> int(13) [22]=> int(34) [23]=> int(7) } string(23) " 2B 2Ba /C2 5 ""