SMix; a specific case of ROMix. See scrypt.pdf in the links above.
974641
def smix(B, Bi, r, N, V, X):
    ''''''

    X[:32 * r] = B[Bi:Bi + 32 * r]                   # ROMix - 1

    for i in xrange(0, N):                           # ROMix - 2
        aod = i * 32 * r                             # ROMix - 3
        V[aod:aod + 32 * r] = X[:32 * r]
        blockmix_salsa8(X, 32 * r, r)                # ROMix - 4

    for i in xrange(0, N):                           # ROMix - 6
        j = X[(2 * r - 1) * 16] & (N - 1)            # ROMix - 7
        for xi in xrange(0, 32 * r):                 # ROMix - 8(inner)
            X[xi] ^= V[j * 32 * r + xi]

        blockmix_salsa8(X, 32 * r, r)                # ROMix - 9(outer)

    B[Bi:Bi + 32 * r] = X[:32 * r]
1372154
def get_merkle_proof(self, tx_hash: str, is_full: bool = False) -> dict:
        
        payload = self.generate_json_rpc_payload(RpcMethod.GET_MERKLE_PROOF, [tx_hash, 1])
        response = self.__post(self.__url, payload)
        if is_full:
            return response
        return response['result']
1016276
function mine(data, target, min, max) {
  let nonce = min;

  data.writeUInt32LE(nonce, 76, true);

  // The heart and soul of the miner: match the target.
  while (nonce <= max) {
    // Hash and test against the next target.
    // if (rcmp(digest.hash256(data), target) <= 0) // cfc
    // if (rcmp(powHash(data), target) <= 0) // ctl
    if (rcmp(calHash(data), target) <= 0)
      return nonce;

    // Increment the nonce to get a different hash.
    nonce++;

    // Update the raw buffer.
    data.writeUInt32LE(nonce, 76, true);
  }

  return -1;
}
1298020
final byte[] crypto(final byte[] input, final int offset, final int len, final boolean decrypt)
			throws InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException,
			BadPaddingException {
		aesCipher.init(decrypt ? Cipher.DECRYPT_MODE : Cipher.ENCRYPT_MODE, aesKey, aesIV);
		return aesCipher.doFinal(input, offset, len);
	}
