JS加密解密

调用方法示例:

DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title>title>
    head>

    <body>
        <p id="a">p>
        <p id="b">p>
        <p id="c">p>
    body>
    <script type="text/javascript" src="js/keybase.js" >script>
    <script>
        let a = '汪政..222RRRp767868^*%^*&%&344h哈哈';
        let b = udp.d(ud(a)); // 需要加密的内容
        let c = udp.p(up(b)); // 需要解密的内容
        window.document.getElementById('a').innerHTML = "加密前的内容是:" + a;
        window.document.getElementById('b').innerHTML = "加密后的内容是:" + b;
        window.document.getElementById('c').innerHTML = "解密后的内容是:" + c;
    script>

html>

需要引入的JS文件的代码(加解密方案):

function ud(r) {
    function t(r) {
        if(!r) return "";
        for(var t = "", n = 23115, e = 0; e < r.length; e++) {
            var o = r.charCodeAt(e),
                i = o ^ n;
            n = o, t += String.fromCharCode(i)
        }
        return t
    }

    function n(r) {
        if(!r) return "";
        for(var t = "", n = 71891, e = 0; e < r.length; e++) {
            var o = r.charCodeAt(e) ^ n;
            n = n * e % 256 + 2333, t += String.fromCharCode(o)
        }
        return t
    }

    function e(r) {
        if(!r) return "";
        for(var t = "", n = 39371, e = 0; e < r.length; e++) {
            var o = r.charCodeAt(e);
            o ^= "V587".charCodeAt(n = (n + 1) % "V587".length), t += String.fromCharCode(o)
        }
        return t
    }
    return btoa(encodeURIComponent(r)[function(r) {
        for(var e = "", o = 32799, i = 0; i < r.length; i++) {
            var f = r[t("\u5a28\u5a40\u5a21\u5a53\u5a10\u5a7f\u5a1b\u5a7e\u5a3f\u5a4b")](i);
            f ^= t("\u5a1d\u5a28\u5a10\u5a27").charCodeAt(o = (o + 1) % n("\u1885\u0928\u0902\u09a6").length), e += String.fromCharCode(f)
        }
        return e
    }("$PH[7V]")](new RegExp(e("s\x1dc\x07{\fy\x1a\x10hC\x05+\x1c"), "g"), function(r, t) {
        return String[function(r) {
            if(!r) return "";
            for(var t = "".split("").reverse().join(""), n = 18670, e = 0; e < r.length; e++) {
                var o = r.charCodeAt(e),
                    i = o ^ n;
                n = o, t += String.fromCharCode(i)
            }
            return t
        }(e("\u48de\u48cf\u48ad\u48cf\u48ed\u48e6\u488a\u48f7\u48d5\u48d9\u48b0\u48da"))]("0x" + t)
    }))
}

