# 4.3.1 Homomorphic Encryption

Flowchart:

<figure><img src="https://2943625670-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FB3H0rG85AA74gZwSfUP6%2Fuploads%2FCrzbvmNiBUX1OZMhCwNz%2Fp4.png?alt=media&#x26;token=ba4c435f-2739-4313-ae94-9cf38a82b886" alt=""><figcaption><p>Figure 4. Homomorphic Encryption Flowchart</p></figcaption></figure>

Code example:

```
from seal import EncryptionParameters, SEALContext, KeyGenerator, Encryptor, Decryptor, Plaintext, Ciphertext

# Set homomorphic encryption parameters
params = EncryptionParameters()
params.set_poly_modulus("1x^4096 + 1")
params.set_coeff_modulus(seal.coeff_modulus_128(4096))
params.set_plain_modulus(1 << 8)

# Create homomorphic encryption context
context = SEALContext(params)

# Create key generator
keygen = KeyGenerator(context)
public_key = keygen.public_key()
secret_key = keygen.secret_key()

# Create encryptor and decryptor 
encryptor = Encryptor(context, public_key)
decryptor = Decryptor(context, secret_key)

# Encrypt Data
plaintext = Plaintext("42")
ciphertext = Ciphertext()
encryptor.encrypt(plaintext, ciphertext)

# Perform homomorphic addition
addend = Plaintext("15")
encryptor.encrypt(addend, ciphertext)
ciphertext += ciphertext

# Perform homomorphic multiplication
multiplier = Plaintext("7")
encryptor.encrypt(multiplier, ciphertext)
ciphertext *= ciphertext

# Decrypted Result
result = Plaintext()
decryptor.decrypt(ciphertext, result)
print("Decrypted result:", result.to_string())
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ccc-23.gitbook.io/credit-chain-coin-white-paper/4.proof-of-credit/4.3-computing-process/4.3.1-homomorphic-encryption.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
