/**对字符串进行加密。
- @param $txt
- @param string $key
- @return string
*/
public static function lockString( t x t , txt, txt,key=‘xxx’)
{
$chars = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=+”;
$nh = rand(0,64);
$ch = c h a r s [ chars[ chars[nh];
m d K e y = m d 5 ( mdKey = md5( mdKey=md5(key.$ch);
m d K e y = s u b s t r ( mdKey = substr( mdKey=substr(mdKey,$nh%8, $nh%8+7);
t x t = b a s e 6 4 e n c o d e ( txt = base64_encode( txt=base64encode(txt);
$tmp = ‘’;
i = 0 ; i=0; i=0;j=0; k = 0 ; f o r ( k = 0; for ( k=0;for(i=0; i < s t r l e n ( i<strlen( i<strlen(txt); $i++) {
$k = k = = s t r l e n ( k == strlen( k==strlen(mdKey) ? 0 : $k;
j = ( j = ( j=(nh+strpos( c h a r s , chars, chars,txt[ i ] ) + o r d ( i])+ord( i])+ord(mdKey[$k++]))%64;
$tmp .= c h a r s [ chars[ chars[j];
}
return urlencode( c h . ch. ch.tmp);
}
/**对字符串进行解密。
- @param $txt
- @param string $key
- @return bool|string
*/
public static function unlockString( t x t , txt, txt,key=‘xxx’)
{
t x t = u r l d e c o d e ( txt = urldecode( txt=urldecode(txt);
$chars = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=+”;
$ch = $txt[0];
n h = s t r p o s ( nh = strpos( nh=strpos(chars,$ch);
m d K e y = m d 5 ( mdKey = md5( mdKey=md5(key.$ch);
m d K e y = s u b s t r ( mdKey = substr( mdKey=substr(mdKey,$nh%8, $nh%8+7);
t x t = s u b s t r ( txt = substr( txt=substr(txt,1);
$tmp = ‘’;
i = 0 ; i=0; i=0;j=0; k = 0 ; f o r ( k = 0; for ( k=0;for(i=0; i < s t r l e n ( i<strlen( i<strlen(txt); $i++) {
$k = k = = s t r l e n ( k == strlen( k==strlen(mdKey) ? 0 : $k;
j = s t r p o s ( j = strpos( j=strpos(chars, t x t [ txt[ txt[i])- n h − o r d ( nh - ord( nh−ord(mdKey[ k + + ] ) ; w h i l e ( k++]); while ( k++]);while(j<0) $j+=64;
$tmp .= c h a r s [ chars[ chars[j];
}
return base64_decode($tmp);
}