# EvalAutomorphismKeyGen ModInverse index

**URL:** <https://openfhe.discourse.group/t/evalautomorphismkeygen-modinverse-index/1801>\
**Category:** Library Questions\
**Created:** [December 23, 2024, 5:41am UTC](https://openfhe.discourse.group/t/evalautomorphismkeygen-modinverse-index/1801 "2024-12-23T05:41:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhaoqiming](https://avatars.discourse-cdn.com/v4/letter/z/a5b964/32.png) [@zhaoqiming](https://openfhe.discourse.group/u/zhaoqiming)\
**Post date:** [December 23, 2024, 5:41am UTC](https://openfhe.discourse.group/t/evalautomorphismkeygen-modinverse-index/1801/1 "2024-12-23T05:41:22Z")

</div>

Hello, I don’t understand why compute ModInverse of index in EvalAutomorphismKeyGen.  
In SEAL, create\_galois\_keys use the galois\_elt of input to do apply\_galois\_ntt of secret\_key.

```auto
for (size_t i = 0; i < sz; ++i) {
        PrivateKey<Element> privateKeyPermuted = std::make_shared<PrivateKeyImpl<Element>>(cc);

        uint32_t index = NativeInteger(indexList[i]).ModInverse(2 * N).ConvertToInt();
        std::vector<uint32_t> vec(N);
        PrecomputeAutoMap(N, index, &vec);

        privateKeyPermuted->SetPrivateElement(s.AutomorphismTransform(index, vec));
        (*evalKeys)[indexList[i]] = algo->KeySwitchGen(privateKey, privateKeyPermuted);
    }

```

---

<div class="post-metadata">

**Author:** ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)\
**Post date:** [December 23, 2024, 10:26pm UTC](https://openfhe.discourse.group/t/evalautomorphismkeygen-modinverse-index/1801/2 "2024-12-23T22:26:45Z")

</div>

The double-hoisting optimization from [Efficient Bootstrapping for Approximate Homomorphic Encryption with Non-Sparse Keys](https://eprint.iacr.org/2020/1203) is used here (See Section 4.2 of the paper). It has no effect on efficiency for a single automorphism but is more efficient when multiple automorphisms for the same ciphertext are needed.
