def testStaticPrivateKeyConstructor(self): public_key, private_key = paillier.generate_paillier_keypair() p = private_key.p q = private_key.q private_key_from_static = PaillierPrivateKey.from_totient(public_key, (p-1) * (q-1)) c = public_key.encrypt(4242) self.assertEqual(private_key, private_key_from_static, "The private keys should be the same.") self.assertEqual(private_key_from_static.decrypt(c), 4242, "Result of the decryption should be 4242")
def calcualte_sigmoid_and_decrypt_result(private_key: pl.PaillierPrivateKey, pre_prediction_results): ''' Function to produce the prediction output. Args: private_key: PaillierPrivateKey object. pre_prediction_results: numpy array obtained from pre_prediction function. Returns: Two numpy arrays. The first one stores sigmoid value of every predicting sample. The second one stores the prediction class label of each predicting sample. ''' output = np.empty(pre_prediction_results.shape, dtype=float) output_class = np.empty(pre_prediction_results.shape, dtype=int) for i in range(pre_prediction_results.size): output[i] = simple_sigmoid(private_key.decrypt(pre_prediction_results[i])) output_class[i] = 1 if output[i] >= 0.5 else 0 return output, output_class
def testPrivateKeyEquality(self): pk = PaillierPublicKey(2537) p1 = PaillierPrivateKey(pk, 43, 59) p2 = PaillierPrivateKey(pk, 59, 43) self.assertEqual(p1, p2, "These private keys should be equal")