php自訂加密與解密程式執行個體,php加密與解密執行個體
本文執行個體講述了php自訂加密與解密程式。分享給大家供大家參考。具體分析如下:
PHP3 Cryption是一個非常容易被破解,不安全的加密功能,不應該是非常重要的東西用,雖然加密是好的,它不會阻礙對尖端開裂程式的嚴格考驗.
不過,試試吧...這是一個偉大的方式來加密和解密字串。與許多隱窩功能,這是雙向的。基於一個密碼,您可以加密或解密。您也可以解密或加密過無數次,通過迴圈或其他方法。字母表中的字元也是變化的。所有這些事情讓你修改和鞏固加密。
關於這最佳的部分?您可以加密與解密或一張紙和一支鉛筆一塊。這需要相當長一點,但你並不需要一台電腦是附近使用它,如果你曾經失去的代碼,如果你還記得你的技術可以解密。
我寫在約一小時這些功能,經過幾次不成功的和令人沮喪的嘗試,並獲得了更長的時間我沒有出路的。成功的那天后的最佳方式做它突然實現。
請注意,這不會加密/解密無形字元(空格),如分行符號(n)或標籤(噸)!很抱歉,但我嘗試,如果你找到一個辦法,請讓我知道!
複製代碼 代碼如下:$ralphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 !,.:;?~@#$%^&*()_+-=][}{/><"'";
$alphabet = $ralphabet . $ralphabet;
class Crypto {
function encrypt ($password,$strtoencrypt) {
global $ralphabet;
global $alphabet;
for( $i=0; $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{
$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{
$cur_pswd_ltr = substr($password,$i,1);
$pos_alpha_ary[] = substr(strstr($alphabet,$cur_pswd_ltr),0,strlen($ralphabet));
}
print "
n"; print "
| "; for( $j=0; $j{ print "
" . substr($ralphabet,$j,1) . " | n"; } print "
"; for( $i=0; $i{ print "
| " . ($i+1) . "| | "; for( $k=0; $k{ print "
" . substr($pos_alpha_ary[$i],$k,1) . " | n"; } print "
"; } print "
n";
}
} // end class Crypto
// Example written by Macro Zeng
$ct = new Crypto;
//$ct->cryption_table($password);
echo "";
複製代碼 代碼如下:
highlight_file("crypto.php");
希望本文所述對大家的php程式設計有所協助。
http://www.bkjia.com/PHPjc/935479.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/935479.htmlTechArticlephp自訂加密與解密程式執行個體,php加密與解密執行個體 本文執行個體講述了php自訂加密與解密程式。分享給大家供大家參考。具體分析如下: P...