logo
Author: Raik
Description: онлайн реализация шифрования по методу Цезаря
Language: PHP
<!DOCTYPE style PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		 <meta http-equiv="content-type" content="text/html; charset=cp1251"/>
		 <title>Реализация шифра Цезаря с помощью PHP</title>
		<style>
			TABLE {
				border: 0px solid black;
				width: 40%;
				text-align: center;
				border-spacing: 0px;
			}
			TR {
				border: 1px solid black;
			}
			#row1 {
				background: darkgrey;
			}
			#row2 {
				background: lightgrey;
			}
		</style>
	</head>
	<body>
		<?php
			error_reporting(0);
		
			$letters = array('а', 'б','в', 'г','д', 'е','ё', 'ж','з', 'и', 'й', 'к','л', 'м','н', 'о','п', 'р','с', 'т', 'у', 'ф', 'х','ц', 'ч','ш', 'щ','ъ', 'ы','ь', 'э','ю', 'я');
			$string = strtolower($_POST['input_word']);
			$level = $_POST['level'];
			$length_string = strlen($string);
			$length_alphabet = count($letters);
			$counter = 0;
			
			
			
			echo "<form method = 'POST'>\n";
			echo "Введите слово:\n";
			echo "<input type = 'text' name = 'input_word' value = '".$string."'><br>\n";
			echo "Введите сдвиг:\n";
			echo "<select name = 'level'>\n";
			echo "<option value = 'undefined'>Неопределен</option>";
			for ($i = 0; $i <= 32; $i++) {
				echo "<option value = '".$i."' ";
				if ($i == $level) {
					echo "selected = 'selected'";
				}
				echo ">".$i."</option>\n";
			}
			echo "</select><br>\n";
			echo "<input name = 'encrypt' type = 'submit' value = 'Шифровать'>\n";
			echo "<input name = 'decode' type = 'submit' value = 'Дешифровать'><br>\n";
			
		
			if (isset($_POST['encrypt'])) {
				if ($level == 'undefined') {
					die('Задайте уровень');
				}
				echo "<hr>";
				for ($i=0;$i<=$length_string-1;$i++) {
					$symbol = $string[$i];
					for ($j = 0; $j <= $length_alphabet-1; $j++) {
						if ($letters[$j] == $symbol) {
							$array_mathes[$counter] = $j; 
							//echo $symbol." found ".$j."<br>";	
							$counter++;				
						}
					}
					//echo "i: ".$i." letter: ".$symbol."<br>";
				}			
		
				for ($i = 0; $i <= count($array_mathes)-1; $i++) {
					$new_index = (intval($level) + intval($array_mathes[$i]))%($length_alphabet);
					$encrypt_word .= $letters[$new_index];
					//echo "new_index: ".$new_index."<br>";
					
				}
				echo "<table>";
				echo "<tr id = 'row1'>\n";
				echo "<td>Сдвиг</td>\n";
				echo "<td>Результат</td>";
				echo "</tr>\n";
				echo "<tr id = 'row2'>";
				echo "<td>".$level."</td>";
				echo "<td>".$encrypt_word."</td>";
				echo "</tr>";
				echo "</table>";
				//echo "Результат шифрования слова '".$string."' с уровнем ".$level.": ";
				//echo "<input type = 'text' name = 'output_word' value = '".$encrypt_word."' readonly>\n<br>";
				//echo $string." ".$level;
				
				
			}
			if (isset($_POST['decode'])) {
				echo "<hr>";
				for ($i=0;$i<=$length_string-1;$i++) {
					$symbol = $string[$i];
					for ($j = 0; $j <= $length_alphabet-1; $j++) {
						if ($letters[$j] == $symbol) {
							$array_mathes[$counter] = $j; 
							//echo $symbol." found ".$j."<br>";	
							$counter++;				
						}
					}
					//echo "i: ".$i." letter: ".$symbol."<br>";
				}	
				
				echo "<table>";
				echo "<tr>\n";
				echo "<th>Сдвиг</th>\n";
				echo "<th>Результат</th>";
				echo "</tr>\n";
				for ($level = 0; $level <= $length_alphabet-1; $level++) {
					if (($level)%2 == 0) {
						echo "<tr id = 'row1'>";
					} else {
						echo "<tr id = 'row2'>";
					}
					
					echo "<td>".$level."</td>";
					for ($i = 0; $i <= $length_string-1; $i++) {
						$new_index = abs(intval($array_mathes[$i])-intval($level))%($length_alphabet);
						//echo $new_index." ";
						$decode_word .= $letters[$new_index];
					}
					
					echo "<td>".$decode_word."</td>";
					$decode_word = '';
					echo "</tr>";
				}
				echo "</table>";
				
			}
			
		?>
	</body>
</html>
Recent pastes:
123123123 (PHP)
ksurent (Perl)
ksurent (Bash)
guata (Plain Text)
biophreak (Plain Text)
Raik (PHP)
MUSbKA (Plain Text)
MUSbKA (Plain Text)
nekitozzz (C++)
nekitozzz (Plain Text)
nekitozzz (C++)
ksurent (Perl)
MUSbKA (C++)
stalin_alex (C++)
dzantiev (Plain Text)
unreal (C++)
eug2b (Plain Text)
We Are Not Responsible for User Content
netsago.paste.β © 2009—2012 Neunica