"use strict";

function q(a) {
    throw a
}

function y(a, b, c) {
    4 !== b.length && q(new sjcl.exception.invalid("invalid aes block size"));
    var d = a.a[c],
        e = b[0] ^ d[0],
        f = b[c ? 3 : 1] ^ d[1],
        g = b[2] ^ d[2];
    b = b[c ? 1 : 3] ^ d[3];
    var h, i, j, k, l = d.length / 4 - 2,
        m = 4,
        n = [0, 0, 0, 0];
    h = a.j[c], a = h[0];
    var o = h[1],
        p = h[2],
        r = h[3],
        s = h[4];
    for (k = 0; l > k; k++) h = a[e >>> 24] ^ o[f >> 16 & 255] ^ p[g >> 8 & 255] ^ r[255 & b] ^ d[m], i = a[f >>> 24] ^ o[g >> 16 & 255] ^ p[b >> 8 & 255] ^ r[255 & e] ^ d[m + 1], j = a[g >>> 24] ^ o[b >> 16 & 255] ^ p[e >> 8 & 255] ^ r[255 & f] ^ d[m + 2], b = a[b >>> 24] ^ o[e >> 16 & 255] ^ p[f >> 8 & 255] ^ r[255 & g] ^ d[m + 3], m += 4, e = h, f = i, g = j;
    for (k = 0; 4 > k; k++) n[c ? 3 & -k : k] = s[e >>> 24] << 24 ^ s[f >> 16 & 255] << 16 ^ s[g >> 8 & 255] << 8 ^ s[255 & b] ^ d[m++], h = e, e = f, f = g, g = b, b = h;
    return n
}

function z(a, b) {
    var c, d, e, f = b.slice(0),
        g = a.q,
        h = a.a,
        i = g[0],
        j = g[1],
        k = g[2],
        l = g[3],
        m = g[4],
        n = g[5],
        o = g[6],
        p = g[7];
    for (c = 0; 64 > c; c++) 16 > c ? d = f[c] : (d = f[c + 1 & 15], e = f[c + 14 & 15], d = f[15 & c] = (d >>> 7 ^ d >>> 18 ^ d >>> 3 ^ d << 25 ^ d << 14) + (e >>> 17 ^ e >>> 19 ^ e >>> 10 ^ e << 15 ^ e << 13) + f[15 & c] + f[c + 9 & 15] | 0), d = d + p + (m >>> 6 ^ m >>> 11 ^ m >>> 25 ^ m << 26 ^ m << 21 ^ m << 7) + (o ^ m & (n ^ o)) + h[c], p = o, o = n, n = m, m = l + d | 0, l = k, k = j, j = i, i = d + (j & k ^ l & (j ^ k)) + (j >>> 2 ^ j >>> 13 ^ j >>> 22 ^ j << 30 ^ j << 19 ^ j << 10) | 0;
    g[0] = g[0] + i | 0, g[1] = g[1] + j | 0, g[2] = g[2] + k | 0, g[3] = g[3] + l | 0, g[4] = g[4] + m | 0, g[5] = g[5] + n | 0, g[6] = g[6] + o | 0, g[7] = g[7] + p | 0
}

function C(a, b) {
    var c, d = sjcl.random.z[a],
        e = [];
    for (c in d) d.hasOwnProperty(c) && e.push(d[c]);
    for (c = 0; c < e.length; c++) e[c](b)
}

function A(a) {
    a.a = B(a).concat(B(a)), a.A = new sjcl.cipher.aes(a.a)
}

function B(a) {
    for (var b = 0; 4 > b && (a.e[b] = a.e[b] + 1 | 0, !a.e[b]); b++);
    return a.A.encrypt(a.e)
}
var t = void 0,
    u = !1,
    sjcl = {
        cipher: {},
        hash: {},
        keyexchange: {},
        mode: {},
        misc: {},
        codec: {},
        exception: {
            corrupt: function(a) {
                this.toString = function() {
                    return "CORRUPT: " + this.message
                }, this.message = a
            },
            invalid: function(a) {
                this.toString = function() {
                    return "INVALID: " + this.message
                }, this.message = a
            },
            bug: function(a) {
                this.toString = function() {
                    return "BUG: " + this.message
                }, this.message = a
            },
            notReady: function(a) {
                this.toString = function() {
                    return "NOT READY: " + this.message
                }, this.message = a
            }
        }
    };
