продолжение
if (isset($_POST[\'submit\'])) {
$check_plain_text = md5(rtrim ($poststring));
$check_decoded_text = md5(rtrim(my_decrypt (my_encrypt($poststring, $_POST[\'cikey\'], $algorithms[$_GET[\'uid\']],$_POST[\'mode\'], $_POST[\'rand\']), $_POST[\'cikey\'],$algorithms[$_GET[\'uid\']],$_POST[\'mode\'])));
(bool) $checksum = ($check_plain_text == $check_decoded_text)?1:0;
$html.= "<div align=\\"center\\" class=\\"white\\">Контрольная сумма и общие данные</div>";
$html.= "<table align=\\"left\\" cellpadding=\\"1\\" cellspacing=\\"2\\" border=\\"0\\" width=\\"540\\"><tr>";
$html.= "<td colspan=\\"2\\" class=\\"greytable\\" align=\\"center\\"><b>Контрольная сумма</b></td></tr><tr>";
$html.= "<td class=\\"greytable\\" width=\\"300\\">Контрольная сумма MD5 исходных данных </td><td class=\\"greylight\\" align=\\"center\\">".$check_plain_text."</td></tr><tr>";
$html.= "<td class=\\"greytable\\" width=\\"300\\">Контрольная сумма MD5 после дешифрации </td><td class=\\"greylight\\" align=\\"center\\">".$check_decoded_text."</td></tr><tr>";
$html.= "<td class=\\"greytable\\" width=\\"300\\">Результат сверки контрольных сумм</td>".(($checksum)?"<td class=\\"greentable\\" align=\\"center\\">Возвращенные данные после дешифрации идентичны оригинальным":"<td class=\\"redtable\\" align=\\"center\\">Исходные данные после дешифрации не совпадают с оригинальными")."</td></tr><tr>";
$html.= "<td colspan=\\"2\\" class=\\"greytable\\" align=\\"center\\"><b>Общие сведения об использованном методе шифрования данных</b></td></tr><tr>";
$html.= "<td class=\\"greytable\\" width=\\"300\\">Используемый алгоритм библиотеки LIBMCRYPT</td><td class=\\"greylight\\" align=\\"center\\"><b>MCRYPT_".strtoupper ($algorithms[$_GET[\'uid\']])."</b>
".$comments[$algorithms[$_GET[\'uid\']]]."</td></tr><tr>";
$html.= "<td class=\\"greytable\\" width=\\"300\\">Используемый режим шифрования</td><td class=\\"greylight\\" align=\\"center\\"><b>MCRYPT_MODE_".strtoupper ($_POST[\'mode\'])."</b>
".$comments[$_POST[\'mode\']]."</td></tr><tr>";
$html.= "<td class=\\"greytable\\" width=\\"300\\">Псевдоустройство случайности</td><td class=\\"greylight\\" align=\\"center\\"><b>".$_POST[\'rand\']."</b>
".$comments[$_POST[\'rand\']]."</td></tr><tr>";
$html.= "<td class=\\"greytable\\" width=\\"300\\">Автоматически сгенерированный 40-разрядный SHA1-хэш ключа</td><td class=\\"greylight\\" align=\\"center\\">".wordwrap ($_POST[\'cikey\'], 40, \'
\',1)."</td></tr><tr>";
$html.= "<td class=\\"greytable\\" width=\\"300\\">Размер ключа (берется максимальный)</td><td class=\\"greylight\\" align=\\"center\\">".mcrypt_get_key_size($algorithms[$_GET[\'uid\']], $_POST[\'mode\'])." Bytes</td></tr><tr>";
$html.= "<td class=\\"greytable\\" width=\\"300\\">Размер блока</td>".((mcrypt_module_is_block_algorithm ($algorithms[$_GET[\'uid\']]))?"<td class=\\"greylight\\" align=\\"center\\">".mcrypt_module_get_algo_block_size($algorithms[$_GET[\'uid\']])." Bytes":"<td class=\\"redtable\\" align=\\"center\\">Является потоковым алгоритмом, блоки не использует")."</td></tr><tr>";
$html.= "<td class=\\"greytable\\" width=\\"300\\">Размер вектора инициализации</td>".((mcrypt_get_iv_size ($algorithms[$_GET[\'uid\']], $_POST[\'mode\'])!=0)?"<td class=\\"greylight\\" align=\\"center\\">".mcrypt_get_iv_size($algorithms[$_GET[\'uid\']], $_POST[\'mode\'])." Bytes":"<td class=\\"redtable\\" align=\\"center\\">В данном режиме вектор инициализации не используется")."</td></tr>";
$html.= "</table>";
}
return $html;
}
function alg () {
global $algorithms, $disable_select, $poststring;
$html.= "<form action=\\"{$_SERVER[\'REQUEST_URI\']}\\" method=\\"POST\\">
<fieldset class=\\"fieldcrypt\\"><legend align=\\"left\\">Алгоритм</legend>
<select value=\\"treat\\" style=\\"width:150px;\\" name=\\"algorithm\\" size=\\"".count ($algorithms)."\\" onchange=\\"javascript: window.location.href=this.options[this.selectedIndex].value\\" ".$disable_select.">";
foreach ($algorithms as $algo_key=>$algo_name) {
$html.= "<option value=\\"/?sid=3&uid=".$algo_key."\\" ".(($algo_key == $_GET[\'uid\'])?\'selected\':NULL).">".strtoupper ($algo_name); }
$html.= "</select></fieldset>";
return $html;
}
function alkey () {
global $value_text, $poststring;
$html = "<fieldset class=\\"fieldcrypt\\"><legend align=\\"left\\">Генерация произвольного 40-разрядного SHA1-хэша ключа</legend>
<input type=\\"text\\" name=\\"cikey\\" style=\\"width: 355px;\\" value=\\"".$value_text."\\" readonly></fieldset>";
return $html;
}
function mod () {
global $option_modes, $disable_form, $poststring;
$html = "
<fieldset class=\\"fieldcrypt\\"><legend align=\\"left\\">Режим шифрования</legend>
<select name=\\"mode\\" ".$disable_form." style=\\"width:170px;\\">".$option_modes."</select></fieldset>";
return $html;
}
function ran () {
global $option_random, $disable_form, $poststring;
$html = "
<fieldset class=\\"fieldcrypt\\"><legend align=\\"left\\">Источник случайности</legend>
<select name=\\"rand\\" ".$disable_form." style=\\"width:165px;\\">".$option_random."</select></fieldset>";
return $html;
}
function text () {
global $disable_form, $poststring;
$html = "
<fieldset class=\\"fieldcrypt\\"><legend align=\\"left\\">Исходные данные</legend>
<textarea rows=\\"6\\" style=\\"width:355px;\\" name=\\"string\\" ".$disable_form.">".((!empty($poststring))?$poststring:"")."</textarea></fieldset>";
return $html;
}
function enc () {
global $algorithms, $poststring;
$html = "
<fieldset class=\\"fieldcrypt\\"><legend align=\\"left\\">Зашифрованные данные</legend>
<textarea rows=\\"6\\" style=\\"width:355px;\\" name=\\"encode\\" readonly>";
if (isset($_POST[\'submit\'])) {
$html.= my_encrypt($poststring, $_POST[\'cikey\'], $algorithms[$_GET[\'uid\']],$_POST[\'mode\'], $_POST[\'rand\']);
}
$html .= "</textarea></fieldset>";
return $html;
}
function sub () {
global $disable_form, $poststring;
$html = "
<input type=\\"submit\\" class=\\"baton\\" name=\\"submit\\" value=\\"Зашифровать данные\\"".$disable_form.">";
return $html;
}
function red () {
global $disable_form, $poststring;
$html = "
<input type=\\"button\\" class=\\"baton\\" value=\\"Выбор нового алгоритма\\" onclick=\\"javascript: window.location.href = \'/?sid=3\'\\"".$disable_form.">";
return $html;
}
function show () {
$html = "<div align=\\"center\\" class=\\"white\\">Здесь можно что-нибудь зашифровать</div>";
$html.= "
<table cellspacing=\\"0\\" cellpadding=\\"2\\" border=\\"0\\" width=\\"500\\" align=\\"center\\">
<tr>
<td rowspan=\\"4\\" valign=\\"top\\">".alg()."</td>
<td colspan=\\"2\\">".alkey()."</td>
</tr>
<tr>
<td>".mod()."</td>
<td>".ran()."</td>
</tr>
<tr>
<td colspan=\\"2\\">".text()."</td>
</tr>
<tr>
<td colspan=\\"2\\">".enc()."</td>
</tr>
<tr>
<td colspan=\\"3\\" align=\\"center\\">
".sub()." ".red()."</td>
</tr>
</table>";
return $html;
}