import time


def obfuscate_api_key(key, verbose=False):
    """Generates the obfuscated API key to attach while logging in.

    Args:
        verbose (bool): Defaults to False. If set to True, end result will be printed.
        key (String): The API key

    Returns:
        int: Timestamp of generation
        key: Obfuscated key
    """
    seed = key
    now = int(time.time() * 1000)
    n = str(now)[-6:]
    r = str(int(n) >> 1).zfill(6)
    key = ""
    for i in range(0, len(str(n)), 1):
        key += seed[int(str(n)[i])]
    for j in range(0, len(str(r)), 1):
        key += seed[int(str(r)[j]) + 2]

    if verbose:
        print("Timestamp:", now, "\tKey:", key)

    return now, key