php自訂加密與解密程式執行個體,php加密與解密執行個體_PHP教程

來源:互聯網
上載者:User

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 " n"; } print " "; for( $i=0; $i{ print " "; for( $k=0; $k{ print " n"; } print " "; } print "
" . substr($ralphabet,$j,1) . "
" . ($i+1) . "|" . substr($pos_alpha_ary[$i],$k,1) . "
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...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.