$text = strtolower($_POST["text"]); $key = strtolower($_POST["key"]); $text = str_replace(" ", "`", $text); $chars = str_split($text); if ($_POST["type"] == "Encode") { foreach ($chars as $i => $char) { $newchar = ((ord($char) + ord($key[$i % strlen($key)])) - 96*2) % 27 + 96; $newtext .= chr($newchar); } } else if ($_POST["type"] == "Decode") { foreach ($chars as $i => $char) { $newchar = (ord($char) - ord($key[$i % strlen($key)]) + 27) % 27 + 96; $newtext .= chr($newchar); } } echo str_replace("`", " ", $newtext); ?>