xtrace_sdk.crypto.paillier_lookup_client ======================================== .. py:module:: xtrace_sdk.crypto.paillier_lookup_client Classes ------- .. autoapisummary:: xtrace_sdk.crypto.paillier_lookup_client.PaillierLookupClient Module Contents --------------- .. py:class:: PaillierLookupClient(embed_len = 512, key_len = 1024, alpha_len = 50, skip_key_gen = False) Bases: :py:obj:`xtrace_sdk.crypto.hamming_client_base.HammingClientBase` This is an implementation of paillier cryptography system optimized for caculating hamming distance between two binary vectors. .. py:attribute:: alpha_len :value: 50 .. py:attribute:: key_len :value: 1024 .. py:attribute:: chunk_len :value: 2048 .. py:attribute:: embed_len :value: 512 .. py:method:: stringify_pk() stringify public key for networking/storage purpose :return: stringified public key :rtype: str .. py:method:: stringify_sk() stringify secret key for networking/storage purpose :return: stringified secret key :rtype: str .. py:method:: stringify_config() stringify crypto context for networking/storage purpose :return: stringified crypto context :rtype: str .. py:method:: load_stringified_keys(pk, sk) load stringified keys :param str_keys: stringified keys :type str_keys: str .. py:method:: load_config(config) load crypto context from a json string :param context: the json string containing crypto context :type context: str .. py:method:: id2power(id_) helper: return chunk id & corresponding power of 2 given an id in the original padded arr :param id_: id_ of an entry in an embedding vector :type id_: int .. py:method:: encrypt(embd) This function implements the encryption scheme on embedding vectors that needs to be run on client side. :param embd: the embedding vector to be encrypted :type embd: iterable[0,1] :return: return a list of length chunk_num contaning PaillierEncryptedNumber :rtype: PaillierEncryptedNumber .. py:method:: encode_hamming_client(ct1, ct2) This function is called from client side. :param embd1: ciphertext of embedding 1 :type embd1: PaillierEncryptedNumber :param embd2: ciphertext of embedding 2 :type embd2: PaillierEncryptedNumber :return: return a list of length chunk_num contaning large int :rtype: PaillierEncryptedNumber .. py:method:: encode_hamming_server(ct1, ct2, pk) :staticmethod: This function is called from server side. :param ct1: ciphertext of embedding 1 :type ct1: PaillierEncryptedNumber :param ct2: ciphertext of embedding 2 :type ct2: PaillierEncryptedNumber :param pk: public key :type pk: PaillierPublicKey :return: return a list of length chunk_num contaning large int :rtype: PaillierEncryptedNumber .. py:method:: decode_hamming_client(cipher) Given a PaillierEncryptedNumber returned from server, calculate the hamming distance encoded :param cipher: a cipher regturned by server which encodes the hamming distance between two encrypted embeddings :type cipher: PaillierEncryptedNumber :return: hamming distance encoded by cipher :rtype: int