'xyz', 'b' => 'qwe', 'c' => 'rty', 'd' => 'uio', 'e' => 'pas', 'f' => 'dfg', 'g' => 'hjk', 'h' => 'lzx', 'i' => 'cvb', 'j' => 'nm', 'k' => 'bnm', 'l' => 'poi', 'm' => 'lkj', 'n' => 'mnb', 'o' => 'poiuytrewq', 'p' => 'asdfghjkl', 'q' => 'zxcvbnm', 'r' => 'qwertyuiop', 's' => 'asdfghjklzxcvbnm', 't' => 'qwertyuiopasdfghjkl', 'u' => 'zxcvbnmqwertyuiop', 'v' => 'asdfghjklzxcvbnmqwertyuiop', 'w' => 'qwertyuiopasdfghjklzxcvbnm', 'x' => 'zxcvbnmqwertyuiopasdfghjkl', 'y' => 'qwertyuiopasdfghjklzxcvbnm', 'z' => 'zxcvbnmqwertyuiopasdfghjkl' ]; // Создаем словарь для расшифровки $decryptionDictionary = array_flip($encryptionDictionary); function encryptText($text, $dictionary) { $encryptedText = ''; $text = strtolower($text); // Приводим текст к нижнему регистру для простоты for ($i = 0; $i < strlen($text); $i++) { $char = $text[$i]; if (isset($dictionary[$char])) { $encryptedText .= $dictionary[$char]; } else { $encryptedText .= $char; // Если символ не найден в словаре, оставляем его без изменений } } return $encryptedText; } function decryptText($text, $dictionary) { $decryptedText = ''; $text = strtolower($text); // Приводим текст к нижнему регистру для простоты $keys = array_keys($dictionary); $values = array_values($dictionary); while ($text != '') { $found = false; foreach ($values as $index => $value) { if (strpos($text, $value) === 0) { $decryptedText .= $keys[$index]; $text = substr($text, strlen($value)); $found = true; break; } } if (!$found) { $decryptedText .= $text[0]; // Если символ не найден в словаре, оставляем его без изменений $text = substr($text, 1); } } return $decryptedText; } if ($action == 'encrypt') { $result = encryptText($text, $encryptionDictionary); } else { $result = decryptText($text, $decryptionDictionary); } echo "

Результат:

"; echo "
$result
"; } ?>