How to use the crypt.bytesToWords function in crypt

To help you get started, we’ve selected a few crypt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vightel / FloodMapsWorkshop / publisher / lib / sha1.js View on Github external
sha1 = function (message) {
    // Convert to byte array
    if (message.constructor == String)
      message = utf8.stringToBytes(message);
    else if (typeof Buffer !== 'undefined' && typeof Buffer.isBuffer == 'function' && Buffer.isBuffer(message))
      message = Array.prototype.slice.call(message, 0);
    else if (!Array.isArray(message))
      message = message.toString();

    // otherwise assume byte array

    var m  = crypt.bytesToWords(message),
        l  = message.length * 8,
        w  = [],
        H0 =  1732584193,
        H1 = -271733879,
        H2 = -1732584194,
        H3 =  271733878,
        H4 = -1009589776;

    // Padding
    m[l >> 5] |= 0x80 << (24 - l % 32);
    m[((l + 64 >>> 9) << 4) + 15] = l;

    for (var i = 0; i < m.length; i += 16) {
      var a = H0,
          b = H1,
          c = H2,
github JedWatson / react-select / examples / dist / app.js View on Github external
md5 = function (message, options) {
    // Convert to byte array
    if (message.constructor == String)
      if (options && options.encoding === 'binary')
        message = bin.stringToBytes(message);
      else
        message = utf8.stringToBytes(message);
    else if (isBuffer(message))
      message = Array.prototype.slice.call(message, 0);
    else if (!Array.isArray(message))
      message = message.toString();
    // else, assume byte array already

    var m = crypt.bytesToWords(message),
        l = message.length * 8,
        a =  1732584193,
        b = -271733879,
        c = -1732584194,
        d =  271733878;

    // Swap endian
    for (var i = 0; i < m.length; i++) {
      m[i] = ((m[i] <<  8) | (m[i] >>> 24)) & 0x00FF00FF |
             ((m[i] << 24) | (m[i] >>>  8)) & 0xFF00FF00;
    }

    // Padding
    m[l >>> 5] |= 0x80 << (l % 32);
    m[(((l + 64) >>> 9) << 4) + 14] = l;
github pvorb / node-sha1 / sha1.js View on Github external
sha1 = function (message) {
    // Convert to byte array
    if (message.constructor == String)
      message = utf8.stringToBytes(message);
    else if (!Array.isArray(message))
      message = message.toString();
    // otherwise assume byte array

    var m  = crypt.bytesToWords(message),
        l  = message.length * 8,
        w  = [],
        H0 =  1732584193,
        H1 = -271733879,
        H2 = -1732584194,
        H3 =  271733878,
        H4 = -1009589776;

    // Padding
    m[l >> 5] |= 0x80 << (24 - l % 32);
    m[((l + 64 >>> 9) << 4) + 15] = l;

    for (var i = 0; i < m.length; i += 16) {
      var a = H0,
          b = H1,
          c = H2,
github codeforgeek / RESTful-api-using-nodejs / node_modules / MD5 / md5.js View on Github external
md5 = function (message, options) {
    // Convert to byte array
    if (message.constructor == String)
      if (options && options.encoding === 'binary')
        message = bin.stringToBytes(message);
      else
        message = utf8.stringToBytes(message);
    else if (typeof Buffer != 'undefined' &&
        typeof Buffer.isBuffer == 'function' && Buffer.isBuffer(message))
      message = Array.prototype.slice.call(message, 0);
    else if (!Array.isArray(message))
      message = message.toString();
    // else, assume byte array already

    var m = crypt.bytesToWords(message),
        l = message.length * 8,
        a =  1732584193,
        b = -271733879,
        c = -1732584194,
        d =  271733878;

    // Swap endian
    for (var i = 0; i < m.length; i++) {
      m[i] = ((m[i] <<  8) | (m[i] >>> 24)) & 0x00FF00FF |
             ((m[i] << 24) | (m[i] >>>  8)) & 0xFF00FF00;
    }

    // Padding
    m[l >>> 5] |= 0x80 << (l % 32);
    m[(((l + 64) >>> 9) << 4) + 14] = l;
github pvorb / node-md5 / md5.js View on Github external
md5 = function (message, options) {
    // Convert to byte array
    if (message.constructor == String)
      if (options && options.encoding === 'binary')
        message = bin.stringToBytes(message);
      else
        message = utf8.stringToBytes(message);
    else if (isBuffer(message))
      message = Array.prototype.slice.call(message, 0);
    else if (!Array.isArray(message) && message.constructor !== Uint8Array)
      message = message.toString();
    // else, assume byte array already

    var m = crypt.bytesToWords(message),
        l = message.length * 8,
        a =  1732584193,
        b = -271733879,
        c = -1732584194,
        d =  271733878;

    // Swap endian
    for (var i = 0; i < m.length; i++) {
      m[i] = ((m[i] <<  8) | (m[i] >>> 24)) & 0x00FF00FF |
             ((m[i] << 24) | (m[i] >>>  8)) & 0xFF00FF00;
    }

    // Padding
    m[l >>> 5] |= 0x80 << (l % 32);
    m[(((l + 64) >>> 9) << 4) + 14] = l;
github petrosagg / papagal / src / vendor / MD5 / index.js View on Github external
if (e.constructor == String) {
                if (t && t.encoding === "binary") {
                    e = i.stringToBytes(e);
                } else {
                    e = o.stringToBytes(e);
                }
            } else {
                if (typeof n != "undefined" && typeof n.isBuffer == "function" && n.isBuffer(e)) {
                    e = Array.prototype.slice.call(e, 0);
                } else {
                    if (!Array.isArray(e)) {
                        e = e.toString()
                    };
                }
            }
            for (var a = r.bytesToWords(e), u = 8 * e.length, l = 1732584193, c = -271733879, p = -1732584194, d = 271733878, h = 0; h < a.length; h++) {
                a[h] = 16711935 & (a[h] << 8 | a[h] >>> 24) | 4278255360 & (a[h] << 24 | a[h] >>> 8);
            }
            a[u >>> 5] |= 128 << u % 32;
            a[(u + 64 >>> 9 << 4) + 14] = u;
            for (var f = s._ff, m = s._gg, g = s._hh, v = s._ii, h = 0; h < a.length; h += 16) {
                var b = l, y = c, _ = p, w = d;
                l = f(l, c, p, d, a[h + 0], 7, -680876936);
                d = f(d, l, c, p, a[h + 1], 12, -389564586);
                p = f(p, d, l, c, a[h + 2], 17, 606105819);
                c = f(c, p, d, l, a[h + 3], 22, -1044525330);
                l = f(l, c, p, d, a[h + 4], 7, -176418897);
                d = f(d, l, c, p, a[h + 5], 12, 1200080426);
                p = f(p, d, l, c, a[h + 6], 17, -1473231341);
                c = f(c, p, d, l, a[h + 7], 22, -45705983);
                l = f(l, c, p, d, a[h + 8], 7, 1770035416);
                d = f(d, l, c, p, a[h + 9], 12, -1958414417);