# About rotation key

**URL:** <https://openfhe.discourse.group/t/about-rotation-key/721>\
**Category:** FHE Questions\
**Tags:** questions\
**Created:** [July 27, 2023, 3:04am UTC](https://openfhe.discourse.group/t/about-rotation-key/721 "2023-07-27T03:04:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kenan](https://avatars.discourse-cdn.com/v4/letter/k/e495f1/32.png) [@kenan](https://openfhe.discourse.group/u/kenan)\
**Post date:** [July 27, 2023, 3:04am UTC](https://openfhe.discourse.group/t/about-rotation-key/721/1 "2023-07-27T03:04:45Z")

</div>

I have a place where I need to rotate, but each rotation index is different. Do I need to generate all the required indexes at once when generating the rotation key? However, this will cause the rotation key to be too large, or will I generate the rotation key again based on the different indexes

---

<div class="post-metadata">

**Author:** ![Caesar](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/caesar/32/63_2.png) [@Caesar](https://openfhe.discourse.group/u/Caesar)\
**Post date:** [July 27, 2023, 6:16pm UTC](https://openfhe.discourse.group/t/about-rotation-key/721/2 "2023-07-27T18:16:58Z")

</div>

The rotation key for each specific rotation index should be generated before invoking the rotation by that index.

You can compose multiple rotations to reduce the number of rotation keys, but this may come at the cost of performance.

```auto
Rotate(x,2)=Rotate(Rotate(x,1),1)

```

---

<div class="post-metadata">

**Author:** ![kenan](https://avatars.discourse-cdn.com/v4/letter/k/e495f1/32.png) [@kenan](https://openfhe.discourse.group/u/kenan)\
**Post date:** [July 28, 2023, 2:54am UTC](https://openfhe.discourse.group/t/about-rotation-key/721/3 "2023-07-28T02:54:40Z")

</div>

If I need to use an index from 0 to 1000, how should I compose it?

---

<div class="post-metadata">

**Author:** ![Caesar](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/caesar/32/63_2.png) [@Caesar](https://openfhe.discourse.group/u/Caesar)\
**Post date:** [July 28, 2023, 3:28pm UTC](https://openfhe.discourse.group/t/about-rotation-key/721/4 "2023-07-28T15:28:37Z")

</div>

You can do something like this:

1. binary-decompose 1000 into: 2^3 + 2^5 + 2^6 + 2^7 + 2^8 + 2^9
2. generate rotations keys for: 2^3, 2^5, 2^6, 2^7, 2^8, 2^9
3. compose your rotations as the following:  
`Rotate(x,1000) = Rotate( Rotate( Rotate(Rotate(Rotate(Rotate(x, 2^3), 2^5), 2^6), 2^7), 2^8), 2^9);`

So you can do it with 6 Rotations and using 6 different keys. You can consider other base decompositions which might require less number of keys. For instance, in base 3 (1000=1 + 3^3 + 3^5 + 3^6), you would need 4 rotation indices, and in base 5 (1000=3\cdot5^3 + 1\cdot5^4), you would need only 2 rotation indices.
