$key = "這應該是個秘密!!!";
函數 keyED($txt,$encrypt_key)
{
$encrypt_key = md5($encrypt_key);
$ctr=0;
$tmp = "";
for ($i=0;$i
if ($ctr==strlen($encrypt_key)) $ctr=0;
$tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1);
$ctr ;
}
回傳$tmp;
}
函數加密($txt,$key)
{
srand((double)microtime(>{
srand((double)microtime(
$encrypt_key = md5(rand(0,32000));
$ctr=0;
$tmp = "";
for ($i=0;$i
if ($ctr==strlen($encrypt_key)) $ctr=0;
$tmp.= substr($encrypt_key,$ctr,1) 。
(substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
$ctr ;
}
return keyED($tmp,$key);
}
函數解密($txt,$key)
{
$txt = keyED($txt,$key);
$tmp = "";
for ($i=0;$i
$md5 = substr($txt,$i,1);
$i ;
$tmp.= (substr($txt,$i,1) ^ $md5);
}
回$tmp;
}
$string = "你好世界!!!";
// 加密 $string,將其儲存放在 $enc_text 中
$enc_text = encrypt($string,$key);
//解密加密文字$enc_text,儲存於$dec_text中
$dec_text =解密($enc_text,$key);
print "原文:$string
n";
print "加密文字:$enc_text
n";
print "解密文字:$dec_text
n";
?