INNER CODE UNIT · Python

string_encode

A3sal0n/CyberThreatHunting · tools/bro-dns-iforest.py:39

def string_encode(data):
    alphabet = '0123456789abcdefghijklmnopqrstuvwxyz.: '
    char_to_int = dict((c, i) for i, c in enumerate(alphabet))
    integer_encoded = [char_to_int[char.decode("ascii")] for char in data]
    encoded = ""
    for n in integer_encoded:
        encoded += str(n)
    return int(encoded)


def entropy(s):
    "Calculates the Boltzmann entropy of a string"
    l = float(len(s))
    return -sum(map(lambda a: (a / l) * math.log((a / l), 2), Counter(s).values()))


def select_fields(data):
    output = []

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…