def compute_chi_squared(data):
    """
    Calculate Chi-Squared value for a given byte array.

    Keyword arguments:
    data -- data bytes
    """
    if len(data) == 0:
        return 0
    expected = float(len(data)) / 256.0
    observed = [0] * 256
    for b in data:
        observed[b] += 1
    chi_squared = 0
    for o in observed:
        chi_squared += (o - expected) ** 2 / expected
    return chi_squared