635405
def hash128( key, seed = 0x0, x64arch = True ):
    '''  '''
    def hash128_x64( key, seed ):
        ''' Implements 128bit murmur3 hash for x64. '''

        def fmix( k ):
            k ^= k >> 33
            k  = ( k * 0xff51afd7ed558ccd ) & 0xFFFFFFFFFFFFFFFF
            k ^= k >> 33
            k  = ( k * 0xc4ceb9fe1a85ec53 ) & 0xFFFFFFFFFFFFFFFF
            k ^= k >> 33
            return k

        length = len( key )
        nblocks = int( length / 16 )

        h1 = seed
        h2 = seed

        c1 = 0x87c37b91114253d5
        c2 = 0x4cf5ad432745937f

        #body
        for block_start in xrange( 0, nblocks * 8, 8 ):
            # ??? big endian?
            k1 = key[ 2 * block_start + 7 ] << 56 | \
                 key[ 2 * block_start + 6 ] << 48 | \
                 key[ 2 * block_start + 5 ] << 40 | \
                 key[ 2 * block_start + 4 ] << 32 | \
                 key[ 2 * block_start + 3 ] << 24 | \
                 key[ 2 * block_start + 2 ] << 16 | \
                 key[ 2 * block_start + 1 ] <<  8 | \
                 key[ 2 * block_start + 0 ]

            k2 = key[ 2 * block_start + 15 ] << 56 | \
                 key[ 2 * block_start + 14 ] << 48 | \
                 key[ 2 * block_start + 13 ] << 40 | \
                 key[ 2 * block_start + 12 ] << 32 | \
                 key[ 2 * block_start + 11 ] << 24 | \
                 key[ 2 * block_start + 10 ] << 16 | \
                 key[ 2 * block_start + 9 ] <<  8 | \
                 key[ 2 * block_start + 8 ]

            k1  = ( c1 * k1 ) & 0xFFFFFFFFFFFFFFFF
            k1  = ( k1 << 31 | k1 >> 33 ) & 0xFFFFFFFFFFFFFFFF # inlined ROTL64
            k1  = ( c2 * k1 ) & 0xFFFFFFFFFFFFFFFF
            h1 ^= k1

            h1 = ( h1 << 27 | h1 >> 37 ) & 0xFFFFFFFFFFFFFFFF # inlined ROTL64
            h1 = ( h1 + h2 ) & 0xFFFFFFFFFFFFFFFF
            h1 = ( h1 * 5 + 0x52dce729 ) & 0xFFFFFFFFFFFFFFFF

            k2  = ( c2 * k2 ) & 0xFFFFFFFFFFFFFFFF
            k2  = ( k2 << 33 | k2 >> 31 ) & 0xFFFFFFFFFFFFFFFF # inlined ROTL64
            k2  = ( c1 * k2 ) & 0xFFFFFFFFFFFFFFFF
            h2 ^= k2

            h2 = ( h2 << 31 | h2 >> 33 ) & 0xFFFFFFFFFFFFFFFF # inlined ROTL64
            h2 = ( h1 + h2 ) & 0xFFFFFFFFFFFFFFFF
            h2 = ( h2 * 5 + 0x38495ab5 ) & 0xFFFFFFFFFFFFFFFF

        #tail
        tail_index = nblocks * 16
        k1 = 0
        k2 = 0
        tail_size = length & 15

        if tail_size >= 15:
            k2 ^= key[ tail_index + 14 ] << 48
        if tail_size >= 14:
            k2 ^= key[ tail_index + 13 ] << 40
        if tail_size >= 13:
            k2 ^= key[ tail_index + 12 ] << 32
        if tail_size >= 12:
            k2 ^= key[ tail_index + 11 ] << 24
        if tail_size >= 11:
            k2 ^= key[ tail_index + 10 ] << 16
        if tail_size >= 10:
            k2 ^= key[ tail_index +  9 ] << 8
        if tail_size >=  9:
            k2 ^= key[ tail_index +  8 ]

        if tail_size > 8:
            k2  = ( k2 * c2 ) & 0xFFFFFFFFFFFFFFFF
            k2  = ( k2 << 33 | k2 >> 31 ) & 0xFFFFFFFFFFFFFFFF # inlined ROTL64
            k2  = ( k2 * c1 ) & 0xFFFFFFFFFFFFFFFF
            h2 ^= k2

        if tail_size >=  8:
            k1 ^= key[ tail_index +  7 ] << 56
        if tail_size >=  7:
            k1 ^= key[ tail_index +  6 ] << 48
        if tail_size >=  6:
            k1 ^= key[ tail_index +  5 ] << 40
        if tail_size >=  5:
            k1 ^= key[ tail_index +  4 ] << 32
        if tail_size >=  4:
            k1 ^= key[ tail_index +  3 ] << 24
        if tail_size >=  3:
            k1 ^= key[ tail_index +  2 ] << 16
        if tail_size >=  2:
            k1 ^= key[ tail_index +  1 ] << 8
        if tail_size >=  1:
            k1 ^= key[ tail_index +  0 ]

        if tail_size > 0:
            k1  = ( k1 * c1 ) & 0xFFFFFFFFFFFFFFFF
            k1  = ( k1 << 31 | k1 >> 33 ) & 0xFFFFFFFFFFFFFFFF # inlined ROTL64
            k1  = ( k1 * c2 ) & 0xFFFFFFFFFFFFFFFF
            h1 ^= k1

        #finalization
        h1 ^= length
        h2 ^= length

        h1  = ( h1 + h2 ) & 0xFFFFFFFFFFFFFFFF
        h2  = ( h1 + h2 ) & 0xFFFFFFFFFFFFFFFF

        h1  = fmix( h1 )
        h2  = fmix( h2 )

        h1  = ( h1 + h2 ) & 0xFFFFFFFFFFFFFFFF
        h2  = ( h1 + h2 ) & 0xFFFFFFFFFFFFFFFF

        return ( h2 << 64 | h1 )

    def hash128_x86( key, seed ):
        ''' Implements 128bit murmur3 hash for x86. '''

        def fmix( h ):
            h ^= h >> 16
            h  = ( h * 0x85ebca6b ) & 0xFFFFFFFF
            h ^= h >> 13
            h  = ( h * 0xc2b2ae35 ) & 0xFFFFFFFF
            h ^= h >> 16
            return h

        length = len( key )
        nblocks = int( length / 16 )

        h1 = seed
        h2 = seed
        h3 = seed
        h4 = seed

        c1 = 0x239b961b
        c2 = 0xab0e9789
        c3 = 0x38b34ae5
        c4 = 0xa1e38b93

        #body
        for block_start in xrange( 0, nblocks * 16, 16 ):
            k1 = key[ block_start +  3 ] << 24 | \
                 key[ block_start +  2 ] << 16 | \
                 key[ block_start +  1 ] <<  8 | \
                 key[ block_start +  0 ]

            k2 = key[ block_start +  7 ] << 24 | \
                 key[ block_start +  6 ] << 16 | \
                 key[ block_start +  5 ] <<  8 | \
                 key[ block_start +  4 ]

            k3 = key[ block_start + 11 ] << 24 | \
                 key[ block_start + 10 ] << 16 | \
                 key[ block_start +  9 ] <<  8 | \
                 key[ block_start +  8 ]

            k4 = key[ block_start + 15 ] << 24 | \
                 key[ block_start + 14 ] << 16 | \
                 key[ block_start + 13 ] <<  8 | \
                 key[ block_start + 12 ]

            k1  = ( c1 * k1 ) & 0xFFFFFFFF
            k1  = ( k1 << 15 | k1 >> 17 ) & 0xFFFFFFFF # inlined ROTL32
            k1  = ( c2 * k1 ) & 0xFFFFFFFF
            h1 ^= k1

            h1 = ( h1 << 19 | h1 >> 13 ) & 0xFFFFFFFF # inlined ROTL32
            h1 = ( h1 + h2 ) & 0xFFFFFFFF
            h1 = ( h1 * 5 + 0x561ccd1b ) & 0xFFFFFFFF

            k2  = ( c2 * k2 ) & 0xFFFFFFFF
            k2  = ( k2 << 16 | k2 >> 16 ) & 0xFFFFFFFF # inlined ROTL32
            k2  = ( c3 * k2 ) & 0xFFFFFFFF
            h2 ^= k2

            h2 = ( h2 << 17 | h2 >> 15 ) & 0xFFFFFFFF # inlined ROTL32
            h2 = ( h2 + h3 ) & 0xFFFFFFFF
            h2 = ( h2 * 5 + 0x0bcaa747 ) & 0xFFFFFFFF

            k3  = ( c3 * k3 ) & 0xFFFFFFFF
            k3  = ( k3 << 17 | k3 >> 15 ) & 0xFFFFFFFF # inlined ROTL32
            k3  = ( c4 * k3 ) & 0xFFFFFFFF
            h3 ^= k3

            h3 = ( h3 << 15 | h3 >> 17 ) & 0xFFFFFFFF # inlined ROTL32
            h3 = ( h3 + h4 ) & 0xFFFFFFFF
            h3 = ( h3 * 5 + 0x96cd1c35 ) & 0xFFFFFFFF

            k4  = ( c4 * k4 ) & 0xFFFFFFFF
            k4  = ( k4 << 18 | k4 >> 14 ) & 0xFFFFFFFF # inlined ROTL32
            k4  = ( c1 * k4 ) & 0xFFFFFFFF
            h4 ^= k4

            h4 = ( h4 << 13 | h4 >> 19 ) & 0xFFFFFFFF # inlined ROTL32
            h4 = ( h1 + h4 ) & 0xFFFFFFFF
            h4 = ( h4 * 5 + 0x32ac3b17 ) & 0xFFFFFFFF

        #tail
        tail_index = nblocks * 16
        k1 = 0
        k2 = 0
        k3 = 0
        k4 = 0
        tail_size = length & 15

        if tail_size >= 15:
            k4 ^= key[ tail_index + 14 ] << 16
        if tail_size >= 14:
            k4 ^= key[ tail_index + 13 ] << 8
        if tail_size >= 13:
            k4 ^= key[ tail_index + 12 ]

        if tail_size > 12:
            k4  = ( k4 * c4 ) & 0xFFFFFFFF
            k4  = ( k4 << 18 | k4 >> 14 ) & 0xFFFFFFFF # inlined ROTL32
            k4  = ( k4 * c1 ) & 0xFFFFFFFF
            h4 ^= k4

        if tail_size >= 12:
            k3 ^= key[ tail_index + 11 ] << 24
        if tail_size >= 11:
            k3 ^= key[ tail_index + 10 ] << 16
        if tail_size >= 10:
            k3 ^= key[ tail_index +  9 ] << 8
        if tail_size >=  9:
            k3 ^= key[ tail_index +  8 ]

        if tail_size > 8:
            k3  = ( k3 * c3 ) & 0xFFFFFFFF
            k3  = ( k3 << 17 | k3 >> 15 ) & 0xFFFFFFFF # inlined ROTL32
            k3  = ( k3 * c4 ) & 0xFFFFFFFF
            h3 ^= k3

        if tail_size >= 8:
            k2 ^= key[ tail_index + 7 ] << 24
        if tail_size >= 7:
            k2 ^= key[ tail_index + 6 ] << 16
        if tail_size >= 6:
            k2 ^= key[ tail_index + 5 ] << 8
        if tail_size >= 5:
            k2 ^= key[ tail_index + 4 ]

        if tail_size > 4:
            k2  = ( k2 * c2 ) & 0xFFFFFFFF
            k2  = ( k2 << 16 | k2 >> 16 ) & 0xFFFFFFFF # inlined ROTL32
            k2  = ( k2 * c3 ) & 0xFFFFFFFF
            h2 ^= k2

        if tail_size >= 4:
            k1 ^= key[ tail_index + 3 ] << 24
        if tail_size >= 3:
            k1 ^= key[ tail_index + 2 ] << 16
        if tail_size >= 2:
            k1 ^= key[ tail_index + 1 ] << 8
        if tail_size >= 1:
            k1 ^= key[ tail_index + 0 ]

        if tail_size > 0:
            k1  = ( k1 * c1 ) & 0xFFFFFFFF
            k1  = ( k1 << 15 | k1 >> 17 ) & 0xFFFFFFFF # inlined ROTL32
            k1  = ( k1 * c2 ) & 0xFFFFFFFF
            h1 ^= k1

        #finalization
        h1 ^= length
        h2 ^= length
        h3 ^= length
        h4 ^= length

        h1 = ( h1 + h2 ) & 0xFFFFFFFF
        h1 = ( h1 + h3 ) & 0xFFFFFFFF
        h1 = ( h1 + h4 ) & 0xFFFFFFFF
        h2 = ( h1 + h2 ) & 0xFFFFFFFF
        h3 = ( h1 + h3 ) & 0xFFFFFFFF
        h4 = ( h1 + h4 ) & 0xFFFFFFFF

        h1 = fmix( h1 )
        h2 = fmix( h2 )
        h3 = fmix( h3 )
        h4 = fmix( h4 )

        h1 = ( h1 + h2 ) & 0xFFFFFFFF
        h1 = ( h1 + h3 ) & 0xFFFFFFFF
        h1 = ( h1 + h4 ) & 0xFFFFFFFF
        h2 = ( h1 + h2 ) & 0xFFFFFFFF
        h3 = ( h1 + h3 ) & 0xFFFFFFFF
        h4 = ( h1 + h4 ) & 0xFFFFFFFF

        return ( h4 << 96 | h3 << 64 | h2 << 32 | h1 )

    key = bytearray( xencode(key) )

    if x64arch:
        return hash128_x64( key, seed )
    else:
        return hash128_x86( key, seed )
