> For the complete documentation index, see [llms.txt](https://ccc-23.gitbook.io/xin-yong-lian-bai-pi-shu/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ccc-23.gitbook.io/xin-yong-lian-bai-pi-shu/4.-xin-yong-zheng-ming-proof-of-credit/4.3-ji-suan-guo-cheng/4.3.1-tong-tai-jia-mi-yin-si-ji-suan.md).

# 4.3.1 同态加密隐私计算

<figure><img src="https://2156172882-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSNrnwfUrPu9j3qCvu4gP%2Fuploads%2F2ryVruoNvt9XBm7mSjfr%2F%E5%9B%BE%E7%89%874.png?alt=media&amp;token=59fc35fb-8a69-4b2a-b482-6b50df8fe58f" alt=""><figcaption><p>图4. 同态加密流程图</p></figcaption></figure>

代码示例：

```
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())
```
