// 暗号化したい文字列
$str = "保つのに時があり,捨てるのに時がある。";
// ワンタイムパッド
$pad = [
12,20,148,22,87,91,239,187,206,215,103,207,192,46,75,243,
204,61,121,210,145,167,108,78,166,129,109,239,138,134,150,196,
217,63,158,201,204,66,181,198,54,0,0,130,163,212,57,167,
169,115,170,50,109,116,173,177,252,242,233,3,33,28,139,73,
];
function convert($str, $pad){
$res = "";
for($i=0; $i<strlen($str); $i++) {
$c = ord(substr($str, $i, 1));
$cx = $c ^ $pad[$i];
$res .= chr($cx);
}
return $res;
}
$enc = convert($str, $pad);
echo "暗号化した文字列:{$enc}\n";
$dec = convert($enc, $pad);
echo "復号化した文字列:{$dec}\n";