1293580
def _get_crypto(keylen, hexkey, key):
    """"""
    if keylen not in camcrypt.ACCEPTABLE_KEY_LENGTHS:
        raise ValueError("key length must be one of 128, 192, or 256")

    if hexkey:
        key = key.decode('hex')

    return camcrypt.CamCrypt(keylen=keylen, key=key)
169414
def get_nonce(block_representation, coin_symbol='btc', api_key=None):
    '''
    
    '''
    return get_block_overview(block_representation=block_representation,
            coin_symbol=coin_symbol, txn_limit=1, api_key=api_key)['bits']
552303
def sighash_all(self, index=0, script=None,
                    prevout_value=None, anyone_can_pay=False):
        '''
        
        '''

        if riemann.network.FORKID is not None:
            return self._sighash_forkid(index=index,
                                        script=script,
                                        prevout_value=prevout_value,
                                        sighash_type=shared.SIGHASH_ALL,
                                        anyone_can_pay=anyone_can_pay)

        copy_tx = self._sighash_prep(index=index, script=script)
        if anyone_can_pay:
            return self._sighash_anyone_can_pay(
                index=index, copy_tx=copy_tx, sighash_type=shared.SIGHASH_ALL)

        return self._sighash_final_hashing(copy_tx, shared.SIGHASH_ALL)
