《PHP實(shí)戰(zhàn):php自定義加密與解密程序?qū)嵗芬c(diǎn):
本文介紹了PHP實(shí)戰(zhàn):php自定義加密與解密程序?qū)嵗M麑δ杏谩H绻幸蓡枺梢月?lián)系我們。
PHP實(shí)例本文實(shí)例講述了php自定義加密與解密程序.分享給大家供大家參考.具體分析如下:
PHP實(shí)例PHP3 Cryption是一個(gè)非常容易被破解,不平安的加密功能,不應(yīng)該是非常重要的東西用,雖然加密是好的,它不會(huì)阻礙對尖端開裂程序的嚴(yán)格考驗(yàn).
PHP實(shí)例不過,試試吧...這是一個(gè)偉大的方式來加密和解密字符串.與許多隱窩功能,這是雙向的.基于一個(gè)暗碼,您可以加密或解密.您也可以解密或加密過無數(shù)次,通過循環(huán)或其他方法.字母表中的字符也是變化的.所有這些事情讓你修改和鞏固加密.
PHP實(shí)例關(guān)于這最佳的部分?您可以加密與解密或一張紙和一支鉛筆一塊.這需要相當(dāng)長一點(diǎn),但你并不需要一臺電腦是附近使用它,如果你曾經(jīng)失去的代碼,如果你還記得你的技術(shù)可以解密.
PHP實(shí)例我寫在約一小時(shí)這些功能,經(jīng)過幾次不成功的和令人沮喪的嘗試,并獲得了更長的時(shí)間我沒有出路的.成功的那天后的最佳方式做它突然實(shí)現(xiàn).
PHP實(shí)例請注意,這不會(huì)加密/解密無形字符(空格),如換行符(n)或標(biāo)簽(噸)!很抱歉,但我嘗試,如果你找到一個(gè)辦法,請讓我知道!
代碼如下:
$ralphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 !,.:;?~@#$%^&*()_+-=][}{/><"'";?
$alphabet = $ralphabet . $ralphabet;
?
class Crypto {
?
function encrypt ($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;
?
}
?
function decrypt ($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;
?
}
?
function cryption_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 "<table border=1 cellpadding="0" cellspacing="0">n";
?
print "<tr><td></td>";?
for( $j=0; $j<strlen($ralphabet); $j++ )?
{?
print "<td align="center"><font size="2" face="arial">" . substr($ralphabet,$j,1) . "</td>n";?
}?
print "</tr>";
?
?
for( $i=0; $i<count($pos_alpha_ary); $i++ )?
{?
print "<tr><td align="right"><font size="2"><b>" . ($i+1) . "|</b></font></td>";?
for( $k=0; $k<strlen($pos_alpha_ary[$i]); $k++ )?
{?
print "<td align="center"><font size="2" face="arial">" . substr($pos_alpha_ary[$i],$k,1) . "</td>n";?
}?
print "</tr>";?
}
?
print "</table>n";
?
}
?
} // end class Crypto
?
// Example written by Macro Zeng?
$ct = new Crypto;?
//$ct->cryption_table($password);?
echo "<form action=$PHP_SELF method=post>";?
if ($mod == 2) {?
$strtodecrypt = $ct->encrypt ($password,$strtoencrypt);?
echo 'Encrypted String(加密后的字段): ';?
echo "<input type=text name=strtodecrypt size=45 value=$strtodecrypt>";?
echo "暗碼鎖: <input type=text name=password size=6 value=$password>";?
echo "<input type=submit value="Decrypt(解密)">";?
}?
else {?
$strtoencrypt = $ct->decrypt ($password,$strtodecrypt);?
echo 'String to Encrypt(需要加密的字段): ';?
echo "<input type=text name=strtoencrypt size=45 value=$strtoencrypt>";?
echo "暗碼鎖: <input type=text name=password size=6 value=$password>";?
echo "<input type=submit value="Encrypt(加密)">";?
echo "<input type=hidden name=mod value=2>";?
}?
echo "</form>";
代碼如下:
highlight_file("crypto.php");
PHP實(shí)例希望本文所述對大家的php程序設(shè)計(jì)有所幫助.
維易PHP培訓(xùn)學(xué)院每天發(fā)布《PHP實(shí)戰(zhàn):php自定義加密與解密程序?qū)嵗返葘?shí)戰(zhàn)技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養(yǎng)人才。
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/12854.html