"undefined" != typeof module && module.exports && (module.exports = sjcl), sjcl.cipher.aes = function(a) {
    this.j[0][0][0] || this.D();
    var b, c, d, e, f = this.j[0][4],
        g = this.j[1];
    b = a.length;
    var h = 1;
    for (4 !== b && 6 !== b && 8 !== b && q(new sjcl.exception.invalid("invalid aes key size")), this.a = [d = a.slice(0), e = []], a = b; 4 * b + 28 > a; a++) c = d[a - 1], (0 === a % b || 8 === b && 4 === a % b) && (c = f[c >>> 24] << 24 ^ f[c >> 16 & 255] << 16 ^ f[c >> 8 & 255] << 8 ^ f[255 & c], 0 === a % b && (c = c << 8 ^ c >>> 24 ^ h << 24, h = h << 1 ^ 283 * (h >> 7))), d[a] = d[a - b] ^ c;
    for (b = 0; a; b++, a--) c = d[3 & b ? a : a - 4], e[b] = 4 >= a || 4 > b ? c : g[0][f[c >>> 24]] ^ g[1][f[c >> 16 & 255]] ^ g[2][f[c >> 8 & 255]] ^ g[3][f[255 & c]]
}, sjcl.cipher.aes.prototype = {
    encrypt: function(a) {
        return y(this, a, 0)
    },
    decrypt: function(a) {
        return y(this, a, 1)
    },
    j: [
        [
            [],
            [],
            [],
            [],
            []
        ],
        [
            [],
            [],
            [],
            [],
            []
        ]
    ],
    D: function() {
        var a, b, c, d, e, f, g, h = this.j[0],
            i = this.j[1],
            j = h[4],
            k = i[4],
            l = [],
            m = [];
        for (a = 0; 256 > a; a++) m[(l[a] = a << 1 ^ 283 * (a >> 7)) ^ a] = a;
        for (b = c = 0; !j[b]; b ^= d || 1, c = m[c] || 1)
            for (f = c ^ c << 1 ^ c << 2 ^ c << 3 ^ c << 4, f = f >> 8 ^ 255 & f ^ 99, j[b] = f, k[f] = b, e = l[a = l[d = l[b]]], g = 16843009 * e ^ 65537 * a ^ 257 * d ^ 16843008 * b, e = 257 * l[f] ^ 16843008 * f, a = 0; 4 > a; a++) h[a][b] = e = e << 24 ^ e >>> 8, i[a][f] = g = g << 24 ^ g >>> 8;
        for (a = 0; 5 > a; a++) h[a] = h[a].slice(0), i[a] = i[a].slice(0)
    }
}, sjcl.bitArray = {
    bitSlice: function(a, b, c) {
        return a = sjcl.bitArray.P(a.slice(b / 32), 32 - (31 & b)).slice(1), c === t ? a : sjcl.bitArray.clamp(a, c - b)
    },
    extract: function(a, b, c) {
        var d = Math.floor(-b - c & 31);
        return (-32 & (b + c - 1 ^ b) ? a[b / 32 | 0] << 32 - d ^ a[b / 32 + 1 | 0] >>> d : a[b / 32 | 0] >>> d) & (1 << c) - 1
    },
    concat: function(a, b) {
        if (0 === a.length || 0 === b.length) return a.concat(b);
        var c = a[a.length - 1],
            d = sjcl.bitArray.getPartial(c);
        return 32 === d ? a.concat(b) : sjcl.bitArray.P(b, d, 0 | c, a.slice(0, a.length - 1))
    },
    bitLength: function(a) {
        var b = a.length;
        return 0 === b ? 0 : 32 * (b - 1) + sjcl.bitArray.getPartial(a[b - 1])
    },
    clamp: function(a, b) {
        if (32 * a.length < b) return a;
        a = a.slice(0, Math.ceil(b / 32));
        var c = a.length;
        return b &= 31, c > 0 && b && (a[c - 1] = sjcl.bitArray.partial(b, a[c - 1] & 2147483648 >> b - 1, 1)), a
    },
    partial: function(a, b, c) {
        return 32 === a ? b : (c ? 0 | b : b << 32 - a) + 1099511627776 * a
    },
    getPartial: function(a) {
        return Math.round(a / 1099511627776) || 32
    },
    equal: function(a, b) {
        if (sjcl.bitArray.bitLength(a) !== sjcl.bitArray.bitLength(b)) return u;
        var c, d = 0;
        for (c = 0; c < a.length; c++) d |= a[c] ^ b[c];
        return 0 === d
    },
    P: function(a, b, c, d) {
        var e;
        for (e = 0, d === t && (d = []); b >= 32; b -= 32) d.push(c), c = 0;
        if (0 === b) return d.concat(a);
        for (e = 0; e < a.length; e++) d.push(c | a[e] >>> b), c = a[e] << 32 - b;
        return e = a.length ? a[a.length - 1] : 0, a = sjcl.bitArray.getPartial(e), d.push(sjcl.bitArray.partial(b + a & 31, b + a > 32 ? c : d.pop(), 1)), d
    },
    k: function(a, b) {
        return [a[0] ^ b[0], a[1] ^ b[1], a[2] ^ b[2], a[3] ^ b[3]]
    }
}, sjcl.codec.utf8String = {
    fromBits: function(a) {
        var b, c, d = "",
            e = sjcl.bitArray.bitLength(a);
        for (b = 0; e / 8 > b; b++) 0 === (3 & b) && (c = a[b / 4]), d += String.fromCharCode(c >>> 24), c <<= 8;
        return decodeURIComponent(escape(d))
    },
    toBits: function(a) {
        a = unescape(encodeURIComponent(a));
        var b, c = [],
            d = 0;
        for (b = 0; b < a.length; b++) d = d << 8 | a.charCodeAt(b), 3 === (3 & b) && (c.push(d), d = 0);
        return 3 & b && c.push(sjcl.bitArray.partial(8 * (3 & b), d)), c
    }
}, sjcl.codec.hex = {
    fromBits: function(a) {
        var b, c = "";
        for (b = 0; b < a.length; b++) c += ((0 | a[b]) + 0xf00000000000).toString(16).substr(4);
        return c.substr(0, sjcl.bitArray.bitLength(a) / 4)
    },
    toBits: function(a) {
        var b, c, d = [];
        for (a = a.replace(/\s|0x/g, ""), c = a.length, a += "00000000", b = 0; b < a.length; b += 8) d.push(0 ^ parseInt(a.substr(b, 8), 16));
        return sjcl.bitArray.clamp(d, 4 * c)
    }
}, sjcl.codec.base64 = {
    J: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
    fromBits: function(a, b, c) {
        var d = "",
            e = 0,
            f = sjcl.codec.base64.J,
            g = 0,
            h = sjcl.bitArray.bitLength(a);
        for (c && (f = f.substr(0, 62) + "-_"), c = 0; 6 * d.length < h;) d += f.charAt((g ^ a[c] >>> e) >>> 26), 6 > e ? (g = a[c] << 6 - e, e += 26, c++) : (g <<= 6, e -= 6);
        for (; 3 & d.length && !b;) d += "=";
        return d
    },
    toBits: function(a, b) {
        a = a.replace(/\s|=/g, "");
        var c, d, e = [],
            f = 0,
            g = sjcl.codec.base64.J,
            h = 0;
        for (b && (g = g.substr(0, 62) + "-_"), c = 0; c < a.length; c++) d = g.indexOf(a.charAt(c)), 0 > d && q(new sjcl.exception.invalid("this isn't base64!")), f > 26 ? (f -= 26, e.push(h ^ d >>> f), h = d << 32 - f) : (f += 6, h ^= d << 32 - f);
        return 56 & f && e.push(sjcl.bitArray.partial(56 & f, h, 1)), e
    }
}, sjcl.codec.base64url = {
    fromBits: function(a) {
        return sjcl.codec.base64.fromBits(a, 1, 1)
    },
    toBits: function(a) {
        return sjcl.codec.base64.toBits(a, 1)
    }
}, sjcl.codec.bytes = {
    fromBits: function(a) {
        var b, c, d = [],
            e = sjcl.bitArray.bitLength(a);
        for (b = 0; e / 8 > b; b++) 0 === (3 & b) && (c = a[b / 4]), d.push(c >>> 24), c <<= 8;
        return d
    },
    toBits: function(a) {
        var b, c = [],
            d = 0;
        for (b = 0; b < a.length; b++) d = d << 8 | a[b], 3 === (3 & b) && (c.push(d), d = 0);
        return 3 & b && c.push(sjcl.bitArray.partial(8 * (3 & b), d)), c
    }
}, sjcl.hash.sha256 = function(a) {
    this.a[0] || this.D(), a ? (this.q = a.q.slice(0), this.n = a.n.slice(0), this.g = a.g) : this.reset()
}, sjcl.hash.sha256.hash = function(a) {
    return (new sjcl.hash.sha256).update(a).finalize()
}, sjcl.hash.sha256.prototype = {
    blockSize: 512,
    reset: function() {
        return this.q = this.N.slice(0), this.n = [], this.g = 0, this
    },
    update: function(a) {
        "string" == typeof a && (a = sjcl.codec.utf8String.toBits(a));
        var b, c = this.n = sjcl.bitArray.concat(this.n, a);
        for (b = this.g, a = this.g = b + sjcl.bitArray.bitLength(a), b = 512 + b & -512; a >= b; b += 512) z(this, c.splice(0, 16));
        return this
    },
    finalize: function() {
        var a, b = this.n,
            c = this.q,
            b = sjcl.bitArray.concat(b, [sjcl.bitArray.partial(1, 1)]);
        for (a = b.length + 2; 15 & a; a++) b.push(0);
        for (b.push(Math.floor(this.g / 4294967296)), b.push(0 | this.g); b.length;) z(this, b.splice(0, 16));
        return this.reset(), c
    },
    N: [],
    a: [],
    D: function() {
        function a(a) {
            return 4294967296 * (a - Math.floor(a)) | 0
        }
        var b, c = 0,
            d = 2;
        a: for (; 64 > c; d++) {
            for (b = 2; d >= b * b; b++)
                if (0 === d % b) continue a;
            8 > c && (this.N[c] = a(Math.pow(d, .5))), this.a[c] = a(Math.pow(d, 1 / 3)), c++
        }
    }
}, sjcl.mode.ccm = {
    name: "ccm",
    encrypt: function(a, b, c, d, e) {
        var f, g = b.slice(0),
            h = sjcl.bitArray,
            i = h.bitLength(c) / 8,
            j = h.bitLength(g) / 8;
        for (e = e || 64, d = d || [], 7 > i && q(new sjcl.exception.invalid("ccm: iv must be at least 7 bytes")), f = 2; 4 > f && j >>> 8 * f; f++);
        return 15 - i > f && (f = 15 - i), c = h.clamp(c, 8 * (15 - f)), b = sjcl.mode.ccm.L(a, b, c, d, e, f), g = sjcl.mode.ccm.o(a, g, c, b, e, f), h.concat(g.data, g.tag)
    },
    decrypt: function(a, b, c, d, e) {
        e = e || 64, d = d || [];
        var f = sjcl.bitArray,
            g = f.bitLength(c) / 8,
            h = f.bitLength(b),
            i = f.clamp(b, h - e),
            j = f.bitSlice(b, h - e),
            h = (h - e) / 8;
        for (7 > g && q(new sjcl.exception.invalid("ccm: iv must be at least 7 bytes")), b = 2; 4 > b && h >>> 8 * b; b++);
        return 15 - g > b && (b = 15 - g), c = f.clamp(c, 8 * (15 - b)), i = sjcl.mode.ccm.o(a, i, c, j, e, b), a = sjcl.mode.ccm.L(a, i.data, c, d, e, b), f.equal(i.tag, a) || q(new sjcl.exception.corrupt("ccm: tag doesn't match")), i.data
    },
    L: function(a, b, c, d, e, f) {
        var g = [],
            h = sjcl.bitArray,
            i = h.k;
        if (e /= 8, (e % 2 || 4 > e || e > 16) && q(new sjcl.exception.invalid("ccm: invalid tag length")), (4294967295 < d.length || 4294967295 < b.length) && q(new sjcl.exception.bug("ccm: can't deal with 4GiB or more data")), f = [h.partial(8, (d.length ? 64 : 0) | e - 2 << 2 | f - 1)], f = h.concat(f, c), f[3] |= h.bitLength(b) / 8, f = a.encrypt(f), d.length)
            for (c = h.bitLength(d) / 8, 65279 >= c ? g = [h.partial(16, c)] : 4294967295 >= c && (g = h.concat([h.partial(16, 65534)], [c])), g = h.concat(g, d), d = 0; d < g.length; d += 4) f = a.encrypt(i(f, g.slice(d, d + 4).concat([0, 0, 0])));
        for (d = 0; d < b.length; d += 4) f = a.encrypt(i(f, b.slice(d, d + 4).concat([0, 0, 0])));
        return h.clamp(f, 8 * e)
    },
    o: function(a, b, c, d, e, f) {
        var g, h = sjcl.bitArray;
        g = h.k;
        var i = b.length,
            j = h.bitLength(b);
        if (c = h.concat([h.partial(8, f - 1)], c).concat([0, 0, 0]).slice(0, 4), d = h.bitSlice(g(d, a.encrypt(c)), 0, e), !i) return {
            tag: d,
            data: []
        };
        for (g = 0; i > g; g += 4) c[3]++, e = a.encrypt(c), b[g] ^= e[0], b[g + 1] ^= e[1], b[g + 2] ^= e[2], b[g + 3] ^= e[3];
        return {
            tag: d,
            data: h.clamp(b, j)
        }
    }
}, sjcl.mode.ocb2 = {
    name: "ocb2",
    encrypt: function(a, b, c, d, e, f) {
        128 !== sjcl.bitArray.bitLength(c) && q(new sjcl.exception.invalid("ocb iv must be 128 bits"));
        var g, h = sjcl.mode.ocb2.H,
            i = sjcl.bitArray,
            j = i.k,
            k = [0, 0, 0, 0];
        c = h(a.encrypt(c));
        var l, m = [];
        for (d = d || [], e = e || 64, g = 0; g + 4 < b.length; g += 4) l = b.slice(g, g + 4), k = j(k, l), m = m.concat(j(c, a.encrypt(j(c, l)))), c = h(c);
        return l = b.slice(g), b = i.bitLength(l), g = a.encrypt(j(c, [0, 0, 0, b])), l = i.clamp(j(l.concat([0, 0, 0]), g), b), k = j(k, j(l.concat([0, 0, 0]), g)), k = a.encrypt(j(k, j(c, h(c)))), d.length && (k = j(k, f ? d : sjcl.mode.ocb2.pmac(a, d))), m.concat(i.concat(l, i.clamp(k, e)))
    },
    decrypt: function(a, b, c, d, e, f) {
        128 !== sjcl.bitArray.bitLength(c) && q(new sjcl.exception.invalid("ocb iv must be 128 bits")), e = e || 64;
        var g, h, i = sjcl.mode.ocb2.H,
            j = sjcl.bitArray,
            k = j.k,
            l = [0, 0, 0, 0],
            m = i(a.encrypt(c)),
            n = sjcl.bitArray.bitLength(b) - e,
            o = [];
        for (d = d || [], c = 0; n / 32 > c + 4; c += 4) g = k(m, a.decrypt(k(m, b.slice(c, c + 4)))), l = k(l, g), o = o.concat(g), m = i(m);
        return h = n - 32 * c, g = a.encrypt(k(m, [0, 0, 0, h])), g = k(g, j.clamp(b.slice(c), h).concat([0, 0, 0])), l = k(l, g), l = a.encrypt(k(l, k(m, i(m)))), d.length && (l = k(l, f ? d : sjcl.mode.ocb2.pmac(a, d))), j.equal(j.clamp(l, e), j.bitSlice(b, n)) || q(new sjcl.exception.corrupt("ocb: tag doesn't match")), o.concat(j.clamp(g, h))
    },
    pmac: function(a, b) {
        var c, d = sjcl.mode.ocb2.H,
            e = sjcl.bitArray,
            f = e.k,
            g = [0, 0, 0, 0],
            h = a.encrypt([0, 0, 0, 0]),
            h = f(h, d(d(h)));
        for (c = 0; c + 4 < b.length; c += 4) h = d(h), g = f(g, a.encrypt(f(h, b.slice(c, c + 4))));
        return c = b.slice(c), 128 > e.bitLength(c) && (h = f(h, d(h)), c = e.concat(c, [-2147483648, 0, 0, 0])), g = f(g, c), a.encrypt(f(d(f(h, d(h))), g))
    },
    H: function(a) {
        return [a[0] << 1 ^ a[1] >>> 31, a[1] << 1 ^ a[2] >>> 31, a[2] << 1 ^ a[3] >>> 31, a[3] << 1 ^ 135 * (a[0] >>> 31)]
    }
}, sjcl.mode.gcm = {
    name: "gcm",
    encrypt: function(a, b, c, d, e) {
        var f = b.slice(0);
        return b = sjcl.bitArray, d = d || [], a = sjcl.mode.gcm.o(!0, a, f, d, c, e || 128), b.concat(a.data, a.tag)
    },
    decrypt: function(a, b, c, d, e) {
        var f = b.slice(0),
            g = sjcl.bitArray,
            h = g.bitLength(f);
        return e = e || 128, d = d || [], h >= e ? (b = g.bitSlice(f, h - e), f = g.bitSlice(f, 0, h - e)) : (b = f, f = []), a = sjcl.mode.gcm.o(u, a, f, d, c, e), g.equal(a.tag, b) || q(new sjcl.exception.corrupt("gcm: tag doesn't match")), a.data
    },
    W: function(a, b) {
        var c, d, e, f, g, h = sjcl.bitArray.k;
        for (e = [0, 0, 0, 0], f = b.slice(0), c = 0; 128 > c; c++) {
            for ((d = 0 !== (a[Math.floor(c / 32)] & 1 << 31 - c % 32)) && (e = h(e, f)), g = 0 !== (1 & f[3]), d = 3; d > 0; d--) f[d] = f[d] >>> 1 | (1 & f[d - 1]) << 31;
            f[0] >>>= 1, g && (f[0] ^= -520093696)
        }
        return e
    },
    f: function(a, b, c) {
        var d, e = c.length;
        for (b = b.slice(0), d = 0; e > d; d += 4) b[0] ^= 4294967295 & c[d], b[1] ^= 4294967295 & c[d + 1], b[2] ^= 4294967295 & c[d + 2], b[3] ^= 4294967295 & c[d + 3], b = sjcl.mode.gcm.W(b, a);
        return b
    },
    o: function(a, b, c, d, e, f) {
        var g, h, i, j, k, l, m, n, o = sjcl.bitArray;
        for (l = c.length, m = o.bitLength(c), n = o.bitLength(d), h = o.bitLength(e), g = b.encrypt([0, 0, 0, 0]), 96 === h ? (e = e.slice(0), e = o.concat(e, [1])) : (e = sjcl.mode.gcm.f(g, [0, 0, 0, 0], e), e = sjcl.mode.gcm.f(g, e, [0, 0, Math.floor(h / 4294967296), 4294967295 & h])), h = sjcl.mode.gcm.f(g, [0, 0, 0, 0], d), k = e.slice(0), d = h.slice(0), a || (d = sjcl.mode.gcm.f(g, h, c)), j = 0; l > j; j += 4) k[3]++, i = b.encrypt(k), c[j] ^= i[0], c[j + 1] ^= i[1], c[j + 2] ^= i[2], c[j + 3] ^= i[3];
        return c = o.clamp(c, m), a && (d = sjcl.mode.gcm.f(g, h, c)), a = [Math.floor(n / 4294967296), 4294967295 & n, Math.floor(m / 4294967296), 4294967295 & m], d = sjcl.mode.gcm.f(g, d, a), i = b.encrypt(e), d[0] ^= i[0], d[1] ^= i[1], d[2] ^= i[2], d[3] ^= i[3], {
            tag: o.bitSlice(d, 0, f),
            data: c
        }
    }
}, sjcl.misc.hmac = function(a, b) {
    this.M = b = b || sjcl.hash.sha256;
    var c, d = [
            [],
            []
        ],
        e = b.prototype.blockSize / 32;
    for (this.m = [new b, new b], a.length > e && (a = b.hash(a)), c = 0; e > c; c++) d[0][c] = 909522486 ^ a[c], d[1][c] = 1549556828 ^ a[c];
    this.m[0].update(d[0]), this.m[1].update(d[1]), this.G = new b(this.m[0])
}, sjcl.misc.hmac.prototype.encrypt = sjcl.misc.hmac.prototype.mac = function(a) {
    return this.Q && q(new sjcl.exception.invalid("encrypt on already updated hmac called!")), this.update(a), this.digest(a)
}, sjcl.misc.hmac.prototype.reset = function() {
    this.G = new this.M(this.m[0]), this.Q = u
}, sjcl.misc.hmac.prototype.update = function(a) {
    this.Q = !0, this.G.update(a)
}, sjcl.misc.hmac.prototype.digest = function() {
    var a = this.G.finalize(),
        a = new this.M(this.m[1]).update(a).finalize();
    return this.reset(), a
}, sjcl.misc.pbkdf2 = function(a, b, c, d, e) {
    c = c || 1e3, (0 > d || 0 > c) && q(sjcl.exception.invalid("invalid params to pbkdf2")), "string" == typeof a && (a = sjcl.codec.utf8String.toBits(a)), "string" == typeof b && (b = sjcl.codec.utf8String.toBits(b)), e = e || sjcl.misc.hmac, a = new e(a);
    var f, g, h, i, j = [],
        k = sjcl.bitArray;
    for (i = 1; 32 * j.length < (d || 1); i++) {
        for (e = f = a.encrypt(k.concat(b, [i])), g = 1; c > g; g++)
            for (f = a.encrypt(f), h = 0; h < f.length; h++) e[h] ^= f[h];
        j = j.concat(e)
    }
    return d && (j = k.clamp(j, d)), j
}, sjcl.prng = function(a) {
    this.b = [new sjcl.hash.sha256], this.h = [0], this.F = 0, this.t = {}, this.C = 0, this.K = {}, this.O = this.c = this.i = this.V = 0, this.a = [0, 0, 0, 0, 0, 0, 0, 0], this.e = [0, 0, 0, 0], this.A = t, this.B = a, this.p = u, this.z = {
        progress: {},
        seeded: {}
    }, this.l = this.U = 0, this.u = 1, this.w = 2, this.S = 65536, this.I = [0, 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024], this.T = 3e4, this.R = 80
}, sjcl.prng.prototype = {
    randomWords: function(a, b) {
        var c, d = [];
        c = this.isReady(b);
        var e;
        if (c === this.l && q(new sjcl.exception.notReady("generator isn't seeded")), c & this.w) {
            c = !(c & this.u), e = [];
            var f, g = 0;
            for (this.O = e[0] = (new Date).valueOf() + this.T, f = 0; 16 > f; f++) e.push(4294967296 * Math.random() | 0);
            for (f = 0; f < this.b.length && (e = e.concat(this.b[f].finalize()), g += this.h[f], this.h[f] = 0, !(!c && this.F & 1 << f)); f++);
            for (this.F >= 1 << this.b.length && (this.b.push(new sjcl.hash.sha256), this.h.push(0)), this.c -= g, g > this.i && (this.i = g), this.F++, this.a = sjcl.hash.sha256.hash(this.a.concat(e)), this.A = new sjcl.cipher.aes(this.a), c = 0; 4 > c && (this.e[c] = this.e[c] + 1 | 0, !this.e[c]); c++);
        }
        for (c = 0; a > c; c += 4) 0 === (c + 1) % this.S && A(this), e = B(this), d.push(e[0], e[1], e[2], e[3]);
        return A(this), d.slice(0, a)
    },
    setDefaultParanoia: function(a) {
        this.B = a
    },
    addEntropy: function(a, b, c) {
        c = c || "user";
        var d, e, f = (new Date).valueOf(),
            g = this.t[c],
            h = this.isReady(),
            i = 0;
        switch (d = this.K[c], d === t && (d = this.K[c] = this.V++), g === t && (g = this.t[c] = 0), this.t[c] = (this.t[c] + 1) % this.b.length, typeof a) {
            case "number":
                b === t && (b = 1), this.b[g].update([d, this.C++, 1, b, f, 1, 0 | a]);
                break;
            case "object":
                if (c = Object.prototype.toString.call(a), "[object Uint32Array]" === c) {
                    for (e = [], c = 0; c < a.length; c++) e.push(a[c]);
                    a = e
                } else
                    for ("[object Array]" !== c && (i = 1), c = 0; c < a.length && !i; c++) "number" != typeof a[c] && (i = 1);
                if (!i) {
                    if (b === t)
                        for (c = b = 0; c < a.length; c++)
                            for (e = a[c]; e > 0;) b++, e >>>= 1;
                    this.b[g].update([d, this.C++, 2, b, f, a.length].concat(a))
                }
                break;
            case "string":
                b === t && (b = a.length), this.b[g].update([d, this.C++, 3, b, f, a.length]), this.b[g].update(a);
                break;
            default:
                i = 1
        }
        i && q(new sjcl.exception.bug("random: addEntropy only supports number, array of numbers or string")), this.h[g] += b, this.c += b, h === this.l && (this.isReady() !== this.l && C("seeded", Math.max(this.i, this.c)), C("progress", this.getProgress()))
    },
    isReady: function(a) {
        return a = this.I[a !== t ? a : this.B], this.i && this.i >= a ? this.h[0] > this.R && (new Date).valueOf() > this.O ? this.w | this.u : this.u : this.c >= a ? this.w | this.l : this.l
    },
    getProgress: function(a) {
        return a = this.I[a ? a : this.B], this.i >= a ? 1 : this.c > a ? 1 : this.c / a
    },
    startCollectors: function() {
        this.p || (window.addEventListener ? (window.addEventListener("load", this.r, u), window.addEventListener("mousemove", this.s, u)) : document.attachEvent ? (document.attachEvent("onload", this.r), document.attachEvent("onmousemove", this.s)) : q(new sjcl.exception.bug("can't attach event")), this.p = !0)
    },
    stopCollectors: function() {
        this.p && (window.removeEventListener ? (window.removeEventListener("load", this.r, u), window.removeEventListener("mousemove", this.s, u)) : window.detachEvent && (window.detachEvent("onload", this.r), window.detachEvent("onmousemove", this.s)), this.p = u)
    },
    addEventListener: function(a, b) {
        this.z[a][this.U++] = b
    },
    removeEventListener: function(a, b) {
        var c, d, e = this.z[a],
            f = [];
        for (d in e) e.hasOwnProperty(d) && e[d] === b && f.push(d);
        for (c = 0; c < f.length; c++) d = f[c], delete e[d]
    },
    s: function(a) {
        sjcl.random.addEntropy([a.x || a.clientX || a.offsetX || 0, a.y || a.clientY || a.offsetY || 0], 2, "mouse")
    },
    r: function() {
        sjcl.random.addEntropy((new Date).valueOf(), 2, "loadtime")
    }
}, sjcl.random = new sjcl.prng(6);
try {
    if ("undefined" != typeof module && module.exports) {
        var D = require("crypto").randomBytes(128);
        sjcl.random.addEntropy(D, 1024, "crypto['randomBytes']")
    } else if (window && window.crypto && window.crypto.getRandomValues) {
        var E = new Uint32Array(32);
        window.crypto.getRandomValues(E), sjcl.random.addEntropy(E, 1024, "crypto['getRandomValues']")
    }
} catch (F) {}
if (sjcl.json = {
        defaults: {
            v: 1,
            iter: 1e3,
            ks: 128,
            ts: 64,
            mode: "ccm",
            adata: "",
            cipher: "aes"
        },
        encrypt: function(a, b, c, d) {
            c = c || {}, d = d || {};
            var e, f = sjcl.json,
                g = f.d({
                    iv: sjcl.random.randomWords(4, 0)
                }, f.defaults);
            return f.d(g, c), c = g.adata, "string" == typeof g.salt && (g.salt = sjcl.codec.base64.toBits(g.salt)), "string" == typeof g.iv && (g.iv = sjcl.codec.base64.toBits(g.iv)), (!sjcl.mode[g.mode] || !sjcl.cipher[g.cipher] || "string" == typeof a && 100 >= g.iter || 64 !== g.ts && 96 !== g.ts && 128 !== g.ts || 128 !== g.ks && 192 !== g.ks && 256 !== g.ks || 2 > g.iv.length || 4 < g.iv.length) && q(new sjcl.exception.invalid("json encrypt: invalid parameters")), "string" == typeof a ? (e = sjcl.misc.cachedPbkdf2(a, g), a = e.key.slice(0, g.ks / 32), g.salt = e.salt) : sjcl.ecc && a instanceof sjcl.ecc.elGamal.publicKey && (e = a.kem(), g.kemtag = e.tag, a = e.key.slice(0, g.ks / 32)), "string" == typeof b && (b = sjcl.codec.utf8String.toBits(b)), "string" == typeof c && (c = sjcl.codec.utf8String.toBits(c)), e = new sjcl.cipher[g.cipher](a), f.d(d, g), d.key = a, g.ct = sjcl.mode[g.mode].encrypt(e, b, g.iv, c, g.ts), f.encode(g)
        },
        decrypt: function(a, b, c, d) {
            c = c || {}, d = d || {};
            var e = sjcl.json;
            b = e.d(e.d(e.d({}, e.defaults), e.decode(b)), c, !0);
            var f;
            return c = b.adata, "string" == typeof b.salt && (b.salt = sjcl.codec.base64.toBits(b.salt)), "string" == typeof b.iv && (b.iv = sjcl.codec.base64.toBits(b.iv)), (!sjcl.mode[b.mode] || !sjcl.cipher[b.cipher] || "string" == typeof a && 100 >= b.iter || 64 !== b.ts && 96 !== b.ts && 128 !== b.ts || 128 !== b.ks && 192 !== b.ks && 256 !== b.ks || !b.iv || 2 > b.iv.length || 4 < b.iv.length) && q(new sjcl.exception.invalid("json decrypt: invalid parameters")), "string" == typeof a ? (f = sjcl.misc.cachedPbkdf2(a, b), a = f.key.slice(0, b.ks / 32), b.salt = f.salt) : sjcl.ecc && a instanceof sjcl.ecc.elGamal.secretKey && (a = a.unkem(sjcl.codec.base64.toBits(b.kemtag)).slice(0, b.ks / 32)), "string" == typeof c && (c = sjcl.codec.utf8String.toBits(c)), f = new sjcl.cipher[b.cipher](a), c = sjcl.mode[b.mode].decrypt(f, b.ct, b.iv, c, b.ts), e.d(d, b), d.key = a, sjcl.codec.utf8String.fromBits(c)
        },
        encode: function(a) {
            var b, c = "{",
                d = "";
            for (b in a)
                if (a.hasOwnProperty(b)) switch (b.match(/^[a-z0-9]+$/i) || q(new sjcl.exception.invalid("json encode: invalid property name")), c += d + '"' + b + '":', d = ",", typeof a[b]) {
                    case "number":
                    case "boolean":
                        c += a[b];
                        break;
                    case "string":
                        c += '"' + escape(a[b]) + '"';
                        break;
                    case "object":
                        c += '"' + sjcl.codec.base64.fromBits(a[b], 0) + '"';
                        break;
                    default:
                        q(new sjcl.exception.bug("json encode: unsupported type"))
                }
            return c + "}"
        },
        decode: function(a) {
            a = a.replace(/\s/g, ""), a.match(/^\{.*\}$/) || q(new sjcl.exception.invalid("json decode: this isn't json!")), a = a.replace(/^\{|\}$/g, "").split(/,/);
            var b, c, d = {};
            for (b = 0; b < a.length; b++)(c = a[b].match(/^(?:(["']?)([a-z][a-z0-9]*)\1):(?:(\d+)|"([a-z0-9+\/%*_.@=\-]*)")$/i)) || q(new sjcl.exception.invalid("json decode: this isn't json!")), d[c[2]] = c[3] ? parseInt(c[3], 10) : c[2].match(/^(ct|salt|iv)$/) ? sjcl.codec.base64.toBits(c[4]) : unescape(c[4]);
            return d
        },
        d: function(a, b, c) {
            if (a === t && (a = {}), b === t) return a;
            for (var d in b) b.hasOwnProperty(d) && (c && a[d] !== t && a[d] !== b[d] && q(new sjcl.exception.invalid("required parameter overridden")), a[d] = b[d]);
            return a
        },
        Z: function(a, b) {
            var c, d = {};
            for (c in a) a.hasOwnProperty(c) && a[c] !== b[c] && (d[c] = a[c]);
            return d
        },
        Y: function(a, b) {
            var c, d = {};
            for (c = 0; c < b.length; c++) a[b[c]] !== t && (d[b[c]] = a[b[c]]);
            return d
        }
    }, sjcl.encrypt = sjcl.json.encrypt, sjcl.decrypt = sjcl.json.decrypt, sjcl.misc.X = {}, sjcl.misc.cachedPbkdf2 = function(a, b) {
        var c, d = sjcl.misc.X;
        return b = b || {}, c = b.iter || 1e3, d = d[a] = d[a] || {}, c = d[c] = d[c] || {
            firstSalt: b.salt && b.salt.length ? b.salt.slice(0) : sjcl.random.randomWords(2, 0)
        }, d = b.salt === t ? c.firstSalt : b.salt, c[d] = c[d] || sjcl.misc.pbkdf2(a, d, b.iter), {
            key: c[d].slice(0),
            salt: d.slice(0)
        }
    }, "function" != typeof Blob && "object" != typeof Blob || "undefined" == typeof URL)
    if ("function" != typeof Blob && "object" != typeof Blob || "undefined" == typeof webkitURL) var Blob = function(a) {
        var b = a.BlobBuilder || a.WebKitBlobBuilder || a.MozBlobBuilder || a.MSBlobBuilder || function(a) {
            var b = function(a) {
                    return Object.prototype.toString.call(a).match(/^\[object\s(.*)\]$/)[1]
                },
                c = function() {
                    this.data = []
                },
                d = function(a, b, c) {
                    this.data = a, this.size = a.length, this.type = b, this.encoding = c
                },
                e = c.prototype,
                f = d.prototype,
                g = a.FileReaderSync,
                h = function(a) {
                    this.code = this[this.name = a]
                },
                i = "NOT_FOUND_ERR SECURITY_ERR ABORT_ERR NOT_READABLE_ERR ENCODING_ERR NO_MODIFICATION_ALLOWED_ERR INVALID_STATE_ERR SYNTAX_ERR".split(" "),
                j = i.length,
                k = a.URL || a.webkitURL || a,
                l = k.createObjectURL,
                m = k.revokeObjectURL,
                n = k,
                o = a.btoa,
                p = a.atob,
                q = a.ArrayBuffer,
                r = a.Uint8Array;
            for (d.fake = f.fake = !0; j--;) h.prototype[i[j]] = j + 1;
            return k.createObjectURL || (n = a.URL = {}), n.createObjectURL = function(a) {
                var b, c = a.type;
                return null === c && (c = "application/octet-stream"), a instanceof d ? (b = "data:" + c, "base64" === a.encoding ? b + ";base64," + a.data : "URI" === a.encoding ? b + "," + decodeURIComponent(a.data) : o ? b + ";base64," + o(a.data) : b + "," + encodeURIComponent(a.data)) : l ? l.call(k, a) : void 0
            }, n.revokeObjectURL = function(a) {
                "data:" !== a.substring(0, 5) && m && m.call(k, a)
            }, e.append = function(a) {
                var c = this.data;
                if (r && (a instanceof q || a instanceof r)) {
                    for (var e = "", f = new r(a), i = 0, j = f.length; j > i; i++) e += String.fromCharCode(f[i]);
                    c.push(e)
                } else if ("Blob" === b(a) || "File" === b(a)) {
                    if (!g) throw new h("NOT_READABLE_ERR");
                    var k = new g;
                    c.push(k.readAsBinaryString(a))
                } else a instanceof d ? "base64" === a.encoding && p ? c.push(p(a.data)) : "URI" === a.encoding ? c.push(decodeURIComponent(a.data)) : "raw" === a.encoding && c.push(a.data) : ("string" != typeof a && (a += ""), c.push(unescape(encodeURIComponent(a))))
            }, e.getBlob = function(a) {
                return arguments.length || (a = null), new d(this.data.join(""), a, "raw")
            }, e.toString = function() {
                return "[object BlobBuilder]"
            }, f.slice = function(a, b, c) {
                var e = arguments.length;
                return 3 > e && (c = null), new d(this.data.slice(a, e > 1 ? b : this.data.length), c, this.encoding)
            }, f.toString = function() {
                return "[object Blob]"
            }, c
        }(a);
        return function(a, c) {
            var d = c ? c.type || "" : "",
                e = new b;
            if (a)
                for (var f = 0, g = a.length; g > f; f++) e.append(a[f]);
            return e.getBlob(d)
        }
    }("undefined" != typeof self && self || "undefined" != typeof window && window || this.content || this);
    else self.URL = webkitURL;
var saveAs = saveAs || "undefined" != typeof navigator && navigator.msSaveOrOpenBlob && navigator.msSaveOrOpenBlob.bind(navigator) || function(a) {
    var b = a,
        c = function() {
            return a.URL || a.webkitURL || a
        },
        d = a.URL || a.webkitURL || a,
        e = b.createElementNS("", "a"),
        f = !a.externalHost && "download" in e,
        g = a.webkitRequestFileSystem,
        h = a.requestFileSystem || g || a.mozRequestFileSystem,
        i = function(b) {
            (a.setImmediate || a.setTimeout)(function() {
                throw b
            }, 0)
        },
        j = "application/octet-stream",
        k = 0,
        l = [],
        m = function() {
            for (var a = l.length; a--;) {
                var b = l[a];
                "string" == typeof b ? d.revokeObjectURL(b) : b.remove()
            }
            l.length = 0
        },
        n = function(a, b, c) {
            b = [].concat(b);
            for (var d = b.length; d--;) {
                var e = a["on" + b[d]];
                if ("function" == typeof e) try {
                    e.call(a, c || a)
                } catch (f) {
                    i(f)
                }
            }
        },
        o = function(d, i) {
            var m, o, p, q = this,
                r = d.type,
                s = !1,
                t = function() {
                    var a = c().createObjectURL(d);
                    return l.push(a), a
                },
                u = function() {
                    n(q, "writestart progress write writeend".split(" "))
                },
                v = function() {
                    (s || !m) && (m = t(d)), o ? o.location.href = m : window.open(m, "_blank"), q.readyState = q.DONE, u()
                },
                w = function(a) {
                    return function() {
                        return q.readyState !== q.DONE ? a.apply(this, arguments) : void 0
                    }
                },
                x = {
                    create: !0,
                    exclusive: !1
                };
            if (q.readyState = q.INIT, i || (i = "download"), f) {
                m = t(d), b = a.document, e = b.createElementNS("", "a"), e.href = m, e.download = i;
                var y = b.createEvent("MouseEvents");
                return y.initMouseEvent("click", !0, !1, a, 0, 0, 0, 0, 0, !1, !1, !1, !1, 0, null), e.dispatchEvent(y), q.readyState = q.DONE, u(), void 0
            }
            return a.chrome && r && r !== j && (p = d.slice || d.webkitSlice, d = p.call(d, 0, d.size, j), s = !0), g && "download" !== i && (i += ".download"), (r === j || g) && (o = a), h ? (k += d.size, h(a.TEMPORARY, k, w(function(a) {
                a.root.getDirectory("saved", x, w(function(a) {
                    var b = function() {
                        a.getFile(i, x, w(function(a) {
                            a.createWriter(w(function(b) {
                                b.onwriteend = function(b) {
                                    o.location.href = a.toURL(), l.push(a), q.readyState = q.DONE, n(q, "writeend", b)
                                }, b.onerror = function() {
                                    var a = b.error;
                                    a.code !== a.ABORT_ERR && v()
                                }, "writestart progress write abort".split(" ").forEach(function(a) {
                                    b["on" + a] = q["on" + a]
                                }), b.write(d), q.abort = function() {
                                    b.abort(), q.readyState = q.DONE
                                }, q.readyState = q.WRITING
                            }), v)
                        }), v)
                    };
                    a.getFile(i, {
                        create: !1
                    }, w(function(a) {
                        a.remove(), b()
                    }), w(function(a) {
                        a.code === a.NOT_FOUND_ERR ? b() : v()
                    }))
                }), v)
            }), v), void 0) : (v(), void 0)
        },
        p = o.prototype,
        q = function(a, b) {
            return new o(a, b)
        };
    return p.abort = function() {
        var a = this;
        a.readyState = a.DONE, n(a, "abort")
    }, p.readyState = p.INIT = 0, p.WRITING = 1, p.DONE = 2, p.error = p.onwritestart = p.onprogress = p.onwrite = p.onabort = p.onerror = p.onwriteend = null, a.addEventListener("unload", m, !1), q
}("undefined" != typeof self && self || "undefined" != typeof window && window || this.content);
"undefined" != typeof module && (module.exports = saveAs);
var CONST = {
        errorImportFileFormat: "File format incorrect.",
        errorDecrypt: "Incorrect password, or data has been corrupted",
        errorInvalidCypherSettings: "Invalid cypher settings",
        errorImportFailed: "Import failed: ",
        errorApplicationTypeNotFound: "Could not determine application type.",
        errorWrongApplicationType: "Incorrect application type",
        cypherSettings: {
            v: 1,
            iter: 1e3,
            ks: 256,
            ts: 128,
            mode: "ocb2",
            cipher: "aes"
        },
        variableCypherSettings: {
            iv: {
                desc: "Initialisation Vector",
                type: "string",
                mandatory: !0
            },
            salt: {
                desc: "Salt",
                type: "string",
                mandatory: !0
            },
            adata: {
                desc: "Hint",
                type: "string",
                mandatory: !1
            },
            ct: {
                desc: "Cypher text",
                type: "string",
                mandatory: !1
            }
        },
        regexEncryptedData: /<script id="encrypted-data" type="text\/javascript">var encData=(.+);<\/script>/g,
        regexAppType: /<meta name="sca-app-type" content="(\w+)"/g
    },
    SCA = {
        e: function(a) {
            return document.getElementById(a)
        },
        setDisplay: function(a, b) {
            this.e(a).style.display = b
        },
        isShown: function(a) {
            return "none" !== this.e(a).style.display
        },
        getAndClear: function(a) {
            var b = this.e(a),
                c = b.value;
            b.value = "";
            try {
                b.innerHtml = ""
            } catch (d) {}
            return c
        },
        getEncPass: function() {
            return this.getAndClear("enc-password")
        },
        getEncHint: function() {
            return this.getAndClear("enc-hint")
        },
        getDecPass: function() {
            return this.getAndClear("dec-password")
        },
        getDecHint: function() {
            return this.getAndClear("dec-hint")
        },
        getDocumentHtml: function() {
            var a = document.doctype,
                b = "";
            return a && (b = "<!DOCTYPE " + a.name + (a.publicId ? ' PUBLIC "' + a.publicId + '"' : "") + (!a.publicId && a.systemId ? " SYSTEM" : "") + (a.systemId ? ' "' + a.systemId + '"' : "") + ">"), b + document.documentElement.outerHTML
        },
        saveDocument: function() {
            saveAs(new Blob([this.getDocumentHtml()], {
                type: "application/xhtml+xml;charset=" + document.characterSet
            }), CONST.appName + ".html")
        },
        getClonedCypherSettings: function() {
            return JSON.parse(JSON.stringify(CONST.cypherSettings))
        },
        clickImport: function() {
            this.e("import").click()
        },
        importFile: function() {
            var a = this.e("import").files,
                b = a[0],
                c = new FileReader;
            c.onload = function() {
                SCA.processImportedFileText(this.result)
            }, c.readAsText(b)
        },
        processImportedFileText: function(a) {
            try {
                var b = CONST.regexAppType.exec(a);
                if (!b || 2 !== b.length) throw CONST.errorApplicationTypeNotFound;
                if (b[1] !== CONST.appName) throw CONST.errorWrongApplicationType;
                var c = CONST.regexEncryptedData.exec(a);
                if (!c || 2 !== c.length) throw CONST.errorImportFileFormat;
                var d = JSON.parse(c[1]),
                    e = this.getClonedCypherSettings();
                for (var f in CONST.cypherSettings)
                    if (d[f] !== CONST.cypherSettings[f]) throw CONST.errorInvalidCypherSettings;
                for (var f in CONST.variableCypherSettings) {
                    var g = CONST.variableCypherSettings[f],
                        h = d[f],
                        i = g.mandatory && typeof h !== g.type,
                        j = !g.mandatory && h && typeof h !== g.type;
                    if (i || j) throw "Bad " + g.desc;
                    e[f] = d[f]
                }
                encData = e, SCA.doOnload()
            } catch (k) {
                console.log(k), alert(CONST.errorImportFailed + k)
            }
        },
        showDecryptError: function(a) {
            var b = this.e("dec-password-group");
            a ? (b.setAttribute("class", "form-group has-error"), this.e("dec-password-help").innerHTML = CONST.errorDecrypt) : (b.setAttribute("class", "form-group"), this.e("dec-password-help").innerHTML = "")
        },
        showAbout: function() {
            var a = "";
            this.isShown("locked") ? a = CONST.about.locked : this.isShown("unlocked") && (a = CONST.about.unlocked), SCA.displayHelp(!0)
        },
        encryptWith: function(a) {
            var b = this.getClonedCypherSettings(),
                c = sjcl.random.randomWords(2, 2),
                d = sjcl.random.randomWords(4, 2);
            b.salt = sjcl.codec.base64.fromBits(c), b.iv = sjcl.codec.base64.fromBits(d);
            var e = sjcl.misc.pbkdf2(this.getEncPass(), c, b.iter),
                f = new sjcl.cipher[b.cipher](e),
                g = sjcl.codec.utf8String.toBits(this.getEncHint());
            b.adata = sjcl.codec.base64.fromBits(g);
            var h = sjcl.codec.utf8String.toBits(SCA.getPlaintext()),
                i = sjcl.mode[b.mode].encrypt(f, h, d, g, b.ts);
            b.ct = sjcl.codec.base64.fromBits(i), a(b, f, d, g);
            var j = "var encData=" + JSON.stringify(b) + ";";
            this.e("encrypted-data").innerHTML = j, encData = CONST.cypherSettings, this.setDisplay("nojavascript", "inline"), this.setDisplay("unsupported", "none"), this.setDisplay("locked", "none"), this.setDisplay("unlocked", "none"), this.resetHelp();
            var k = this.e("enc-password-fb-group");
            k.style.display = "none", k.setAttribute("class", "form-group"), this.e("enc-password-fb").innerHTML = "", this.e("enc-password-group").setAttribute("class", "form-group")
        },
        decryptWith: function(a) {
            var b = this.getDecPass(),
                c = sjcl.codec.base64.toBits(encData.salt),
                d = sjcl.codec.base64.toBits(encData.iv),
                e = sjcl.codec.base64.toBits(encData.adata),
                f = sjcl.misc.pbkdf2(b, c, encData.iter),
                g = new sjcl.cipher[encData.cipher](f),
                h = sjcl.codec.base64.toBits(encData.ct);
            try {
                var i = sjcl.mode[encData.mode].decrypt(g, h, d, e, encData.ts);
                i = sjcl.codec.utf8String.fromBits(i), a(g, d, e, i), this.setUnlocked(!0), this.showDecryptError(!1), this.e("enc-password").value = b, this.e("enc-hint").value = sjcl.codec.utf8String.fromBits(e)
            } catch (j) {
                console.log(j), this.showDecryptError(!0)
            }
        },
        validateEncPass: function() {
            var a = this.e("enc-password").value,
                b = this.getPasswordStrength(a),
                c = "form-group",
                d = "Password: ";
            .33 > b ? (c += " has-error", d += "Weak") : .66 > b ? (c += " has-warning", d += "OK") : (c += " has-success", d += "Strong");
            var e = this.e("enc-password-fb-group");
            e.style.display = "inline-block", e.setAttribute("class", c), this.e("enc-password-fb").innerHTML = d, this.e("enc-password-group").setAttribute("class", c)
        },
        getPasswordStrength: function(a) {
            var b = 18,
                c = a.length;
            return a.match(/[A-Z]/) && (c += 1), a.match(/\W/) && (c += 2), c / b
        },
        displayHelp: function(a) {
            var b = a ? "block" : "none";
            this.setDisplay("help-screen", b)
        },
        toggleHelpDetail: function() {
            var a = this.isHelpDetailed(),
                b = a ? "none" : "block",
                c = a ? "more" : "less";
            this.setDisplay("help-detail", b), this.e("help-toggle").innerHTML = c
        },
        isHelpDetailed: function() {
            return "block" === this.e("help-detail").style.display
        },
        resetHelp: function() {
            this.isHelpDetailed() && this.toggleHelpDetail(), this.displayHelp(!1)
        },
        doOnload: function() {
            this.setDisplay("nojavascript", "none");
            try {
                if (new Blob, !(window.File && window.FileReader && window.FileList && window.Blob)) throw "File operations not supported";
                if (this.setDisplay("unsupported", "none"), sjcl.random.startCollectors(), encData.ct && encData.salt && encData.iv) {
                    if (this.setUnlocked(!1), encData.adata) {
                        var a = sjcl.codec.utf8String.fromBits(sjcl.codec.base64.toBits(encData.adata));
                        this.e("dec-hint").innerHTML = a
                    }
                    this.e("dec-password").focus()
                } else this.setUnlocked(!0), this.displayHelp(!0)
            } catch (b) {
                alert(b), console.log(b), this.setDisplay("unsupported", "inline")
            }
        }
    };
CONST.appName = "EveryPass", CONST.about = {
    general: "Password Manager allows you to safely save and restore passwords in a single encrypted HTML file.\n\n",
    unlocked: "Add password information via the main form, and then save an encrypted copy of them by specifying a password and clicking Encrypt.",
    locked: "This file contains secure passwords which may be accessed when the correct password (used to encrypt them) is entered."
}, SCA._nextPwdId = 0, SCA._divPwData = function() {
    return this.dPwData || (this.dPwData = this.e("pw-data")), this.dPwData
}, SCA._divPwds = function() {
    return this.dPwds || (this.dPwds = this.e("pwds")), this.dPwds
}, SCA.newPwd = function() {
    var a = {
        s: this.getAndClear("new-service"),
        u: this.getAndClear("new-username"),
        p: this.getAndClear("new-password"),
        q: this.getAndClear("new-question"),
        a: this.getAndClear("new-answer")
    };
    this.addPwd(a), this.e("search").value = "", this.filterPwds()
}, SCA.addPwd = function(a) {
    var b = "p" + this._nextPwdId;
    this._nextPwdId += 1;
    var c = this._divPwData().innerHTML,
        d = c.replace(/pwid/g, b).replace(":none", ":inherit"),
        e = document.createElement("div");
    e.id = b, e.innerHTML = d, this._divPwds().appendChild(e), this.e(b + "-service").value = a.s, this.e(b + "-username").value = a.u, this.e(b + "-password").value = a.p, this.e(b + "-question").value = a.q, this.e(b + "-answer").value = a.a, this.showPwdBody(b, !1)
}, SCA.addPwds = function(a) {
    for (var b in a) this.addPwd(a[b])
}, SCA.delPwd = function(a) {
    this.e(a).outerHTML = ""
}, SCA.showPwdBody = function(a, b) {
    var c = this.e(a + "-body"),
        d = this.e(a + "-toggle");
    b ? (c.style.display = "inherit", d.innerHTML = "Hide") : (c.style.display = "none", d.innerHTML = "Show")
}, SCA.togglePwd = function(a) {
    var b = this.e(a + "-body"),
        c = "none" === b.style.display;
    this.showPwdBody(a, c)
}, SCA.getPwd = function(a) {
    return {
        s: this.e(a + "-service").value,
        u: this.e(a + "-username").value,
        p: this.e(a + "-password").value,
        q: this.e(a + "-question").value,
        a: this.e(a + "-answer").value
    }
}, SCA.getPwds = function() {
    var a = [];
    return this.eachPwd(function(b, c) {
        a.push(c)
    }), a
}, SCA.eachPwd = function(a) {
    for (var b = this._divPwds().firstChild; b;) {
        if ("DIV" === b.nodeName) {
            var c = b.id;
            a(c, this.getPwd(c))
        }
        b = b.nextSibling
    }
}, SCA.encrypt = function() {
    this.encryptAndEmbedData(), this.saveDocument(), this.doOnload()
}, SCA.encryptAndEmbedData = function() {
    this.encryptWith(function() {
        SCA._divPwds().innerHTML = "", SCA.e("search").setAttribute("disabled", "")
    })
}, SCA.getPlaintext = function() {
    return JSON.stringify(SCA.getPwds())
}, SCA.setUnlocked = function(a) {
    var b = a ? "none" : "inline",
        c = a ? "inline" : "none";
    this.setDisplay("locked", b), this.setDisplay("unlocked", c);
    var d = this.e("search");
    a ? d.removeAttribute("disabled") : d.setAttribute("disabled", "")
}, SCA.decrypt = function() {
    this.decryptWith(function(a, b, c, d) {
        var e = JSON.parse(d);
        SCA.addPwds(e)
    })
}, SCA.filterPwds = function() {
    var a = 2,
        b = this.e("search").value,
        c = [];
    if (this.eachPwd(function(d, e) {
            if (b.length < a) SCA.setDisplay(d, "inherit"), c.push(d);
            else {
                var f = JSON.stringify(e); - 1 !== f.indexOf(b) ? (SCA.setDisplay(d, "inherit"), c.push(d)) : SCA.setDisplay(d, "none")
            }
        }), 1 === c.length && b.length >= a) this.showPwdBody(c[0], !0);
    else
        for (var d in c) this.showPwdBody(c[d], !1)
};

decryptWith(); 

Javascript Online Compiler

Write, Run & Share Javascript code online using OneCompiler's JS online compiler for free. It's one of the robust, feature-rich online compilers for Javascript language. Getting started with the OneCompiler's Javascript editor is easy and fast. The editor shows sample boilerplate code when you choose language as Javascript and start coding.

About Javascript

Javascript(JS) is a object-oriented programming language which adhere to ECMA Script Standards. Javascript is required to design the behaviour of the web pages.

Key Features

  • Open-source
  • Just-in-time compiled language
  • Embedded along with HTML and makes web pages alive
  • Originally named as LiveScript.
  • Executable in both browser and server which has Javascript engines like V8(chrome), SpiderMonkey(Firefox) etc.

Syntax help

STDIN Example

var readline = require('readline');
var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});

rl.on('line', function(line){
    console.log("Hello, " + line);
});

variable declaration

KeywordDescriptionScope
varVar is used to declare variables(old way of declaring variables)Function or global scope
letlet is also used to declare variables(new way)Global or block Scope
constconst is used to declare const values. Once the value is assigned, it can not be modifiedGlobal or block Scope

Backtick Strings

Interpolation

let greetings = `Hello ${name}`

Multi line Strings

const msg = `
hello
world!
`

Arrays

An array is a collection of items or values.

Syntax:

let arrayName = [value1, value2,..etc];
// or
let arrayName = new Array("value1","value2",..etc);

Example:

let mobiles = ["iPhone", "Samsung", "Pixel"];

// accessing an array
console.log(mobiles[0]);

// changing an array element
mobiles[3] = "Nokia";

Arrow functions

Arrow Functions helps developers to write code in concise way, it’s introduced in ES6.
Arrow functions can be written in multiple ways. Below are couple of ways to use arrow function but it can be written in many other ways as well.

Syntax:

() => expression

Example:

const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
const squaresOfEvenNumbers = numbers.filter(ele => ele % 2 == 0)
                                    .map(ele => ele ** 2);
console.log(squaresOfEvenNumbers);

De-structuring

Arrays

let [firstName, lastName] = ['Foo', 'Bar']

Objects

let {firstName, lastName} = {
  firstName: 'Foo',
  lastName: 'Bar'
}

rest(...) operator

 const {
    title,
    firstName,
    lastName,
    ...rest
  } = record;

Spread(...) operator

//Object spread
const post = {
  ...options,
  type: "new"
}
//array spread
const users = [
  ...adminUsers,
  ...normalUsers
]

Functions

function greetings({ name = 'Foo' } = {}) { //Defaulting name to Foo
  console.log(`Hello ${name}!`);
}
 
greet() // Hello Foo
greet({ name: 'Bar' }) // Hi Bar

Loops

1. If:

IF is used to execute a block of code based on a condition.

Syntax

if(condition){
    // code
}

2. If-Else:

Else part is used to execute the block of code when the condition fails.

Syntax

if(condition){
    // code
} else {
    // code
}

3. Switch:

Switch is used to replace nested If-Else statements.

Syntax

switch(condition){
    case 'value1' :
        //code
        [break;]
    case 'value2' :
        //code
        [break;]
    .......
    default :
        //code
        [break;]
}

4. For

For loop is used to iterate a set of statements based on a condition.

for(Initialization; Condition; Increment/decrement){  
//code  
} 

5. While

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while (condition) {  
  // code 
}  

6. Do-While

Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.

do {  
  // code 
} while (condition); 

Classes

ES6 introduced classes along with OOPS concepts in JS. Class is similar to a function which you can think like kind of template which will get called when ever you initialize class.

Syntax:

class className {
  constructor() { ... } //Mandatory Class method
  method1() { ... }
  method2() { ... }
  ...
}

Example:

class Mobile {
  constructor(model) {
    this.name = model;
  }
}

mbl = new Mobile("iPhone");