# OpenFHE-Python: BFV Threshold

**URL:** <https://openfhe.discourse.group/t/openfhe-python-bfv-threshold/1997>\
**Category:** Library Questions\
**Created:** [April 15, 2025, 11:09am UTC](https://openfhe.discourse.group/t/openfhe-python-bfv-threshold/1997 "2025-04-15T11:09:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![d9fdciar](https://avatars.discourse-cdn.com/v4/letter/d/ee59a6/32.png) [@d9fdciar](https://openfhe.discourse.group/u/d9fdciar)\
**Post date:** [April 15, 2025, 11:09am UTC](https://openfhe.discourse.group/t/openfhe-python-bfv-threshold/1997/1 "2025-04-15T11:09:47Z")

</div>

Hello,  
This issue is based on the example provided in the repository [openfhe-python/examples/pke/threshold-fhe-5p.py](https://github.com/openfheorg/openfhe-python/blob/a9d90e2c687aa84e2c33eabfa5fa1097801a0029/examples/pke/threshold-fhe-5p.py).

When I run the file, I get the supposedly correct output:

```auto
 Original Plaintext: 

( 1 2 3 4 5 6 5 4 3 2 1 ... )
( 1 0 0 1 1 ... )
( 2 2 3 4 5 6 7 8 9 10 ... )

 Resulting Fused Plaintext: 

( 4 4 6 9 11 12 12 12 12 12 1 ... )

 Resulting Fused Plaintext after Multiplication of plaintexts 1 and 3: 

( 1 32 243 1024 3125 7776 3125 1024 243 32 1 ... )

 Fused result after the Summation of ciphertext 3: 

( 56 54 52 49 45 40 34 27 19 10 ... )

```

Then, I did the following modifications :

- parameters.SetThresholdNumOfParties(5) → parameters.SetThresholdNumOfParties(3)
- I only used the first 3 (out of 5) partial decrypts of each list used as input of _MultipartyDecryptFusion_,

I obtained the following output:

```auto

 Original Plaintext: 

( 1 2 3 4 5 6 5 4 3 2 1 ... )
( 1 0 0 1 1 ... )
( 2 2 3 4 5 6 7 8 9 10 ... )

 Resulting Fused Plaintext: 

( 4618 -24943 18873 2235 21991 -6427 -28758 2949 6309 -20429 -30074 -14833 ... )

 Resulting Fused Plaintext after Multiplication of plaintexts 1 and 3: 

( -13584 12354 6146 -474 20337 6535 -32265 7222 -28725 -30276 -17296 -26837 ... )

 Fused result after the Summation of ciphertext 3: 

( 13735 2239 -21315 14559 -13415 5429 27787 27981 20517 17689 -30053 5278 ... )

```

Edit : Using the first 4 elements of each list, I get the following:

```auto
 Original Plaintext: 

( 1 2 3 4 5 6 5 4 3 2 1 ... )
( 1 0 0 1 1 ... )
( 2 2 3 4 5 6 7 8 9 10 ... )

 Resulting Fused Plaintext: 

( -28553 21134 30056 11726 30949 4400 -31747 29014 -6299 31757 -15025 18083 ... )

 Resulting Fused Plaintext after Multiplication of plaintexts 1 and 3: 

( -9813 21457 30218 17305 -26711 -25069 -15120 -26709 -32198 28855 14267 -4523 ... )

 Fused result after the Summation of ciphertext 3: 

( 4833 14130 20550 -23265 -17613 5225 10538 17882 24686 -32048 28714 30208 ... )

```

Is it the expected behavior ? If yes, I would greatly appreciate an explanation.

Sincerely,

---

<div class="post-metadata">

**Author:** ![andreea.alexandru](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/andreea.alexandru/32/378_2.png) [@andreea.alexandru](https://openfhe.discourse.group/u/andreea.alexandru)\
**Post date:** [April 15, 2025, 9:07pm UTC](https://openfhe.discourse.group/t/openfhe-python-bfv-threshold/1997/2 "2025-04-15T21:07:51Z")

</div>

SetThresholdNumOfParties expects the total number of parties and is used to generate the parameters. For a t-out-of-n setting where t \< n, please see the description of [threshold decryption with aborts](https://github.com/openfheorg/openfhe-development/blob/main/docs/static_docs/Threshold_FHE.md#threshold-decryption-with-aborts) and a small example [here](https://github.com/openfheorg/openfhe-development/blob/main/src/pke/unittest/UnitTestMultiparty.cpp#L790) to understand the kind of capability currently implemented in OpenFHE.

---

<div class="post-metadata">

**Author:** ![d9fdciar](https://avatars.discourse-cdn.com/v4/letter/d/ee59a6/32.png) [@d9fdciar](https://openfhe.discourse.group/u/d9fdciar)\
**Post date:** [April 16, 2025, 4:14pm UTC](https://openfhe.discourse.group/t/openfhe-python-bfv-threshold/1997/3 "2025-04-16T16:14:28Z")

</div>

Hello,  
Looks like I misunderstood the method `SetThresholdNumOfParties`, thank you for linking [this](https://github.com/openfheorg/openfhe-development/blob/main/docs/static_docs/Threshold_FHE.md#threshold-decryption-with-aborts).

Is it possible to do it with the Python wrapper ?  
I see no mention of `ShareKeys` and `RecoverSharedKey` in [Welcome to OpenFHE - Python’s documentation! — openfhe-python 0.8.0 documentation](https://openfheorg.github.io/openfhe-python/html/index.html) or when creating contexts.
