|log2(keyspace^length) = bits|
        -> (#float) number of bits of entropy in @length of characters for
            a given a @keyspace
970184
def bits_in(length, keyspace):
    
    keyspace = len(keyspace)
    length_per_cycle = 64
    if length > length_per_cycle:
        bits = 0
        length_processed = 0
        cycles = ceil(length / length_per_cycle)
        for _ in range(int(cycles)):
            if length_processed + length_per_cycle > length:
                length_per_cycle = length - length_processed
            bits += calc_bits_in(length_per_cycle, keyspace)
            length_processed += length_per_cycle
    else:
        bits = calc_bits_in(length, keyspace)
    return float(abs(bits))
481302
public static int log_2( int x ) {
		int shift;
		/* Scale x to range 1.0 <= x < 2.0 */
		shift = IBXM.FP_SHIFT;
		while( x < IBXM.FP_ONE ) {
			x <<= 1;
			shift--;
		}
		while( x >= ( IBXM.FP_ONE << 1 ) ) {
			x >>= 1;
			shift++;
		}
		return ( IBXM.FP_ONE * shift ) + eval_table( log_2_table, x - IBXM.FP_ONE );
	}
1212160
private double logL(int k, long n, double x) {
        if (x == 0.0) x = 0.01;
        if (x == 1.0) x = 0.99;
        return k * Math.log(x) + (n-k) * Math.log(1-x);
    }
19924
private static String getLeadingZeros(int i, int size)
	{
		assert i <= size;
		int w1 = (int) Math.floor(Math.log10(size));
		int w2 = (int) Math.floor(Math.log10(i));
		
		String s = "";

		for (int j = w2; j < w1; j++)
		{
			s += "0";
		}
		return s;
	}
37699
def calculate_shannon_entropy(self, data):
        
        if not data:  # pragma: no cover
            return 0

        entropy = 0
        for x in self.charset:
            p_x = float(data.count(x)) / len(data)
            if p_x > 0:
                entropy += - p_x * math.log(p_x, 2)

        return entropy
579643
def calculate_prefix_length
      duplications = 2

      (0..(block_size() -1)).each do |pad_length|
        # construct a message like this:
        # 1 <unknown-prefix>|| prefix_pad * DUMMY
        # 2 DUMMY * (block_size)
        # 3 DUMMY * (block_size)
        # 4 - (n-1) Target Message
        # 5: target_end + pkcs#7 padding
        malicious_msg = (PREFIX_PAD_DUMMY * pad_length) + (DUMMY * (block_size * duplications)) 
        ciphertext = @oracle.encipher(malicious_msg)
        
        return pad_length if block_is_left_aligned?(ciphertext,duplications)
      end
    end
1260911
def logspace(self,bins=None,units=None,conversion_function=convert_time,resolution=None,end_at_end=True):
        
        if type(bins) in [list, np.ndarray]:
            return bins
        min = conversion_function(self.min,from_units=self.units,to_units=units)
        max = conversion_function(self.max,from_units=self.units,to_units=units)
        if units is None:
            units = self.units
        if resolution is None:
            resolution = 1.0
        if bins is None:
            bins = self.len(resolution=resolution,units=units,conversion_function=conversion_function)# + 1
        if units != '1' and end_at_end:
            # continuous variable behaviour:
            #   we end with the last valid value at the outer edge
            return np.logspace(np.log10(min),np.log10(max),bins+1)[:-1]
        # discrete variable behaviour:
        #   we end with the last valid value as its own bin
        return np.logspace(np.log10(min),np.log10(max),bins)
941994
def entropy_H(self, data):
        """"""

        if not data:
            return 0.0

        occurences = Counter(bytearray(data))

        entropy = 0
        for x in occurences.values():
            p_x = float(x) / len(data)
            entropy -= p_x*math.log(p_x, 2)

        return entropy
978616
function(b) {
  var b2 = b.getByte();
  if(b2 === 0x80) {
    return undefined;
  }

  // see if the length is "short form" or "long form" (bit 8 set)
  var length;
  var longForm = b2 & 0x80;
  if(!longForm) {
    // length is just the first byte
    length = b2;
  } else {
    // the number of bytes the length is specified in bits 7 through 1
    // and each length byte is in big-endian base-256
    length = b.getInt((b2 & 0x7F) << 3);
  }
  return length;
}
926510
def size_of_varint_2(value):
    
    value = (value << 1) ^ (value >> 63)
    if value <= 0x7f:
        return 1
    if value <= 0x3fff:
        return 2
    if value <= 0x1fffff:
        return 3
    if value <= 0xfffffff:
        return 4
    if value <= 0x7ffffffff:
        return 5
    if value <= 0x3ffffffffff:
        return 6
    if value <= 0x1ffffffffffff:
        return 7
    if value <= 0xffffffffffffff:
        return 8
    if value <= 0x7fffffffffffffff:
        return 9
    return 10
190822
def _len_int(obj):
    '''
    '''
    if obj:
        n, i = 1, abs(obj)
        if i > _digitmax:
             # no log(x[, base]) in Python 2.2
            n += int(log(i) * _digitlog)
    else:  # zero
        n = 0
    return n
432676
def maxEntropy(n,k):
  

  s = float(k)/n
  if s > 0.0 and s < 1.0:
    entropy = - s * math.log(s,2) - (1 - s) * math.log(1 - s,2)
  else:
    entropy = 0

  return n*entropy
792180
private static int getLengthBits(int version, int bitsA, int bitsB, int bitsC) {
		int lengthBits;

		if (version < 10)
			lengthBits = bitsA;
		else if (version < 27)
			lengthBits = bitsB;
		else
			lengthBits = bitsC;
		return lengthBits;
	}
1095780
async function getPkcs1Padding(length) {
  let result = '';
  while (result.length < length) {
    const randomBytes = await random.getRandomBytes(length - result.length);
    for (let i = 0; i < randomBytes.length; i++) {
      if (randomBytes[i] !== 0) {
        result += String.fromCharCode(randomBytes[i]);
      }
    }
  }
  return result;
}
1186740
function wstring(bits, s) {
      var charLength = bits / 8;
      var dataLength = s.length * charLength;
      var res = Buffer.alloc(xutil.padded_length(dataLength));
      debugger;
      var write = res[bufferWriteBits[bits]];
      res.fill(0);
      for (var i = 0; i < s.length; i++) write.call(res, s.charCodeAt(i), i * charLength);
      return res;
    }
1060166
def appendRandomLenPadding(str, blocksize=AES_blocksize):
  ''
  pad_len = paddingLength(len(str), blocksize) - 1
  
  from os import urandom
  
  padding = urandom(pad_len)+chr(pad_len)
  
  return str + padding
647707
function entropy(labels, ix) {
    var N= ix.length;
    var p=0.0;
    for(var i=0;i<N;i++) {
        if(labels[ix[i]]==1) p+=1;
    }
    p=(1+p)/(N+2); // let's be bayesian about this
    q=(1+N-p)/(N+2);
    return (-p*Math.log(p) -q*Math.log(q));
}