シーザー暗号

<meta charset="UTF-8">
<?php
// get parameter
    $str = isset($_GET&#91;"str"&#93;) : "";
    $shift = isset($_GET&#91;"shift"&#93;) ? intval($_GET&#91;"shift"&#93;) : 3;
    if ($str != "")convert($str, $shift);
    $str_ = htmlentities($str, ENT_QUOTES);
// display form
echo <<< EOS
<form>
    character line: <input name="str" value="$str_"><br>
    shift: <input name="shift" value="$shift"><br>
    <input type=="submit" value="change">
</form>
    EOS;
    function makeTable($shift){
    $ch1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        $shift = $shift % strlen($ch1);
        $ch2 = substr($ch1, $shift).substr($ch1, 0, $shift);
        $table = [];
        for ($i = 0; $i < strlen($ch1); $i++){
            $c1 = substr($ch1, $i, 1);
            $c2 = substr($ch2, $i, 1);
            $table&#91;$c2&#93; = $c1;
        }
        return $table;
    }
    function convert($str, $shift){
        if (empty($_GET&#91;"str"&#93;)) return;
        $table = makeTable($shift);
        $res = "";
        for ($i = 0; $i < strlen($str); $i++){
            $c = substr($str, $i, 1);
            $res .= isset($table&#91;$c&#93;) ? $table&#91;$c&#93; : $c;
        }
        $str = htmlentities($str, ENT_QUOTES);
        $res = htmlentities($res, ENT_QUOTES);
        echo "<div>before transfer: $str</div>";
        echo "<div>after transfer: $res</div><hr>";
    }