737930
function evp_kdf (data, salt, opts) { // eslint-disable-line
  // A single EVP iteration, returns `D_i`, where block equlas to `D_(i-1)`
  function iter (block) {
    var hash = crypto.createHash(opts.digest || 'md5')
    hash.update(block)
    hash.update(data)
    hash.update(salt)
    block = hash.digest()

    for (var i = 1; i < (opts.count || 1); i++) {
      hash = crypto.createHash(opts.digest || 'md5')
      hash.update(block)
      block = hash.digest()
    }

    return block
  }

  var keysize = opts.keysize || 16
  var ivsize = opts.ivsize || 16

  var ret = []

  var i = 0
  while (Buffer.concat(ret).length < (keysize + ivsize)) {
    ret[i] = iter((i === 0) ? Buffer.alloc(0) : ret[i - 1])
    i++
  }

  var tmp = Buffer.concat(ret)

  return {
    key: tmp.slice(0, keysize),
    iv: tmp.slice(keysize, keysize + ivsize)
  }
}
1023945
def sighash_all(self, index, script=None, anyone_can_pay=False):
        '''
        
        '''
        copy_tx = self._sighash_prep(index, script)

        if anyone_can_pay:
            return self._sighash_anyone_can_pay(
                index=index,
                copy_tx=copy_tx,
                sighash_type=shared.SIGHASH_ALL)

        return self._sighash_final_hashing(
            index=index,
            copy_tx=copy_tx,
            sighash_type=shared.SIGHASH_ALL)
