import string


def build_cypher_map(keyword, decrypt):
    """
    Builds the cypher substituition map that will be used for the encryption
    and decryption.

    :param str keyword: Cypher keyword
    :param bool decrypt: If True, build the cypher map for decryption
    :rtype: dict
    :return: dictionary with the cypher substituitions
    """

    # Build a list of uppercase letters, making it easier to loop and to
    # generate the cypher dictionary
    alphabet = list(string.ascii_uppercase)

    # This cypher works with uppercase only
    keyword = keyword.upper()

    # Remove duplicated letters from the keyword
    sequence = sorted(set(keyword), key=keyword.index)

    # Append the other letters of the alphabet in reverse order
    sequence.extend([c for c in reversed(alphabet) if c not in sequence])

    if decrypt:
        return dict(zip(sequence, alphabet))
    else:
        return dict(zip(alphabet, sequence))