pip install to a working encrypted NAND
gate in under five minutes. No account, no API key, all local.
What you’ll build
A program that:- Generates a fresh FHE keypair locally.
- Encrypts two boolean bits.
- Computes
NANDon the encrypted bits. - Decrypts the result and verifies it’s correct.
api.wavis.xyz. The server (or in this case, your local engine) never
sees the plaintext bits — only the ciphertexts.
Prerequisites
- Python 3.9+
- ~50 MB free disk
- A terminal
Step 1: Install
Step 2: Generate keys
keys object holds your secret key, public key, and evaluation key.
wv.keygen() takes ~5 seconds on the first call (CPU-bound polynomial
expansion); subsequent calls are instant due to caching.
Step 3: Encrypt
Ciphertext is ~2 KB regardless of which bit it encrypts. From this
point on, the bits are computationally indistinguishable from random under
RLWE hardness.
Step 4: Compute on ciphertexts
keys.nand() performs a TFHE gate bootstrap on the two
ciphertexts. It takes ~14 ms on a modern CPU (fast_128 preset) and
returns a fresh ciphertext encrypting NAND(false, true) = true.
Crucially, no plaintext was reconstructed during this step. The
operation manipulates the ciphertexts directly.
Step 5: Decrypt
Full program
Save asquickstart.py:
What you actually proved
You just executed a computation where:- Step 2 (encrypt) used the secret key.
- Step 3 (compute) did not use the secret key — it used only the evaluation key.
- Step 4 (decrypt) used the secret key.
Try the full gate set
Common questions
Q: How do I make this run on a server? A: See Server Mode Example. The pattern is: clientkeygen() + encrypt(), upload eval-key + ciphertexts, server
nand(), return ciphertext, client decrypt().
Q: How fast is this?
A: fast_128 ≈ 14 ms/gate, standard_128 ≈ 32 ms/gate on CPU. With
batching on a local GPU (BYO GPU): 5.2 ms/gate. See
Performance.
Q: Is this actually 128-bit secure?
A: Yes. The fast_128 preset uses TLWE n=636 with conservative noise
parameters. See Security Model for the math.
Q: What about more complex circuits?
A: NAND is universal — you can build any boolean circuit by composing
gates. See Full Adder for a 1-bit adder example.
Next Steps
Full Adder
Build a 1-bit adder from NAND gates
Server Mode
Move computation to api.wavis.xyz