def entropy_of_byte(packets, position):
 counter = [0 for _ in range(256)]
 for pkt in packets:
  if ((- position) <= len(pkt)):
   counter[ord(pkt[position])] += 1
 entropy = 0
 length = len(packets)
 for count in counter:
  if (count > 0):
   ratio = (float(count) / length)
   entropy -= (ratio * math.log(ratio, 2))
 return entropy

def entropy_of_byte ( packets , position ) : counter = [ 0 for _ in range ( 256 ) ] for pkt in packets : if ( ( - position ) <= len ( pkt ) ) : counter [ ord ( pkt [ position ] ) ] += 1 entropy = 0 length = len ( packets ) for count in counter : if ( count > 0 ) : ratio = ( float ( count ) / length ) entropy -= ( ratio * math . log ( ratio , 2 ) ) return entropy
compute the entropy of a byte at a given offset .