commit 66ec387b38d8ba42aad88ba3026ebb8cfd7a792f Author: Toy Rik Date: Sat Mar 15 08:27:47 2025 +0300 init diff --git a/chefr.php b/chefr.php new file mode 100644 index 0000000..37c2333 --- /dev/null +++ b/chefr.php @@ -0,0 +1,105 @@ + + + + + Шифрование/Расшифровка + + +
+
+
+ +
+ +
+ +
+ + '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
"; + } + ?> + + \ No newline at end of file