def core_sha1(x, len)
      # append padding
      x[len >> 5] ||= 0
      x[len >> 5] |= 0x80 << (24 - len % 32)
      x[((len + 64 >> 9) << 4) + 15] = len

      w = Array.new(80, 0)
      a =  1_732_584_193
      b = -271_733_879
      c = -1_732_584_194
      d =  271_733_878
      e = -1_009_589_776

      # for(var i = 0; i < x.length; i += 16)
      i = 0
      while i < x.length
        olda = a
        oldb = b
        oldc = c
        oldd = d
        olde = e

        # for(var j = 0; j < 80; j++)
        j = 0
        while j < 80
          if j < 16
            w[j] = x[i + j] || 0
          else
            w[j] = rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1)
          end

          t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)),
                       safe_add(safe_add(e, w[j]), sha1_kt(j)))
          e = d
          d = c
          c = rol(b, 30)
          b = a
          a = t
          j += 1
        end

        a = safe_add(a, olda)
        b = safe_add(b, oldb)
        c = safe_add(c, oldc)
        d = safe_add(d, oldd)
        e = safe_add(e, olde)
        i += 16
      end
      [a, b, c, d, e]
    end
def core_sha1(x, len)
      # append padding
      x[len >> 5] ||= 0
      x[len >> 5] |= 0x80 << (24 - len % 32)
      x[((len + 64 >> 9) << 4) + 15] = len

      w = Array.new(80, 0)
      a =  1_732_584_193
      b = -271_733_879
      c = -1_732_584_194
      d =  271_733_878
      e = -1_009_589_776

      # for(var i = 0; i < x.length; i += 16)
      i = 0
      while i < x.length
        olda = a
        oldb = b
        oldc = c
        oldd = d
        olde = e

        # for(var j = 0; j < 80; j++)
        j = 0
        while j < 80
          if j < 16
            w[j] = x[i + j] || 0
          else
            w[j] = rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1)
          end

          t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)),
                       safe_add(safe_add(e, w[j]), sha1_kt(j)))
          e = d
          d = c
          c = rol(b, 30)
          b = a
          a = t
          j += 1
        end

        a = safe_add(a, olda)
        b = safe_add(b, oldb)
        c = safe_add(c, oldc)
        d = safe_add(d, oldd)
        e = safe_add(e, olde)
        i += 16
      end
      [a, b, c, d, e]
    end
Calculate the SHA-1 of an array of big-endian words, and a bit length