502631
def format_checksum(checksum_pyxb):
    
    return '{}/{}'.format(
        checksum_pyxb.algorithm.upper().replace('-', ''), checksum_pyxb.value().lower()
    )
703558
def smpar(C):
    """"""
    m2 = C['m2'].real
    Lambda = C['Lambda'].real
    v = (sqrt(2 * m2 / Lambda) + 3 * m2**(3 / 2) /
         (sqrt(2) * Lambda**(5 / 2)) * C['phi'])
    GF = 1 / (sqrt(2) * v**2)  # TODO
    Mh2 = 2 * m2 * (1 - m2 / Lambda * (3 * C['phi'] - 4 * Lambda * C['phiBox'] +
                                       Lambda * C['phiD']))
    eps = C['phiWB'] * (v**2)
    gb = (C['g'] / (1 - C['phiW'] * (v**2))).real
    gpb = (C['gp'] / (1 - C['phiB'] * (v**2))).real
    gsb = (C['gs'] / (1 - C['phiG'] * (v**2))).real
    MW = gb * v / 2
    ZG0 = 1 + C['phiD'] * (v**2) / 4
    MZ = (sqrt(gb**2 + gpb**2) / 2 * v
          * (1 + eps * gb * gpb / (gb**2 + gpb**2)) * ZG0)
    Mnup = -(v**2) * C['llphiphi']
    Mep = v / sqrt(2) * (C['Ge'] - C['ephi'] * (v**2) / 2)
    Mup = v / sqrt(2) * (C['Gu'] - C['uphi'] * (v**2) / 2)
    Mdp = v / sqrt(2) * (C['Gd'] - C['dphi'] * (v**2) / 2)
    UeL, Me, UeR = ckmutil.diag.msvd(Mep)
    UuL, Mu, UuR = ckmutil.diag.msvd(Mup)
    UdL, Md, UdR = ckmutil.diag.msvd(Mdp)
    UnuL, Mnu = ckmutil.diag.mtakfac(Mnup)
    eb = (gb * gpb / sqrt(gb**2 + gpb**2) *
          (1 - eps * gb * gpb / (gb**2 + gpb**2)))
    K = UuL.conj().T @ UdL
    # U = UeL.conj().T @ UnuL
    sm = {}
    sm['GF'] = GF
    sm['alpha_e'] = eb**2 / (4 * pi)
    sm['alpha_s'] = gsb**2 / (4 * pi)
    sm['Vub'] = abs(K[0, 2])
    sm['Vcb'] = abs(K[1, 2])
    sm['Vus'] = abs(K[0, 1])
    sm['delta'] = phase(-K[0, 0] * K[0, 2].conj()
                        / (K[1, 0] * K[1, 2].conj()))
    # sm['U'] = Uu
    sm['m_W'] = MW
    sm['m_Z'] = MZ
    sm['m_h'] = sqrt(abs(Mh2))
    sm['m_u'] = Mu[0]
    sm['m_c'] = Mu[1]
    sm['m_t'] = Mu[2]
    sm['m_d'] = Md[0]
    sm['m_s'] = Md[1]
    sm['m_b'] = Md[2]
    sm['m_e'] = Me[0]
    sm['m_mu'] = Me[1]
    sm['m_tau'] = Me[2]
    return  {k: v.real for k, v in sm.items()}
