Привет форумчанам.
<?php
class Viginer {
var $A1 = array ("А","Б","В","Г","Д","Е","Ж","З","И","Й","К","Л","М","Н","О","П","Р","С","Т","У","Ф","Х","Ц","Ч","Ш","Щ","Ъ","Ы","Ь","Э","Ю","Я","#","0","1","2","3","4","5","6","7","8","9");
var $message="";
var $key="";
var $table = array(array(),array());
var $code="";
var $decoding="";
function Viginer($mes, $k) {
$message = $mes;
$key = $k;
}
function tablele() {
echo "Constructing Viginer table:<br>";
for ($i = 0; $i < count($this->A1); $i++) {
for ($j = 0; $j < count($this->A1); $j++) {
$table[$i][$j] = $this->A1[($j+$i)%count($this->A1)];
echo $table[$i][$j];
}
echo '<br>';
}
}
function searchFunction($sym, $ch) {
for ($i = 0; $i < count($sym); $i++) {
if ($sym[$i] == $ch)
return $i;
}
return -1;
}
function searchFunctionTwo($sym, $n, $ch) {
for ($i = 0; $i < count($this->sym); $i++) {
if ($this->sym[$n][$i] == $this->ch)
return $i;
}
return -1;
}
function encoding() {
for ($i = 0; $i < strlen($this->message); $i++) {
$this->code += $this->table[searchFunction($this->A1, substr(strlen($i%$this->key), 1, $this->key))][searchFunction($this->A1, substr($i, 1, $this->message))];
}
echo "Encrypting message: ".$this->code;
}
function decodingo() {
for ($i = 0; $i < count($this->code); $i++) {
$this->decoding += $this->A1[searchFunctionTwo($this->table, searchFunction($this->A1, substr(strlen($i%$this->key), 1, $this->key)), substr($i, 1, $this->code))];
}
echo "Decoded message: ".$this->decoding;
}
function alpha()
{
echo "Alphabet:";
foreach($this->A1 as $alpha)
{
echo $alpha;
}
}
}
$mes="Сообщенийо";
$key="Ключ";
$vig = new Viginer($mes, $key);
$vig->tablele();
$vig->encoding();
$vig->decodingo();
$vig->alpha();
?>