# KeySwitch keys reuse & optimization for hybrid key switching

**URL:** <https://openfhe.discourse.group/t/keyswitch-keys-reuse-optimization-for-hybrid-key-switching/471>\
**Category:** Library Questions\
**Created:** [April 18, 2023, 9:09am UTC](https://openfhe.discourse.group/t/keyswitch-keys-reuse-optimization-for-hybrid-key-switching/471 "2023-04-18T09:09:39Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Sijia](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@Sijia](https://openfhe.discourse.group/u/Sijia)\
**Post date:** [April 20, 2023, 2:01am UTC](https://openfhe.discourse.group/t/keyswitch-keys-reuse-optimization-for-hybrid-key-switching/471/5 "2023-04-20T02:01:50Z")

</div>

Thank you for the reply.

That is exactly what I’m talking about. But your code in OpenFHE seems to be the opposite, that is computing

Sum{(Q\_hat\_inverse)DigitDecompose(c2), KeySwitchKey[(Q\_hat)Ps2]}

See [openfhe-development/keyswitch-hybrid.cpp at 122f470e0dbf94688051ab852131ccc5d26be934 · openfheorg/openfhe-development · GitHub](https://github.com/openfheorg/openfhe-development/blob/122f470e0dbf94688051ab852131ccc5d26be934/src/pke/lib/keyswitch/keyswitch-hybrid.cpp#L108) for Key-Switch Keys generation with multiplication by _PartQHatModq_

And [openfhe-development/keyswitch-hybrid.cpp at 122f470e0dbf94688051ab852131ccc5d26be934 · openfheorg/openfhe-development · GitHub](https://github.com/openfheorg/openfhe-development/blob/122f470e0dbf94688051ab852131ccc5d26be934/src/pke/lib/keyswitch/keyswitch-hybrid.cpp#L463) for digit extraction in OpenFHE. It seems that the multiplication by _QHatInvModq_ is executed when every digit is extracted from c2.

---

_[View the full topic](https://openfhe.discourse.group/t/keyswitch-keys-reuse-optimization-for-hybrid-key-switching/471)._
