PHP加解密函数

该博客详细介绍了两个函数,一个是加密函数,另一个是解密函数。加密函数使用了MD5和自定义的字符映射,通过随机数和密钥进行混淆。解密函数则逆向操作,通过同样的步骤还原原始数据。这两个函数对于数据的安全存储和传输具有重要作用。
摘要由CSDN通过智能技术生成

/**

  • 加密函数
  • @param string $txt 需要加密的字符串
  • @param string $key 密钥
  • @return string 返回加密结果
    /
    function encrypt($txt, KaTeX parse error: Expected '}', got 'EOF' at end of input: …'){ if (empty(txt)) return t x t ; i f ( e m p t y ( txt; if (empty( txt;if(empty(key)) $key = md5(MD5_KEY);
    $chars = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.”;
    $ikey ="-x6g6ZWm2G9g_vr0Bo.pOq3kRIxsZ6rm";
    $nh1 = rand(0,64);
    $nh2 = rand(0,64);
    $nh3 = rand(0,64);
    $ch1 = KaTeX parse error: Expected '}', got 'EOF' at end of input: chars{nh1};
    $ch2 = KaTeX parse error: Expected '}', got 'EOF' at end of input: chars{nh2};
    $ch3 = KaTeX parse error: Expected '}', got 'EOF' at end of input: chars{nh3};
    $nhnum = $nh1 + $nh2 + $nh3;
    k n u m = 0 ; knum = 0; knum=0;i = 0;
    while(isset(KaTeX parse error: Expected '}', got 'EOF' at end of input: key{i})) k n u m + = o r d ( knum +=ord( knum+=ord(key{$i++});
    m d K e y = s u b s t r ( m d 5 ( m d 5 ( m d 5 ( mdKey = substr(md5(md5(md5( mdKey=substr(md5(md5(md5(key. c h 1 ) . ch1). ch1).ch2. i k e y ) . ikey). ikey).ch3), n h n u m nhnum%8, nhnumknum%8 + 16);
    KaTeX parse error: Expected group after '_' at position 29: …encode(time().'_̲'.txt);
    KaTeX parse error: Expected group after '_' at position 49: …='),array('-','_̲','.'),txt);
    $tmp = ‘’;
    j = 0 ; j=0; j=0;k = 0;
    t l e n = s t r l e n ( tlen = strlen( tlen=strlen(txt);
    k l e n = s t r l e n ( klen = strlen( klen=strlen(mdKey);
    for ($i=0; i < i< i<tlen; $i++) {
    $k = $k == $klen ? 0 : $k;
    j = ( j = ( j=(nhnum+strpos( c h a r s , chars, chars,txt{KaTeX parse error: Expected 'EOF', got '}' at position 2: i}̲)+ord(mdKey{$k++}))%64;
    $tmp .= KaTeX parse error: Expected '}', got 'EOF' at end of input: chars{j};
    }
    t m p l e n = s t r l e n ( tmplen = strlen( tmplen=strlen(tmp);
    t m p = s u b s t r r e p l a c e ( tmp = substr_replace( tmp=substrreplace(tmp, c h 3 , ch3, ch3,nh2 % ++$tmplen,0);
    t m p = s u b s t r r e p l a c e ( tmp = substr_replace( tmp=substrreplace(tmp, c h 2 , ch2, ch2,nh1 % ++$tmplen,0);
    t m p = s u b s t r r e p l a c e ( tmp = substr_replace( tmp=substrreplace(tmp, c h 1 , ch1, ch1,knum % ++$tmplen,0);
    return $tmp;
    }
    /
    *
  • 解密函数
  • @param string $txt 需要解密的字符串
  • @param string $key 密匙
  • @return string 字符串类型的返回结果
    */
    function decrypt($txt, $key = ‘’, KaTeX parse error: Expected '}', got 'EOF' at end of input: …0){ if (empty(txt)) return t x t ; i f ( e m p t y ( txt; if (empty( txt;if(empty(key)) $key = md5(MD5_KEY);
    $chars = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.";
    $ikey ="-x6g6ZWm2G9g_vr0Bo.pOq3kRIxsZ6rm";
    k n u m = 0 ; knum = 0; knum=0;i = 0;
    t l e n = @ s t r l e n ( tlen = @strlen( tlen=@strlen(txt);
    while(isset(KaTeX parse error: Expected '}', got 'EOF' at end of input: key{i})) k n u m + = o r d ( knum +=ord( knum+=ord(key{$i++});
    c h 1 = @ ch1 = @ ch1=@txt{$knum % $tlen};
    n h 1 = s t r p o s ( nh1 = strpos( nh1=strpos(chars,$ch1);
    t x t = @ s u b s t r r e p l a c e ( txt = @substr_replace( txt=@substrreplace(txt,’’,$knum % $tlen–,1);
    c h 2 = @ ch2 = @ ch2=@txt{$nh1 % $tlen};
    n h 2 = @ s t r p o s ( nh2 = @strpos( nh2=@strpos(chars,$ch2);
    t x t = @ s u b s t r r e p l a c e ( txt = @substr_replace( txt=@substrreplace(txt,’’,$nh1 % $tlen–,1);
    c h 3 = @ ch3 = @ ch3=@txt{$nh2 % $tlen};
    n h 3 = @ s t r p o s ( nh3 = @strpos( nh3=@strpos(chars,$ch3);
    t x t = @ s u b s t r r e p l a c e ( txt = @substr_replace( txt=@substrreplace(txt,’’,$nh2 % $tlen–,1);
    $nhnum = $nh1 + $nh2 + $nh3;
    m d K e y = s u b s t r ( m d 5 ( m d 5 ( m d 5 ( mdKey = substr(md5(md5(md5( mdKey=substr(md5(md5(md5(key. c h 1 ) . ch1). ch1).ch2. i k e y ) . ikey). ikey).ch3), n h n u m nhnum % 8, nhnumknum % 8 + 16);
    $tmp = ‘’;
    $j=0; $k = 0;
    t l e n = @ s t r l e n ( tlen = @strlen( tlen=@strlen(txt);
    k l e n = @ s t r l e n ( klen = @strlen( klen=@strlen(mdKey);
    for ($i=0; i < i< i<tlen; $i++) {
    $k = $k == $klen ? 0 : $k;
    j = s t r p o s ( j = strpos( j=strpos(chars,KaTeX parse error: Expected '}', got 'EOF' at end of input: txt{i})- n h n u m − o r d ( nhnum - ord( nhnumord(mdKey{KaTeX parse error: Expected 'EOF', got '}' at position 4: k++}̲); while (j<0) $j+=64;
    $tmp .= KaTeX parse error: Expected '}', got 'EOF' at end of input: chars{j};
    }
    KaTeX parse error: Expected group after '_' at position 30: …ace(array('-','_̲','.'),array('+…tmp);
    t m p = t r i m ( b a s e 6 4 d e c o d e ( tmp = trim(base64_decode( tmp=trim(base64decode(tmp));
    if (preg_match("/\d{10}
    /s”,substr(KaTeX parse error: Expected '}', got 'EOF' at end of input: …1))){ if (ttl > 0 && (time() - substr($tmp,0,11) > $ttl)){
    $tmp = null;
    }else{
    t m p = s u b s t r ( tmp = substr( tmp=substr(tmp,11);
    }
    }
    return $tmp;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值