Java Script generateToken(String val)

Here you can find the source of generateToken(String val)

Description

generate Token

License

Apache License

Declaration

public static String generateToken(String val) 

Method Source Code

//package com.java2s;
/**/*ww  w .j a  va 2  s . c  om*/
 * Copyright 2016-2017 linghushaoxia
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

public class Main {

    public static String generateToken(String val) {
        try {
            String script = "function tk(a) {"
                    + "var TKK = ((function() {var a = 561666268;var b = 1526272306;return 406398 + '.' + (a + b); })());\n"
                    + "function b(a, b) { for (var d = 0; d < b.length - 2; d += 3) { var c = b.charAt(d + 2), c = 'a' <= c ? c.charCodeAt(0) - 87 : Number(c), c = '+' == b.charAt(d + 1) ? a >>> c : a << c; a = '+' == b.charAt(d) ? a + c & 4294967295 : a ^ c } return a }\n"
                    + "for (var e = TKK.split('.'), h = Number(e[0]) || 0, g = [], d = 0, f = 0; f < a.length; f++) {"
                    + "var c = a.charCodeAt(f);"
                    + "128 > c ? g[d++] = c : (2048 > c ? g[d++] = c >> 6 | 192 : (55296 == (c & 64512) && f + 1 < a.length && 56320 == (a.charCodeAt(f + 1) & 64512) ? (c = 65536 + ((c & 1023) << 10) + (a.charCodeAt(++f) & 1023), g[d++] = c >> 18 | 240, g[d++] = c >> 12 & 63 | 128) : g[d++] = c >> 12 | 224, g[d++] = c >> 6 & 63 | 128), g[d++] = c & 63 | 128)"
                    + "}" + "a = h;" + "for (d = 0; d < g.length; d++) a += g[d], a = b(a, '+-a^+6');"
                    + "a = b(a, '+-3^+b+-f');" + "a ^= Number(e[1]) || 0;"
                    + "0 > a && (a = (a & 2147483647) + 2147483648);" + "a %= 1E6;"
                    + "return a.toString() + '.' + (a ^ h)\n" + "}";
            ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
            engine.eval(script);
            Invocable inv = (Invocable) engine;
            return (String) inv.invokeFunction("tk", val);
        } catch (Exception e) {
            // TODO: handle exception
        }
        return "";
    }
}

Related

  1. evaluateExpression(String s)
  2. executeAppleScript(String script)
  3. executeScript(String script)
  4. executeScript(String strScript)
  5. fillStringCollection(ScriptObjectMirror som, Collection collection)
  6. getBallerinaFromJsonModel(String jsonModel)
  7. getDynamicInput(String key)
  8. getScript(String name)
  9. getScriptCompileMsg(ScriptException ex)