import hashlib


def key_to_md5(key):
    """
    convert bibtex-key to shortened md5-sum to avoid special characters in the keys
    :param key: bibtex-key of an article
    :return: converted key, first six characters of the key md5-sum
    """
    m = hashlib.md5()
    m.update(key.encode('utf-8'))
    hd = m.hexdigest()
    shorthd = hd[:6]
    if shorthd.isdigit():
        return shorthd + 'a'
    return shorthd