燃鹅解密PHP版,可做接口
PHP版
<?php /* * @Author: ZeroArt * @Date: 2021-02-25 * @Link: http://www.8gws.com * @LastEditors: ZeroArt */ class rane { // utf8编码 function decodeUtf8($bytes) { $encoded = ""; for ($i = 0; $i < count($bytes); $i++) { $encoded .= '%' . dechex($bytes[$i]); } return urldecode($encoded); } // 数组转字符串 function dec($t) { if (is_string($t)) { return $t; } else { $n = []; for ($i = 0; $i < count($t); $i++) { $n[] = $t[$i]; } } return $this->decodeUtf8($n); } // hex字符串转数组 public function n($t) { $e = 0; $n = strlen($t); if ($n % 2 != 0) { return null; } else { $n /= 2; $o = []; for ($i = 0; $i < $n; $i++) { $r = substr($t, $e, 2); $a = hexdec($r); $o[] = $a; $e += 2; } $os = []; foreach ($o as $key => $value) { $os[] = $value; } return $os; } } // 加解密核心算法 function m($t, $e) { $a = []; $n = ""; $o = count($e); $i = ($t ^ $o) % 255; $r = (($o & $i) + ($t ^ $i)) % 255; $a = []; $s = 0; for ($s = 0; $s < $o; $s++) { $i -= ($r * $o ^ $t) % 255; $t -= $r; $n = 255 & (($n = $e[$s]) ^ ($r = $i % 255)); $a[] = $n; } return $a; } } $rane = new rane(); // 常规模式 if (isset($_GET['t']) && isset($_GET['v'])) { echo ($rane->dec($rane->m($_GET['t'], $rane->n($_GET['v'])))); exit(); } // JOSN格式 if (isset($_GET['json']) || isset($_POST['json'])) { $param = json_decode($_REQUEST['json'], true); echo ($rane->dec($rane->m($param['t'], $rane->n($param['v'])))); exit(); } // 案例 if (isset($_GET['dome'])) { echo ($rane->dec($rane->m('59131814', $rane->n('ad88eff390bd7706d24a93f04727c0d61f886f3f4922680c5cb7f8716073379a625845875d6708477d3014f31e575098b983ce709bd1f7f3f7fa63f6e12eb216ade7a43e314048cc80d73c18d6a8d72cb1f231593b4aa9ef56a170fbf9db23d07048589053d56fa4bafdbbe8b52720d938f6b4f85a2dd0092805fc2c6aa4c8fd3b92a89c7786368eb0e979d96c03831412d23d008a491b68295d893c77251902dba8ee84fe390efbee01d65815254bd9bbe1bd7e12b1fc0542bfc893d0ac83c3b7abafbc6328aa37f89a378fce83e01d49d19ef4ed20893993870501fdef066e092a27fc45a7ce8c0d54fa0244f6b7a2388be2a7fba0aa80cbe313194886d0ace13ab730f0288e987fa31088d4f559d74a14a8f057254e070b8b')))); exit; } // 提示 $msg = [ [ "JSON请求" => "?json={'t'=>'59131814','v'=>'xxxxxx'}" ], [ "常规请求" => "?t=59131814&v=xxxxxx" ] ]; echo "<pre>"; var_dump($msg); echo "</pre>";Js版(可加密)
// utf8编码 - www.8gws.com function decodeUtf8(bytes) { var encoded = ""; for (var i = 0; i < bytes.length; i++) { encoded += '%' + bytes[i].toString(16); } return decodeURIComponent(encoded); } // 数组转字符串 function dec(t) { if ("string" == typeof t) return t; for (var n = [], i = 0; i < t.length; i++) { n.push(t[i]); } return decodeUtf8(n); } // hex字符串转数组 function n(t) { var e = 0, n = t.length; if (n % 2 != 0) return null; n /= 2; for (var o = [], i = 0; i < n; i++) { var r = t.substr(e, 2), a = parseInt(r, 16); o.push(a), e += 2; } return o; } // 加解密核心算法 function m(t, e) { for (var n, o = e.length, i = (t ^ o) % 255, r = ((o & i) + (t ^ i)) % 255, a = [], s = 0; s < o; s++) { i -= (r * o ^ t) % 255, t -= r, n = 255 & ((n = e[s]) ^ (r = i % 255)), a.push(n); } return a; } // 字符串转字节 function stringToByte(t) { var e, n, o = new Array(); e = t.length; for (var i = 0; i < e; i++) { (n = t.charCodeAt(i)) >= 65536 && n <= 1114111 ? (o.push(n >> 18 & 7 | 240), o.push(n >> 12 & 63 | 128), o.push(n >> 6 & 63 | 128), o.push(63 & n | 128)) : n >= 2048 && n <= 65535 ? (o.push(n >> 12 & 15 | 224), o.push(n >> 6 & 63 | 128), o.push(63 & n | 128)) : n >= 128 && n <= 2047 ? (o.push(n >> 6 & 31 | 192), o.push(63 & n | 128)) : o.push(255 & n); } return o; } // 数组转hex字符串 function parseByte2HexStr(t) { for (var e = "", n = 0; n < t.length; n++) { var o = t[n].toString(16); 1 == o.length && (o = "0" + o), e += o; } return e; } // 解密数据,a和b分别为t和v function decode(a, b) { return dec(m(a, n(b))) } // 加密数据,e和n分别为t和v function encode(e, n) { return parseByte2HexStr(m(e, stringToByte(n))) } // t值,v值 decode("59131814",'xxxxxx');