483266
function ScryptPacket(passwd, salt, N, r, p, len) {
  Packet.call(this);
  this.passwd = passwd || null;
  this.salt = salt || null;
  this.N = N != null ? N : -1;
  this.r = r != null ? r : -1;
  this.p = p != null ? p : -1;
  this.len = len != null ? len : -1;
}
507459
function (password, algorithm, salt) {
            salt = salt || Crypto.randomBytes(128).toString("hex");
            algorithm = algorithm || this.$.algorithm;

            var hash = Crypto.createHash(this.$.algorithm);
            hash.update(salt + password, "utf8");

            return [algorithm, salt, hash.digest("hex")].join(this.$.delimiter);
        }
383965
function getK(params, S_buf) {
  assertIsNBuffer(S_buf, params, "S");
  return crypto.createHash(params.hash)
      .update(S_buf)
      .digest();
}
1199910
def get_bits(block_representation, coin_symbol='btc', api_key=None):
    '''
    
    '''
    return get_block_overview(block_representation=block_representation,
            coin_symbol=coin_symbol, txn_limit=1, api_key=api_key)['bits']
267621
def decrypt(data, digest=True):
    """"""
    alg, _, data = data.rpartition("$")
    if not alg:
        return data
    data = _from_hex_digest(data) if digest else data
    try:
        return implementations["decryption"][alg](
            data, implementations["get_key"]()
        )
    except KeyError:
        raise CryptError("Can not decrypt key for algorithm: %s" % alg)