def enc_input_vector()

in src/ppxgboost/PPBooster.py [0:0]


def enc_input_vector(hash_key, ope, feature_set, input_vector, metadata):
    """
    Process the feature's name using hmac, then encrypts the neccessary values using OPE
    based on the feature set.
    :param metadata: encryption metadata containing min, max and affine transform
    :param hash_key: hmac hash key
    :param ope: ope object
    :param feature_set: feature set
    :param input_vector: input vector
    """
    # starts to encrypt using ope based on the feature set.

    feature_list = list(feature_set)
    enc_feature_list = list()

    # Process feature list first.
    for i in feature_list:
        enc_feature_list.append(hmac_msg(hash_key, i))

    # calls the hmac_feature method to hmac the feature name of the input vector.
    hmac_feature(hash_key, input_vector)

    # Dropping the columns not in the feature list
    for col in input_vector.columns:
        if col not in enc_feature_list:
            input_vector.drop(col, axis=1, inplace=True)

    for i, row in input_vector.iterrows():
        # Encrypts all the features in the input_vector
        for feature in list(input_vector.columns.values):
            if not math.isnan(row[feature]):

                noramlized_feature = metadata.affine_transform(row[feature])

                if noramlized_feature > MAX_NUM_OPE_ENC or noramlized_feature < 0:
                    raise Exception("Invalid input: input is out of range (0, " + MAX_NUM_OPE_ENC +
                                    "). The system cannot encrypt",
                                    noramlized_feature)

                ope_value = ope.encrypt(int(noramlized_feature))

                input_vector.at[i, feature] = ope_value