php自定义加密与解密程序实例
本文实例讲述了php自定义加密与解密程序。分享给大家供大家参考。具体分析如下:
PHP3Cryption是一个非常容易被破解,不安全的加密功能,不应该是非常重要的东西用,虽然加密是好的,它不会阻碍对尖端开裂程序的严格考验.
不过,试试吧...这是一个伟大的方式来加密和解密字符串。与许多隐窝功能,这是双向的。基于一个密码,您可以加密或解密。您也可以解密或加密过无数次,通过循环或其他方法。字母表中的字符也是变化的。所有这些事情让你修改和巩固加密。
关于这最佳的部分?您可以加密与解密或一张纸和一支铅笔一块。这需要相当长一点,但你并不需要一台电脑是附近使用它,如果你曾经失去的代码,如果你还记得你的技术可以解密。
我写在约一小时这些功能,经过几次不成功的和令人沮丧的尝试,并获得了更长的时间我没有出路的。成功的那天后的最佳方式做它突然实现。
请注意,这不会加密/解密无形字符(空格),如换行符(n)或标签(吨)!很抱歉,但我尝试,如果你找到一个办法,请让我知道!
$ralphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!,.:;?~@#$%^&*()_+-=][}{/><"'"; $alphabet=$ralphabet.$ralphabet; classCrypto{ functionencrypt($password,$strtoencrypt){ global$ralphabet; global$alphabet; for($i=0;$i<strlen($password);$i++) { $cur_pswd_ltr=substr($password,$i,1); $pos_alpha_ary[]=substr(strstr($alphabet,$cur_pswd_ltr),0,strlen($ralphabet)); } $i=0; $n=0; $nn=strlen($password); $c=strlen($strtoencrypt); while($i<$c) { $encrypted_string.=substr($pos_alpha_ary[$n],strpos($ralphabet,substr($strtoencrypt,$i,1)),1); $n++; if($n==$nn)$n=0; $i++; } return$encrypted_string; } functiondecrypt($password,$strtodecrypt){ global$ralphabet; global$alphabet; for($i=0;$i<strlen($password);$i++) { $cur_pswd_ltr=substr($password,$i,1); $pos_alpha_ary[]=substr(strstr($alphabet,$cur_pswd_ltr),0,strlen($ralphabet)); } $i=0; $n=0; $nn=strlen($password); $c=strlen($strtodecrypt); while($i<$c) { $decrypted_string.=substr($ralphabet,strpos($pos_alpha_ary[$n],substr($strtodecrypt,$i,1)),1); $n++; if($n==$nn)$n=0; $i++; } return$decrypted_string; } functioncryption_table($password){ global$ralphabet; global$alphabet; for($i=0;$i<strlen($password);$i++) { $cur_pswd_ltr=substr($password,$i,1); $pos_alpha_ary[]=substr(strstr($alphabet,$cur_pswd_ltr),0,strlen($ralphabet)); } print"<tableborder=1cellpadding="0"cellspacing="0">n"; print"<tr><td></td>"; for($j=0;$j<strlen($ralphabet);$j++) { print"<tdalign="center"><fontsize="2"face="arial">".substr($ralphabet,$j,1)."</td>n"; } print"</tr>"; for($i=0;$i<count($pos_alpha_ary);$i++) { print"<tr><tdalign="right"><fontsize="2"><b>".($i+1)."|</b></font></td>"; for($k=0;$k<strlen($pos_alpha_ary[$i]);$k++) { print"<tdalign="center"><fontsize="2"face="arial">".substr($pos_alpha_ary[$i],$k,1)."</td>n"; } print"</tr>"; } print"</table>n"; } }//endclassCrypto //ExamplewrittenbyMacroZeng $ct=newCrypto; //$ct->cryption_table($password); echo"<formaction=$PHP_SELFmethod=post>"; if($mod==2){ $strtodecrypt=$ct->encrypt($password,$strtoencrypt); echo'EncryptedString(加密后的字段):'; echo"<inputtype=textname=strtodecryptsize=45value=$strtodecrypt>"; echo"密码锁:<inputtype=textname=passwordsize=6value=$password>"; echo"<inputtype=submitvalue="Decrypt(解密)">"; } else{ $strtoencrypt=$ct->decrypt($password,$strtodecrypt); echo'StringtoEncrypt(需要加密的字段):'; echo"<inputtype=textname=strtoencryptsize=45value=$strtoencrypt>"; echo"密码锁:<inputtype=textname=passwordsize=6value=$password>"; echo"<inputtype=submitvalue="Encrypt(加密)">"; echo"<inputtype=hiddenname=modvalue=2>"; } echo"</form>";
highlight_file("crypto.php");
希望本文所述对大家的php程序设计有所帮助。