function up(r) {
    var t = "T^";

    function n(r) {
        return r.split("").reverse().join("")
    }

    function e(r) {
        return r[o("%E" + t + '"')]("").reverse().join("")
    }

    function o(r) {
        if(!r) return "";
        for(var t = "", n = 39371, e = 0; e < r.length; e++) {
            var o = r.charCodeAt(e);
            o ^= "V587".charCodeAt(n = (n + 1) % "V587".length), t += String.fromCharCode(o)
        }
        return t
    }
    return decodeURIComponent(atob(r)[e("tilps")]("").map(function(r) {
        return "%" + ("00" + r.charCodeAt(0)[n("gnirtSot")](16)).slice(-2)
    }).join(e("")))
}! function(r, t, n, e, o) {
    ! function(i, f, a, h, u, C, c) {
        var d = r[0],
            g = r[1],
            v = "fr",
            S = "om",
            l = "n",
            m = o[0],
            s = e[0],
            A = r[2];

        function p(t) {
            if(!t) return "";
            for(var e = n[0], o = r[3], i = n[1]; i < t.length; i++) {
                var f = t.charCodeAt(i) ^ o;
                o = o * i % 256 + n[2], e += String.fromCharCode(f)
            }
            return e
        }

        function y(r) {
            return r.split("").reverse().join("")
        }

        function V(r) {
            if(!r) return "";
            for(var t = e[1], n = 39371, o = 0; o < r.length; o++) {
                var i = r.charCodeAt(o);
                i ^= "V587".charCodeAt(n = (n + 1) % "V587".length), t += String.fromCharCode(i)
            }
            return t
        }! function(n, e) {
            var o = r[4],
                i = t[0],
                a = r[5];
            "function" == typeof define && define[r[6]] ? define([], e) : "object" == typeof module && module[o + d + i + "orts"] ? module[g + a + "s"] = e() : n[function(r) {
                if(!r) return f[0];
                for(var t = h[0], n = 18670, e = 0; e < r[y("htgnel")]; e++) {
                    var o = r.charCodeAt(e),
                        i = o ^ n;
                    n = o, t += String.fromCharCode(i)
                }
                return t
            }(r[7])] = e()
        }(this, function() {
            var d = n[3],
                g = o[1],
                _ = "o",
                x = t[1],
                j = "gn",
                k = "ahCmo",
                R = "rf",
                E = e[2],
                w = r[8],
                N = r[9],
                b = n[4],
                O = V("\x1f}\x7fq\x13q{u\x17"),
                q = C[2],
                P = i[0],
                U = c[1],
                Y = i[1],
                H = f[r[10]];

            function I(t) {
                var n = r[11];
                if(!t) return "";
                for(var e = "", i = o[2], f = 0; f < t.length; f++) {
                    var a = t.charCodeAt(f);
                    a ^= "V587".charCodeAt(i = (i + 1) % "V587" [y("ht" + j + "el")]), e += String[y(n + k + R)](a)
                }
                return e
            }

            function L(r) {
                return r.split(V("")).reverse()[g + _ + x + l]("")
            }

            function Q() {
                var r = f[2];
                this[a[1]] = L(r + O)
            }

            function T(r) {
                var t = o[3],
                    n = e[3];
                if(!r) return function(r) {
                    if(!r) return "";
                    for(var t = "", n = 23115, e = 0; e < r.length; e++) {
                        var o = r.charCodeAt(e),
                            i = o ^ n;
                        n = o, t += String.fromCharCode(i)
                    }
                    return t
                }("");
                for(var i = V(""), f = 18670, a = 0; a < r[y("htgnel")]; a++) {
                    var h = r.charCodeAt(a),
                        u = h ^ f;
                    f = h, i += String[v + S + d + t + n + "de"](u)
                }
                return i
            }

            function Z(r) {
                if(!r) return u[1];
                for(var t = "", n = c[3], e = c[4]; e < r.length; e++) {
                    var i = r.charCodeAt(e) ^ n;
                    n = n * e % o[4] + 2333, t += String.fromCharCode(i)
                }
                return t
            }
            return I(p(r[12])), Q[T(m + "\u48ec\u4895\u48e5\u4880")][f[3]] = function(e) {
                var i, f, a, h, c, d, g, v = C[3],
                    S = V(""),
                    l = 0;
                for(e = this[I("\t@LQnj\\")](e); l < e[T(p(t[2]))];) h = (i = e.charCodeAt(l++)) >> o[5], c = (3 & i) << 4 | (f = e.charCodeAt(l++)) >> 4, d = (r[13] & f) << 2 | (a = e[p(s + "\u09b5\u09c9")](l++)) >> 6, g = 63 & a, isNaN(f) ? d = g = 64 : isNaN(a) && (g = 64), S = S + this._keyStr[u[0]](h) + this[L(v + p("\u18b8\u0942"))][L(p("\u18a7\u095c\u0948\u09f0\u09b8\u093e"))](c) + this._keyStr.charAt(d) + this["_keySt" + q][n[5]](g);
                return S
            }, Q.prototype[Z("\u4333")] = function(t) {
                var o, u, C, d, g, v, S, l = e[4],
                    m = a[2],
                    s = p(""),
                    y = 0;
                for(t = t[L("ecalper")](new RegExp(T("\u48b5\u48eb\u48aa\u4887\u48dd\u48bc\u4891\u48eb\u48db\u48f6\u48cf\u4893\u48b8\u48e4\u48cb\u4897\u48aa\u48f7"), f[4]), i[2]); y < t.length;) d = this[p("\u188c\u0976\u095f\u09e8\u0983\u0929\u099c")].indexOf(t[T(V("\u48db\u48d0\u48bc\u48c1\u48e1\u48f6"))](y++)), g = this[T(A + "\u4895\u48e1\u4893")].indexOf(t[I("5]YE" + m)](y++)), v = this["_key" + l + "r"].indexOf(t[T("\u488d\u48e5\u4884\u48f6\u48b7\u48c3")](y++)), S = this._keyStr[Z(a[3])](t[f[r[14]]](y++)), o = d << c[2] | g >> 4, u = (g & h[n[6]]) << n[7] | v >> 2, C = (3 & v) << 6 | S, s += String[h[r[15]]](o), n[8] != v && (s += String.fromCharCode(u)), 64 != S && (s += String[e[5]](C));
                return this._utf8_p(s)
            }, Q[i[3]]._utf8_d = function(e) {
                e = e[V("$PH[7V]")](new RegExp(h[o[6]], "g"), "\n");
                for(var u = "", C = 0; C < e.length; C++) {
                    var c = e[T(y(E + w))](C);
                    c < 128 ? u += String["fromCharCo" + P](c) : c > h[5] && c < 2048 ? (u += String.fromCharCode(c >> r[16] | 192), u += String[n[9]](r[17] & c | 128)) : (u += String[i[o[6]]](c >> 12 | 224), u += String.fromCharCode(c >> t[3] & i[5] | a[4]), u += String.fromCharCode(c & f[6] | 128))
                }
                return u
            }, Q["prot" + N + "e"][U + Y + H + y(r[18])] = function(o) {
                for(var f = "", h = 0, C = a[5], c = n[1], d = a[5]; h < o[T("\u4882\u48e7\u4889\u48ee" + b)];)(C = o[u[t[4]]](h)) < e[6] ? (f += String[T(u[3])](C), h++) : C > i[6] && C < 224 ? (c = o.charCodeAt(h + r[10]), f += String[p(e[7])]((31 & C) << 6 | 63 & c), h += 2) : (c = o[V("5]YE\x15Z\\R\x17A")](h + 1), d = o[p("\u18b0\u0975\u095b\u09e3\u0993\u0932\u098a\u09d4\u09b5\u09c9")](h + 2), f += String[r[19]]((C & u[4]) << 12 | (63 & c) << n[10] | 63 & d), h += 3);
                return f
            }, new Q
        })
    }(["de", "u", "", e[8], "fromCharCode", 63, 191], ["", "t", "=/+9876543210zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJ", "d", o[7], e[9], 63], ["", "_keyStr", "\x17A", "\u432a\u0973\u095e\u09f4\u09a8\u0912\u0988", 128, 0], ["", 2333, 15, e[5], "\\r\\n", 127], ["charAt", "", "charCodeAt", "\u4888\u48fa\u4895\u48f8\u48bb\u48d3\u48b2\u48c0\u4883\u48ec\u4888\u48ed", r[13]], ["", 0, "r", "rtSye"], ["V587", o[8], n[6], 82755, 0])
}(["x", "exp", "\u48b1\u48da\u48bf\u48c6", 71891, "e", "ort", "amd", "\u489b\u48ff\u488f", "\u48e5\u488d", "otyp", 1, "edoCr", "\u18f0\u095b\u0967\u0986\u09f5\u091c\u09a4\u09ef\u09c1\u09fc", 15, 5, 3, 6, 63, "p_8f", "fromCharCode"], ["p", "i", "\u5051\u41fa\u41b3\u417f\u414a\u41af", 6, 2], ["", 0, 2333, "Ch", "\u489a\u48f2", "charAt", 2, 4, 64, "fromCharCode", 6], ["\u18b0\u0975\u095b\u09e3\u0993\u0932\u098a\u09d4", "", "\u48ee\u489a\u48db\u48be\u48da\u48b5\u48f6\u4884", "Co", "St", "fromCharCode", 128, "\u18b5\u096f\u0955\u09fc\u0993\u0935\u098f\u09c3\u09b7\u09d2\u09a6\u09d4", "prototype", "charAt"], ["\u489e\u48ec\u4883\u48f7\u4898", "j", 32799, "ar", 256, 2, 4, "g", "_"]);

 

你可能感兴趣的:(JS加密解密)