def encrypt_selection(selection: PlaintextBallotSelection, selection_description: SelectionDescription, elgamal_public_key: ElementModP, crypto_extended_base_hash: ElementModQ, nonce_seed: ElementModQ, is_placeholder: bool=False, should_verify_proofs: bool=True) -> Optional[CiphertextBallotSelection]:
    "\n    Encrypt a specific `BallotSelection` in the context of a specific `BallotContest`\n\n    :param selection: the selection in the valid input form\n    :param selection_description: the `SelectionDescription` from the\n        `ContestDescription` which defines this selection's structure\n    :param elgamal_public_key: the public key (K) used to encrypt the ballot\n    :param crypto_extended_base_hash: the extended base hash of the election\n    :param nonce_seed: an `ElementModQ` used as a header to seed the `Nonce` generated for this selection.\n                 this value can be (or derived from) the BallotContest nonce, but no relationship is required\n    :param is_placeholder: specifies if this is a placeholder selection\n    :param should_verify_proofs: specify if the proofs should be verified prior to returning (default True)\n    "
    if (not selection.is_valid(selection_description.object_id)):
        log_warning(f'malformed input selection: {selection}')
        return None
    selection_description_hash = selection_description.crypto_hash()
    nonce_sequence = Nonces(selection_description_hash, nonce_seed)
    selection_nonce = nonce_sequence[selection_description.sequence_order]
    disjunctive_chaum_pedersen_nonce = next(iter(nonce_sequence))
    log_info(f': encrypt_selection: for {selection_description.object_id} hash: {selection_description_hash.to_hex()}')
    selection_representation = selection.vote
    elgamal_encryption = elgamal_encrypt(selection_representation, selection_nonce, elgamal_public_key)
    if (elgamal_encryption is None):
        return None
    encrypted_selection = make_ciphertext_ballot_selection(object_id=selection.object_id, description_hash=selection_description_hash, ciphertext=get_optional(elgamal_encryption), elgamal_public_key=elgamal_public_key, crypto_extended_base_hash=crypto_extended_base_hash, proof_seed=disjunctive_chaum_pedersen_nonce, selection_representation=selection_representation, is_placeholder_selection=is_placeholder, nonce=selection_nonce)
    if (encrypted_selection.proof is None):
        return None
    if (not should_verify_proofs):
        return encrypted_selection
    if encrypted_selection.is_valid_encryption(selection_description_hash, elgamal_public_key, crypto_extended_base_hash):
        return encrypted_selection
    log_warning(f'mismatching selection proof for selection {encrypted_selection.object_id}')
    return None
Encrypt a specific `BallotSelection` in the context of a specific `BallotContest`

:param selection: the selection in the valid input form
:param selection_description: the `SelectionDescription` from the
    `ContestDescription` which defines this selection's structure
:param elgamal_public_key: the public key (K) used to encrypt the ballot
:param crypto_extended_base_hash: the extended base hash of the election
:param nonce_seed: an `ElementModQ` used as a header to seed the `Nonce` generated for this selection.
             this value can be (or derived from) the BallotContest nonce, but no relationship is required
:param is_placeholder: specifies if this is a placeholder selection
:param should_verify_proofs: specify if the proofs should be verified prior to returning (default True)
def encrypt_selection(selection: PlaintextBallotSelection, selection_description: SelectionDescription, elgamal_public_key: ElementModP, crypto_extended_base_hash: ElementModQ, nonce_seed: ElementModQ, is_placeholder: bool=False, should_verify_proofs: bool=True) -> Optional[CiphertextBallotSelection]:
    "\n    Encrypt a specific `BallotSelection` in the context of a specific `BallotContest`\n\n    :param selection: the selection in the valid input form\n    :param selection_description: the `SelectionDescription` from the\n        `ContestDescription` which defines this selection's structure\n    :param elgamal_public_key: the public key (K) used to encrypt the ballot\n    :param crypto_extended_base_hash: the extended base hash of the election\n    :param nonce_seed: an `ElementModQ` used as a header to seed the `Nonce` generated for this selection.\n                 this value can be (or derived from) the BallotContest nonce, but no relationship is required\n    :param is_placeholder: specifies if this is a placeholder selection\n    :param should_verify_proofs: specify if the proofs should be verified prior to returning (default True)\n    "
    if (not selection.is_valid(selection_description.object_id)):
        log_warning(f'malformed input selection: {selection}')
        return None
    selection_description_hash = selection_description.crypto_hash()
    nonce_sequence = Nonces(selection_description_hash, nonce_seed)
    selection_nonce = nonce_sequence[selection_description.sequence_order]
    disjunctive_chaum_pedersen_nonce = next(iter(nonce_sequence))
    log_info(f': encrypt_selection: for {selection_description.object_id} hash: {selection_description_hash.to_hex()}')
    selection_representation = selection.vote
    elgamal_encryption = elgamal_encrypt(selection_representation, selection_nonce, elgamal_public_key)
    if (elgamal_encryption is None):
        return None
    encrypted_selection = make_ciphertext_ballot_selection(object_id=selection.object_id, description_hash=selection_description_hash, ciphertext=get_optional(elgamal_encryption), elgamal_public_key=elgamal_public_key, crypto_extended_base_hash=crypto_extended_base_hash, proof_seed=disjunctive_chaum_pedersen_nonce, selection_representation=selection_representation, is_placeholder_selection=is_placeholder, nonce=selection_nonce)
    if (encrypted_selection.proof is None):
        return None
    if (not should_verify_proofs):
        return encrypted_selection
    if encrypted_selection.is_valid_encryption(selection_description_hash, elgamal_public_key, crypto_extended_base_hash):
        return encrypted_selection
    log_warning(f'mismatching selection proof for selection {encrypted_selection.object_id}')
    return None