# LuxFHE Python Bindings

Python bindings for the Lux FHE (Fully Homomorphic Encryption) library.

## Installation

```bash
pip install luxfhe
```

## Requirements

- Python 3.9+
- LuxFHE shared library (libluxfhe.so/dylib/dll)

Set the `LUXFHE_LIBRARY` environment variable to point to the shared library, or install it to a standard location.

## Quick Start

```python
from luxfhe import Context, ParamSet

# Create context with 128-bit security
ctx = Context(ParamSet.PN10QP27)

# Generate keys
sk, pk, bsk = ctx.keygen_all()

# Create encryptor, decryptor, evaluator
enc = ctx.encryptor(sk)
dec = ctx.decryptor(sk)
eval = ctx.evaluator(bsk)

# Encrypt boolean values
ct_a = enc.encrypt(True)
ct_b = enc.encrypt(False)

# Perform homomorphic operations
ct_and = eval.and_gate(ct_a, ct_b)
ct_or = eval.or_gate(ct_a, ct_b)
ct_xor = eval.xor_gate(ct_a, ct_b)
ct_not = eval.not_gate(ct_a)

# Decrypt results
print(f"AND(True, False) = {dec.decrypt(ct_and)}")  # False
print(f"OR(True, False)  = {dec.decrypt(ct_or)}")   # True
print(f"XOR(True, False) = {dec.decrypt(ct_xor)}")  # True
print(f"NOT(True)        = {dec.decrypt(ct_not)}")  # False
```

## Parameter Sets

- `ParamSet.PN10QP27` - 128-bit security, good performance (recommended)
- `ParamSet.PN11QP54` - 128-bit security, higher precision

## Gates Available

### Basic Gates
- `not_gate(ct)` - NOT gate
- `and_gate(ct1, ct2)` - AND gate
- `or_gate(ct1, ct2)` - OR gate
- `xor_gate(ct1, ct2)` - XOR gate
- `nand_gate(ct1, ct2)` - NAND gate
- `nor_gate(ct1, ct2)` - NOR gate
- `xnor_gate(ct1, ct2)` - XNOR gate
- `mux(sel, ct_true, ct_false)` - Multiplexer

### Multi-Input Gates
- `and3(ct1, ct2, ct3)` - 3-input AND
- `or3(ct1, ct2, ct3)` - 3-input OR
- `majority(ct1, ct2, ct3)` - Majority (2 of 3)

## Integer Operations

```python
# Encrypt bytes
ct_a = enc.encrypt_byte(42)
ct_b = enc.encrypt_byte(10)

# Decrypt
result = dec.decrypt_byte(ct_a)
print(f"Decrypted: {result}")  # 42
```

## Serialization

```python
# Serialize ciphertext
data = ct_a.serialize()

# Save to file
with open("ciphertext.bin", "wb") as f:
    f.write(data)
```

## Error Handling

```python
from luxfhe import LuxFHEError

try:
    # Invalid operation
    enc.encrypt_byte(256)  # Out of range
except LuxFHEError as e:
    print(f"Error {e.code}: {e}")
```

## License

BSD-3-Clause - Copyright (c) 2025, Lux Industries Inc
