刚学习php不久,请大神指教! 无 ?php/** * 精简版加密/解密类 * @author 布衣 QQ 780998900 * @packge SimpleTools * @link http://commoner.cn 布衣博客 * @copyright http://commoner.cn */class SimpleCrypt{ /** * 密钥 * 越复杂越好,但字符串长度会整
刚学习php不久,请大神指教!
<?php /** * 精简版加密/解密类 * @author 布衣 QQ 780998900 * @packge SimpleTools * @link http://commoner.cn 布衣博客 * @copyright http://commoner.cn */ class SimpleCrypt{ /** * 密钥 * 越复杂越好,但字符串长度会整加 * @var String */ private static $key = 'jdkhvxdicstui'; /** * 用于生成随机字符串 * @var array */ private static $word = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','v','u','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','V','U','W','X','Y','Z'); /** * 加密算法 * @param $str 需要加密的字符串 * @return String 加密后的字符串 */ public static function encode($str){ //首次加密 $str = base64_encode($str); //计算字符串长度 $str_num = mb_strlen($str); //取一半长度 $half = ceil($str_num / 2); //获取前半和后半字符串 $head_str = substr($str , 0 , $half); $end_str = substr($str , $half , $str_num); //计算前半和后半加密次数 $head_loop_num = $half < 50 ? ceil($half / 5) : ceil($half / 10); $end_loop_num = $str_num > 200 ? ceil($str_num / 10) : ceil($str_num /8); //生成随机字符串 $head_rand_loop_num = ($head_loop_num * 10) - $head_loop_num; $end_rand_loop_num = ($end_loop_num + $head_loop_num) * 10 - $end_loop_num; $head_rand_str = null; $end_rand_str = null; //前半部分随机字符串 for($i = 0 ; $i < $head_rand_loop_num ; $i++){ $head_rand_str .= self::$word[rand(0 , 51) ]; } //后半部分随机字符串 for($i = 0 ; $i < $end_rand_loop_num ; $i++){ $end_rand_str .= self::$word[rand(0 , 51)]; } //前半部分内容加密 for($i = 0 ; $i < $head_loop_num ; $i++){ $head_str = base64_encode($head_str); } //撕毁变量 unset($i); //后半部分内容加密 for($i = 0 ; $i < $end_loop_num ; $i++){ $end_str = base64_encode($end_str); } //合并 $implode_str = $head_rand_str . $head_str . self::$key . base64_encode($head_loop_num) . self::$key . base64_encode($end_loop_num) . self::$key . $end_str . $end_rand_str; $result = base64_encode($implode_str); //以后继续,先返回 return $result; } /** * 解密算法 * @param $str 需解密的字符串 * @return String 解密后字符串 */ public static function decode($str){ //获取加密信息 $get = explode(self::$key , base64_decode($str)); $head_str = $get[0]; $end_str = $get[3]; $head_loop_num = base64_decode($get[1]); $end_loop_num = base64_decode($get[2]); //去除随机字符串的算法 $head_rand_num = ($head_loop_num * 10) - $head_loop_num; $end_rand_num = ($end_loop_num + $head_loop_num) * 10 - $end_loop_num; //去除随机字符串,获取原文 $head_str = substr($head_str , $head_rand_num , strlen($head_str)); $end_str = substr($end_str , 0 , strlen($end_str) - $end_rand_num); //解密前半部分 for($i = 0 ; $i < $head_loop_num ; $i++){ $head_str = base64_decode($head_str); } //撕毁变量 unset($i); //解密后半部分 for($i = 0 ; $i < $end_loop_num ; $i++){ $end_str = base64_decode($end_str); } //合并并解密 $result = base64_decode($head_str . $end_str); return $result; } } ?>

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

Hot Tools

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

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
