# How to print coefficients of CKKS private key

**URL:** <https://openfhe.discourse.group/t/how-to-print-coefficients-of-ckks-private-key/320>\
**Category:** Library Questions\
**Created:** [January 26, 2023, 12:22pm UTC](https://openfhe.discourse.group/t/how-to-print-coefficients-of-ckks-private-key/320 "2023-01-26T12:22:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hilder](https://avatars.discourse-cdn.com/v4/letter/h/e95f7d/32.png) [@hilder](https://openfhe.discourse.group/u/hilder)\
**Post date:** [January 26, 2023, 12:22pm UTC](https://openfhe.discourse.group/t/how-to-print-coefficients-of-ckks-private-key/320/1 "2023-01-26T12:22:00Z")

</div>

I know that in CKKS (well, the same holds for BGV, FV, etc) the secret key is just a polynomial in \mathbb{Z}[X] / \langle X^N + 1 \rangle, that is, integer coefficients and degree smaller than N. Moreover, the coefficients are generally small (belonging to the set {-1, 0, 1} or following a discrete Gaussian with small variance).

Thus, I would like to print these coefficients.

If I try

```auto
CryptoContext<DCRTPoly> cc = GenCryptoContext(parameters);
auto keys = cc->KeyGen();
std::cout << "Secret key: " << keys.secretKey << std::endl;

```

it just prints some memory address.

I also tried to use the methods defined in [privatekey.h](https://github.com/openfheorg/openfhe-development/blob/2c7d2bb090ea1f1bd7b7b15f8fcfcf294b94ab16/src/pke/include/key/privatekey.h), but this gives me compilation errors.

For example, trying `keys.secretKey.GetPrivateElement()` produces the error message

> error: ‘lbcrypto::PrivateKey\<lbcrypto::DCRTPolyImpl\<bigintdyn::mubintvec\<bigintdyn::ubint \> \> \> {aka class std::shared\_ptr\<lbcrypto::PrivateKeyImpl\<lbcrypto::DCRTPolyImpl\<bigintdyn::mubintvec\<bigintdyn::ubint \> \> \> \>}’ has no member named ‘GetPrivateElement’

---

<div class="post-metadata">

**Author:** ![iquah](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/iquah/32/8_2.png) [@iquah](https://openfhe.discourse.group/u/iquah)\
**Post date:** [January 26, 2023, 5:46pm UTC](https://openfhe.discourse.group/t/how-to-print-coefficients-of-ckks-private-key/320/2 "2023-01-26T17:46:40Z")

</div>

@hilder

I’ve modified your question to include `LaTeX` typesetting. Do LMK if that changes the nature of the question

---

<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:** [January 27, 2023, 7:31pm UTC](https://openfhe.discourse.group/t/how-to-print-coefficients-of-ckks-private-key/320/3 "2023-01-27T19:31:42Z")

</div>

`keys.secretKey` is an `std::shared_ptr`. Use the line below instead.

```auto
std::cout << "Secret key: " << keys.secretKey->GetPrivateElement() << std::endl;

```

---

<div class="post-metadata">

**Author:** ![hilder](https://avatars.discourse-cdn.com/v4/letter/h/e95f7d/32.png) [@hilder](https://openfhe.discourse.group/u/hilder)\
**Post date:** [January 31, 2023, 2:50pm UTC](https://openfhe.discourse.group/t/how-to-print-coefficients-of-ckks-private-key/320/4 "2023-01-31T14:50:59Z")

</div>

Thank you! So, this gives me access to the secret key in double-CRT representation and I could print the coefficients using the method CRTInterpolate().

```auto
const DCRTPoly& ckks_sk = keys.secretKey->GetPrivateElement();
std::cout << ckks_sk.CRTInterpolate() << std::endl;

```
