import math


def calcEntropy(messageString, alphabet, verbose = False):
    """
        Calculate the entropy (information content) of the given message
        using the probabilities of each character in the given alphabet.
    """
    if verbose:
        print("Calculating entropy of %s" %alphabet)

    entropy = 0.0

    for ch in messageString:
        p = alphabet[ch]
        entropy += -p*math.log2(p)

        if verbose:
            print(ch, p)
            print("Entropy: %f" %entropy)

    return entropy