import hashlib


def shorten(link: str):
    """
    Calculates a hash function for a string and returns eight characters
    from the beginning of the received value.
    """
    # ! The algorithm used in this function must be checked out for
    # ! the probability of URL collision when hash calculation for two
    # ! different strings gives the same result 
    return hashlib.sha256(link.encode()).hexdigest()[:8]