php自定义加密函数、解密的例子
php encryption function
php decryption
加密就是将一些字符转换为另一个字符串的过程,简单的说就是把大门上锁,并且只有你有开启的钥匙,作为一个程序员都应该有属于自己的加密方式,目前最流行的加密算法就是MD5()加密方式,但是在网站已经有了破解的软件用起来也不是很安全,下面简单的介绍一下自定义的加密函数,代码如下:
<?php /*加密*/ function addcoder($str) { $yuan = 'abA!c1dB#ef2@Cg$h%iD_3jkl^E:m}4n.o{&F*p)5q(G-r[sH]6tuIv7w+Jxy8z9K0'; $jia = 'zAy%0Bx+1C$wDv^Eu2-t3(F{sr&G4q_pH5*on6I)m:l7.Jk]j8K}ih@gf9#ed!cb[a'; if (strlen($str) == 0) return false; for ($i = 0; $i < strlen($str); $i++) { for ($j = 0; $j < strlen($yuan); $j++) { if ($str[$i] == $yuan[$j]) { $results.= $jia[$j]; break; } } } return $results; } /*解密*/ function removecoder($str) { $yuan = 'abA!c1dB#ef2@Cg$h%iD_3jkl^E:m}4n.o{&F*p)5q(G-r[sH]6tuIv7w+Jxy8z9K0'; $jia = 'zAy%0Bx+1C$wDv^Eu2-t3(F{sr&G4q_pH5*on6I)m:l7.Jk]j8K}ih@gf9#ed!cb[a'; If (strlen($str) == 0) return false; for ($i = 0; $i < strlen($str); $i++) { for ($j = 0; $j < strlen($jia); $j++) { if ($str[$i] == $jia[$j]) { $results.= $yuan[$j]; break; } } } return $results; } $str = "www.phprm.com"; echo "加密前:" . $str . "<br >"; $str1 = addcoder($str); echo "加密后:" . $str1 . "<br >"; $str2 = removecoder($str1); echo "解密后:" . $str2 . "<br >"; ?>
Copy after login
例子二,利用md5+base64_encode进行编辑处理,代码如下:
<?php // function passport_encrypt($txt, $key) { srand((double)microtime() * 1000000); $encrypt_key = md5(rand(0, 32000)); $ctr = 0; $tmp = ''; for ($i = 0; $i < strlen($txt); $i++) { $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr; $tmp.= $encrypt_key[$ctr] . ($txt[$i] ^ $encrypt_key[$ctr++]); } return base64_encode(passport_key($tmp, $key)); } function passport_decrypt($txt, $key) { $txt = passport_key(base64_decode($txt) , $key); $tmp = ''; for ($i = 0; $i < strlen($txt); $i++) { $md5 = $txt[$i]; $tmp.= $txt[++$i] ^ $md5; } return $tmp; } function passport_key($txt, $encrypt_key) { $encrypt_key = md5($encrypt_key); $ctr = 0; $tmp = ''; for ($i = 0; $i < strlen($txt); $i++) { $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr; $tmp.= $txt[$i] ^ $encrypt_key[$ctr++]; } return $tmp; } ?>
Copy after login
本文链接:
收藏随意^^请保留教程地址.
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
Roblox: Grow A Garden - Complete Mutation Guide
3 weeks ago
By DDD
Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How to fix KB5055612 fails to install in Windows 10?
3 weeks ago
By DDD
Nordhold: Fusion System, Explained
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics
Java Tutorial
1665
14


CakePHP Tutorial
1423
52


Laravel Tutorial
1321
25


PHP Tutorial
1269
29


C# Tutorial
1249
24

