先发一下原始的加密代码,通过传入$operation = 'ENCODE'|'DECODE' 来实现加密和解密,操作就是$data=authcode($data);
authcode的function代码
function authcode($string,$operation='ENCODE') { if ($operation=='ENCODE'){ $OutTxt = ""; for ($x=0;$x<strlen($string);$x++) { $nr = ord($string[$x]); if ($nr < 128) { $nr += 128; } elseif ($nr > 127) { $nr -= 128; } $nr = 255 - $nr; $OutTxt .= sprintf("%02x", $nr); } return $OutTxt; }else{ $OutTxt = ""; for ($x=0;$x<(strlen($string)/2);$x++) { $nr = hexdec($string[$x * 2] . $string[($x * 2) + 1]); $nr = 255 - $nr; if ($nr < 128) { $nr += 128; } elseif ($nr > 127) { $nr -= 128; } $OutTxt .= chr($nr); } return $OutTxt; } }
把加密解密代码改一下,就可以单独解密了
<form method="post" name="form1" action=""> <input type="text" name="password" value="要解密的密码"> <br><input type="submit" name="Submit" value="提 交"><br><br> <?php $string = $_POST['password']; $oldpass = $string; function authcode($string) { $OutTxt = ""; for ($x=0;$x<(strlen($string)/2);$x++) { $nr = hexdec($string[$x * 2] . $string[($x * 2) + 1]); $nr = 255 - $nr; if ($nr < 128) { $nr += 128; } elseif ($nr > 127) { $nr -= 128; } $OutTxt .= chr($nr); } return $OutTxt; } echo $oldpass; echo " 解密后得到明文为:"; echo authcode($string); ?>