Examples
OpenFHE provides the following examples which should provide the reader with a basic understanding of how to use the library for various purposes.
Page Contents
Boolean FHE
Boolean Fully Homomorphic Encryption Examples
At a high level:
boolean.cpp: GINX (CGGI) Bootstrapping:
bootstrapping as described in TFHE: Fast Fully Homomorphic Encryption over the Torus and in Bootstrapping in FHEWlike Cryptosystems
booleanap.cpp: AP (DM) Bootstrapping:
bootstrapping as described in FHEW: Bootstrapping Homomorphic Encryption in less than a second and in Bootstrapping in FHEWlike Cryptosystems
booleanlmkcdey.cpp: LMKCDEY Bootstrapping:
bootstrapping as described in Efficient FHEW Bootstrapping with Small Evaluation Keys, and Applications to Threshold Homomorphic Encryption
booleanserialbinary.cpp: Boolean Serialization:
serializing
CryptoContext
, various keys, and ciphertext to a file in binary format
booleanserialjson.cpp: Boolean Serialization  json:
serializing
CryptoContext
, various keys, and ciphertext to a file in json format
booleantruthtables.cpp: Boolean Truth Tables:
prints out the truth tables for all supported binary gates
evaldecomp.cpp: Eval Decomposition:
runs a homomorphic digit decomposition process on the input ciphertext
evalflooring.cpp: Eval Flooring:
rounds down the input ciphertext by certain number of bits
evalfunction.cpp: Eval Function:
evaluates a function f: Z_p > Z_p on the input ciphertext

evaluates the mostsignificant bit of the input ciphertext
Core

provides an example of parallelization in
OpenFHE
with OpenMP

provides an example of doing integer Gaussian sampling using OpenFHE samplers.
For more information on sampling, read sampling documentation
PKE  SIMD FHE
SIMD Fully Homomorphic Encryption Examples:
Basic Homomorphic Encryption
Demonstrates basic homomorphic encryption using the various schemes:
Simple Mathematical Operations and Serialization
Demonstrates the following mathematical operations on vectors of appropriate type (integers in the case of BGV and BFV, and real numbers in CKKS):
homomorphic additions,
homomorphic multiplications
homomorphic rotations
Additionally, we include the variants detailing how to do serializationdeserialization.
Schemes:
Advanced CKKS Usage
Demonstates advanced operations on realnumber vectors using CKKS
:
Highprecision CKKS
Rescaling (automatic and manual)
hybrid keyswitching
hoisting
Formats
Misc. Operations across Schemes

demonstrates use of
EvalRotate automorphism
for different schemes

demonstrates the process of taking the linear weighted sum of a vector of ciphertexts against a vector of plaintext data in the CKKS scheme

demonstrates an evaluation of a polynomial (power series) using
CKKS

demonstrates use of OpenFHE for encryption, reencryption and decryption of packed vector of binary data

shows several examples of threshold FHE in
BGVrns
,BFVrns
, andCKKSrns

shows example of threshold FHE with 5 parties in
BFVrns