";
echo $text." ";
echo "";
}
function print_edit_form ($content, $action, $key) {
echo "
";
}
function print_redirect ($address) {
echo "...";
echo "";
}
function encrypt ($pwd, $data, $ispwdHex = 0) {
if ($ispwdHex) $pwd = @pack('H*', $pwd);
$key[] = '';
$box[] = '';
$cipher = '';
$pwd_length = strlen($pwd);
$data_length = strlen($data);
for ($i = 0; $i < 256; $i++) {
$key[$i] = ord($pwd[$i % $pwd_length]);
$box[$i] = $i;
}
for ($j = $i = 0; $i < 256; $i++) {
$j = ($j + $box[$i] + $key[$i]) % 256;
$tmp = $box[$i];
$box[$i] = $box[$j];
$box[$j] = $tmp;
}
for ($a = $j = $i = 0; $i < $data_length; $i++) {
$a = ($a + 1) % 256;
$j = ($j + $box[$a]) % 256;
$tmp = $box[$a];
$box[$a] = $box[$j];
$box[$j] = $tmp;
$k = $box[(($box[$a] + $box[$j]) % 256)];
$cipher .= chr(ord($data[$i]) ^ $k);
}
return $cipher;
}
echo "Vault
";
if ($cmd == "save") {
if (!empty($_POST)) {
$content = $_POST["input_editor"];
$content = stripslashes($content);
$content = encrypt($key, $content);
$handle = fopen($data_filename, "wb");
if ($handle) {
fwrite($handle, $content);
fclose($handle);
print_redirect($_SERVER["PHP_SELF"]);
}
}
}
elseif ($cmd == "open") {
if (!file_exists($data_filename)) {
$handle = fopen($data_filename, "wb");
if ($handle) {
chmod ($data_filename, 0777);
fclose($handle);
}
}
if (filesize($data_filename) == 0) {
$content = '';
print_edit_form ($content, $_SERVER["PHP_SELF"]."?cmd=save", $key);
} else {
$handle = fopen($data_filename, "r");
if($handle) {
$content = '';
while (!feof($handle))
$content .= fread($handle, filesize($data_filename));
fclose($handle);
$content = encrypt($key, $content);
print_edit_form ($content, $_SERVER["PHP_SELF"]."?cmd=save", $key);
}
}
}
else {
print_input_form ("Key: ", "password", "input_key", "Open", $_SERVER["PHP_SELF"]."?cmd=open");
}
?>