一段javascript转PHP的encrypt加密算法

简介: javascript 常用函数转换成PHP代码处理

javascript 常用函数转换成PHP代码处理

对应的javascript代码如下:

classjs2php{
publicstaticfunctiondetect_encoding($text){
$charsets=array(“UTF-8,“GB2312”,“GBK”,“BIG5”,“ASCII”,“EUC-JP”,‘KOI8-R’,“Shift_JIS”,“CP936”,“ISO-8859-1,“JIS”,“eucjp-win”,“sjis-win”);
encode= ( mbdetectencoding ( encode= (mb_detect_encoding(encode=(mbdetectencoding(text, $charsets));
return$encode;
}
publicstaticfunctionstrlen()
{
staticfunc=null ; if ( isnull ( func=null; if (is_null(func=null;if(isnull(func)) {
$func=‘strlen’;
if (function_exists(‘mb_strlen’)) {
$func=‘mb_strlen’;
}elseif (function_exists(‘iconv_strlen’)) {
$func=‘iconv_strlen’;
}
}
$args=func_get_args();
encode=self : : detectencoding ( encode=self::detect_encoding(encode=self::detectencoding(args[0]);
$args[1] =$encode;
returncall_user_func_array($func, $args);
}
publicstaticfunctionsubstr()
{
staticfunc=null ; if ( isnull ( func=null; if (is_null(func=null;if(isnull(func)) {
$func=‘substr’;
if (function_exists(‘mb_substr’)) {
$func=‘mb_substr’;
}elseif (function_exists(‘iconv_substr’)) {
$func=‘iconv_substr’;
}
}
$args=func_get_args();
encode=self : : detectencoding ( encode=self::detect_encoding(encode=self::detectencoding(args[0]);
$args[3] =$encode;
returncall_user_func_array($func, KaTeXparseerror: Expected'EOF', got'}'atposition8: args); }̲publicstatic…str, KaTeXparseerror: Expected'}', got'EOF'atendofinput: =false) { if (!offset) offset=0 ; returnself : : ordutf8 ( offset=0; returnself::ordutf8(offset=0;returnself::ordutf8(str, KaTeXparseerror: Expected'EOF', got'}'atposition10: offset); }̲privatestatic…string, &$offset)
{
code=ord ( substr ( code=ord(substr(code=ord(substr(string, offset , 1 ) ) ; if ( offset,1)); if (offset,1));if(code>=128) { //otherwise 0xxxxxxxif ($code<224) bytesnumber=2 ; / /110xxxxxelseif ( bytesnumber=2; //110xxxxx else if (bytesnumber=2;//110xxxxxelseif(code < 240) b y t e s n u m b e r = 3 ; / / 1110 x x x x e l s e i f ( bytesnumber = 3; //1110xxxx else if (bytesnumber=3;//1110xxxxelseif(code < 248) $bytesnumber = 4; //11110xxx$codetemp=code192 ( code-192- (code−192−(bytesnumber>2?32 : 0) - (bytesnumber>3?16 : 0 ) ; for ( bytesnumber>3?16 : 0); for (bytesnumber>3?16:0);for(i=2; $i<=$bytesnumber; $i++) {
$offset++;
code2=ord ( substr ( code2=ord(substr(code2=ord(substr(string, $offset, 1)) -128; //10xxxxxx$codetemp=$codetemp*64+$code2;
}
$code=$codetemp;
}
offset+=1 ; if ( offset+=1; if (offset+=1;if(offset>=strlen($string)) $offset=-1;
returnKaTeXparseerror: Expected'EOF', got'}'atposition7: code; }̲publicstatic…a, $b)
{
return (
$a>=0?$a>>b : ( ( b : ((b:((a&0x7fffffff) >>b )  ( 0x40000000>> ( b) | (0x40000000>> (b)(0x40000000>>(b-1))
);
}
publicstaticfunctioncharAt(a , a,a,i)
{
returnself::substr(a , a,a,i,1);
}
publicstaticfunctionhex_md5(KaTeXparseerror: Expected'}', got'EOF'atendofinput: …r){ returnmd5(str);
}
publicstaticfunctiontoString(str , str,str,dec=null){
if(dec==16 ) returndechex ( dec==16)returndechex(dec==16)returndechex(str);
return (string)$str;
}
publicstaticfunctionreverse(KaTeXparseerror: Expected'}', got'EOF'atendofinput: array_reverse(arr);
}
publicstaticfunctionstring_lenght($string) {
returnstrlen(iconv(‘UTF-8, ‘UTF-16LE’, $string)) /2;
}
publicstaticfunctioncharCodeAt($str, $index){
//not working!char=mbsubstr ( char=mb_substr(char=mbsubstr(str, index , 1 , UTF8 ) ; if ( mbcheckencoding ( index, 1, 'UTF-8'); if (mb_check_encoding(index,1, 
UTF−8 );if(mbcheckencoding(char, ‘UTF-8))
{
ret=mbconvertencoding ( ret=mb_convert_encoding(ret=mbconvertencoding(char, ‘UTF-32BE’, ‘UTF-8);
returnhexdec(bin2hex($ret));
} else {
returnnull;
}
}
}
//一段由js代码转换而来的加密算法<?phpclassmmb_d{ static$zero=array("0", "00", "000", "0000", "00000", "000000", "0000000", "00000000"); static$chars=array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'); staticpublicfunctionstrReverse($a) { $b='';$c=array(); for ($b=0, $l=strlen($a); $b<$l; $b++) $c[] =$a{$b}; returnimplode('',array_reverse($c)); } staticpublicfunctionencrypt($a, $b, $e) { $a1=static::shuzi($a); $a2=static::zimu($a); $a=$a2 . $a1; $f=''; $g=array(); for ($f=0, $l=strlen($a); $f<$l; $f++) $g[] =static::to(js2php::charCodeAt($a,$f), $b); returnstatic::rnd($e?static::strReverse(implode("",$g)) : implode("",$g), 4); } staticpublicfunctionto($a, $c) { $e="" . js2php::toString(static::round($a+88, $c),16); $f=$c-strlen($e); return$f>0?static::$zero{$f-1} . $e : $e; } staticpublicfunctionround($a, $b) { $c=1<<4*$b; return0>$a?$a%$c+$c : $a%$c; } staticpublicfunctionshuzi($a) { returnpreg_replace('/[^0-9]+/i', "",$a); } staticpublicfunctionzimu($a) { returnpreg_replace('/[^a-zA-Z]+/i', "",preg_replace('/https/', "http",strtolower($a))); } staticpublicfunctionrnd($a, $b) { returnstatic::rd($b) . js2php::hex_md5($a) . static::rd(ceil(('0.'.mt_rand()) *10)); } staticpublicfunctionrd($a) { $res=""; for ( $i=0; $i<$a; $i++) { $res .=static::$chars[ceil(('0.'.mt_rand()) *35)]; } return$res; } } ?>


相关文章
|
1月前
|
PHP 数据安全/隐私保护
在PHP中使用AES进行加密和解密
在PHP中使用AES进行加密和解密
|
2月前
|
算法 JavaScript 前端开发
彩票中奖率的真相:用 JavaScript 看透彩票背后的随机算法(下)
至于分发?我们可以参考一下市面上已有的一些概念做一下对比,下面是笼统的一个网络服务器的TPS预估值,也就是说彩票服务器在1秒内可以处理的最大请求数:
|
2月前
|
数据采集 算法 JavaScript
彩票中奖率的真相:用 JavaScript 看透彩票背后的随机算法(上)
原本这篇文章是打算叫「假如我是彩票系统开发者」,但细想一下,如果在文章中引用太多的 JavaScript 的话,反而不是那么纯粹,毕竟也只是我的一厢情愿,彩票开发也不全如本文所讲,有所误导的话便也是得不偿失了。
|
3月前
|
移动开发 JavaScript 安全
js的常见的三种密码加密方式-MD5加密、Base64加密和解密和sha1加密详解总结
js的常见的三种密码加密方式-MD5加密、Base64加密和解密和sha1加密详解总结
112 0
|
17天前
|
安全 PHP 开发工具
php代码加密 php-screw-plus
php代码加密 php-screw-plus
17 0
|
24天前
|
PHP 数据安全/隐私保护
PHP在线加密系统网站源码
这个是sg的加密,免费可用(目前)并不会收费 源码说明:下载直接上传即可
19 1
PHP在线加密系统网站源码
|
1月前
|
缓存 JavaScript 算法
Vue.js中的diff算法:让虚拟DOM更高效
Vue.js中的diff算法:让虚拟DOM更高效
|
3月前
|
PHP 数据安全/隐私保护
|
3月前
|
PHP 数据安全/隐私保护
|
3月前
|
PHP 数据安全/隐私保护