D
D
dllweb2016-10-10 15:23:31
JavaScript
dllweb, 2016-10-10 15:23:31

What is this javascript magic?

Dear, who can explain what is happening here?

function hash(r, e) {
    var t = "23aagaAGGGGA245" + e + r + "ASDFsdgmjn8574zT";
    return secr(t);
}

!function (r, e) {
// ... очень много сжатого кода
    var t = "undefined" != typeof module;
    
    var n = "undefined",
        o = "0123456789abcdef".split(""),
        a = [-2147483648, 8388608, 32768, 128],
        c = [24, 16, 8, 0],
        i = [1116352408, 1899447441, 3049323471, 3921009573, 961987163, 1508970993, 2453635748, 2870763221, 3624381080, 310598401, 607225278, 1426881987, 1925078388, 2162078206, 2614888103, 3248222580, 3835390401, 4022224774, 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, 2554220882, 2821834349, 2952996808, 3210313671, 3336571891, 3584528711, 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291, 1695183700, 1986661051, 2177026350, 2456956037, 2730485921, 2820302411, 3259730800, 3345764771, 3516065817, 3600352804, 4094571909, 275423344, 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218, 1537002063, 1747873779, 1955562222, 2024104815, 2227730452, 2361852424, 2428436474, 2756734187, 3204031479, 3329325298],
        s = [];
    
    var u = function(r) {
            return h(r, !0)
        },

        h = function(r, e) {
            var t, n, u, h, f, _, l, A, v, y, d, R, p, m, x, L, g, z, S, b, k, E, T = !0,
                V = !1,
                Y = 0,
                q = 0,
                w = 0,
                U = r.length;
            e ? (t = 3238371032, n = 914150663, u = 812702999, h = 4144912697, f = 4290775857, _ = 1750603025, l = 1694076839, A = 3204075428) : (t = 1779033703, n = 3144134277, u = 1013904242, h = 2773480762, f = 1359893119, _ = 2600822924, l = 528734635, A = 1541459225), v = 0;
            do {
                if (s[0] = v, s[16] = s[1] = s[2] = s[3] = s[4] = s[5] = s[6] = s[7] = s[8] = s[9] = s[10] = s[11] = s[12] = s[13] = s[14] = s[15] = 0, r.__ARRAY__)
                    for (d = q; U > Y && 64 > d; ++Y) s[d >> 2] |= r[Y] << c[3 & d++];
                else
                    for (d = q; U > Y && 64 > d; ++Y) y = r.charCodeAt(Y), 128 > y ? s[d >> 2] |= y << c[3 & d++] : 2048 > y ? (s[d >> 2] |= (192 | y >> 6) << c[3 & d++], s[d >> 2] |= (128 | 63 & y) << c[3 & d++]) : 55296 > y || y >= 57344 ? (s[d >> 2] |= (224 | y >> 12) << c[3 & d++], s[d >> 2] |= (128 | y >> 6 & 63) << c[3 & d++], s[d >> 2] |= (128 | 63 & y) << c[3 & d++]) : (y = 65536 + ((1023 & y) << 10 | 1023 & r.charCodeAt(++Y)), s[d >> 2] |= (240 | y >> 18) << c[3 & d++], s[d >> 2] |= (128 | y >> 12 & 63) << c[3 & d++], s[d >> 2] |= (128 | y >> 6 & 63) << c[3 & d++], s[d >> 2] |= (128 | 63 & y) << c[3 & d++]);
                w += d - q, q = d - 64, Y == U && (s[d >> 2] |= a[3 & d], ++Y), v = s[16], Y > U && 56 > d && (s[15] = w << 3, V = !0);
                var B = t,
                    C = n,
                    J = u,
                    M = h,
                    N = f,
                    X = _,
                    D = l,
                    G = A;
                for (R = 16; 64 > R; ++R) L = s[R - 15], p = (L >>> 7 | L << 25) ^ (L >>> 18 | L << 14) ^ L >>> 3, L = s[R - 2], m = (L >>> 17 | L << 15) ^ (L >>> 19 | L << 13) ^ L >>> 10, s[R] = s[R - 16] + p + s[R - 7] + m << 0;
                for (E = C & J, R = 0; 64 > R; R += 4) T ? (e ? (S = 300032, L = s[0] - 1413257819, G = L - 150054599 << 0, M = L + 24177077 << 0) : (S = 704751109, L = s[0] - 210244248, G = L - 1521486534 << 0, M = L + 143694565 << 0), T = !1) : (p = (B >>> 2 | B << 30) ^ (B >>> 13 | B << 19) ^ (B >>> 22 | B << 10), m = (N >>> 6 | N << 26) ^ (N >>> 11 | N << 21) ^ (N >>> 25 | N << 7), S = B & C, x = S ^ B & J ^ E, z = N & X ^ ~N & D, L = G + m + z + i[R] + s[R], g = p + x, G = M + L << 0, M = L + g << 0), p = (M >>> 2 | M << 30) ^ (M >>> 13 | M << 19) ^ (M >>> 22 | M << 10), m = (G >>> 6 | G << 26) ^ (G >>> 11 | G << 21) ^ (G >>> 25 | G << 7), b = M & B, x = b ^ M & C ^ S, z = G & N ^ ~G & X, L = D + m + z + i[R + 1] + s[R + 1], g = p + x, D = J + L << 0, J = L + g << 0, p = (J >>> 2 | J << 30) ^ (J >>> 13 | J << 19) ^ (J >>> 22 | J << 10), m = (D >>> 6 | D << 26) ^ (D >>> 11 | D << 21) ^ (D >>> 25 | D << 7), k = J & M, x = k ^ J & B ^ b, z = D & G ^ ~D & N, L = X + m + z + i[R + 2] + s[R + 2], g = p + x, X = C + L << 0, C = L + g << 0, p = (C >>> 2 | C << 30) ^ (C >>> 13 | C << 19) ^ (C >>> 22 | C << 10), m = (X >>> 6 | X << 26) ^ (X >>> 11 | X << 21) ^ (X >>> 25 | X << 7), E = C & J, x = E ^ C & M ^ k, z = X & D ^ ~X & G, L = N + m + z + i[R + 3] + s[R + 3], g = p + x, N = B + L << 0, B = L + g << 0;
                t = t + B << 0, n = n + C << 0, u = u + J << 0, h = h + M << 0, f = f + N << 0, _ = _ + X << 0, l = l + D << 0, A = A + G << 0
            } while (!V);
            var H = o[t >> 28 & 15] + o[t >> 24 & 15] + o[t >> 20 & 15] + o[t >> 16 & 15] + o[t >> 12 & 15] + o[t >> 8 & 15] + o[t >> 4 & 15] + o[15 & t] + o[n >> 28 & 15] + o[n >> 24 & 15] + o[n >> 20 & 15] + o[n >> 16 & 15] + o[n >> 12 & 15] + o[n >> 8 & 15] + o[n >> 4 & 15] + o[15 & n] + o[u >> 28 & 15] + o[u >> 24 & 15] + o[u >> 20 & 15] + o[u >> 16 & 15] + o[u >> 12 & 15] + o[u >> 8 & 15] + o[u >> 4 & 15] + o[15 & u] + o[h >> 28 & 15] + o[h >> 24 & 15] + o[h >> 20 & 15] + o[h >> 16 & 15] + o[h >> 12 & 15] + o[h >> 8 & 15] + o[h >> 4 & 15] + o[15 & h] + o[f >> 28 & 15] + o[f >> 24 & 15] + o[f >> 20 & 15] + o[f >> 16 & 15] + o[f >> 12 & 15] + o[f >> 8 & 15] + o[f >> 4 & 15] + o[15 & f] + o[_ >> 28 & 15] + o[_ >> 24 & 15] + o[_ >> 20 & 15] + o[_ >> 16 & 15] + o[_ >> 12 & 15] + o[_ >> 8 & 15] + o[_ >> 4 & 15] + o[15 & _] + o[l >> 28 & 15] + o[l >> 24 & 15] + o[l >> 20 & 15] + o[l >> 16 & 15] + o[l >> 12 & 15] + o[l >> 8 & 15] + o[l >> 4 & 15] + o[15 & l];
            return e || (H += o[A >> 28 & 15] + o[A >> 24 & 15] + o[A >> 20 & 15] + o[A >> 16 & 15] + o[A >> 12 & 15] + o[A >> 8 & 15] + o[A >> 4 & 15] + o[15 & A])
        };
     r && (r.secr = h, r.sha224 = u)

}(this);

In the body of the hash function, the secr(t) function is called with the argument t being passed,
but further, it is not clear to me why after the end of the hash function body there is !function(){}(this);
what does !function mean and how does it turn out that a function called secr() is called, but the function itself with the name secr simply does not exist, that is, they are not declared anywhere, what is it, how to understand?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Ineshin, 2016-10-10
@dllweb

Very simple
1. !function- shorthand for self-invoking functions
2. !function(){}(this);- this refers to the global object, in our case it is window
3. At the end of this function, a reference to secr is created, like this r.secr = h. r- this window, i.e. this is where function window.secr
4 was created. Now we can safely call secr(t). This is the same as calling window.secr(t). In step 3, this function was created.
Those. h- this is your functionsecr

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question