This repository provides a Python-based benchmark suite that compares ElGamal and CKKS (via TenSEAL) homomorphic encryption. It measures both execution time and memory usage for encrypting and combining large datasets of latitude-longitude coordinates.
-
ElGamal Encryption (using PyCryptodome).
-
CKKS (using TenSEAL) for efficient floating-point homomorphic operations.
-
Command-line prompt to run either:
- ElGamal only
- TenSEAL CKKS only
- Both, side by side
-
Performance metrics:
- Execution time (seconds)
- Memory usage (MB)
-
Plots comparing time and memory usage vs. input size.
- Python 3.8+ (tested with Python 3.9).
- pip or another package manager.
- Basic build tools (often required for TenSEAL).
-
Clone this repository (or download the ZIP):
git clone https://github.com/your-username/ElGamal-CKKS-Homomorphic-Comparison.git cd ElGamal-CKKS-Homomorphic-Comparison -
Create a virtual environment (recommended):
python -m venv venv source venv/bin/activate # On macOS/Linux # or on Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
Example
requirements.txt:psutil pycryptodome numpy pandas matplotlib tenseal
-
Update the file path to your dataset in the script:
FILE_PATH = "/path/to/allCountries.txt"
The file should be a TSV with latitude and longitude in columns 9 and 10.
-
Run the script:
python main.py
-
Choose a test method when prompted:
Choose method to test: 1 - ElGamal only 2 - TenSEAL CKKS only 3 - Both -
Results will be printed in the terminal and shown in a comparison plot.
-
"Failed to find enough qualifying primes"
TenSEAL could not find a suitable set of primes for the given parameters. Adjustcoeff_mod_bit_sizesor reducepoly_modulus_degree. -
"End of modulus switching chain reached"
You ran out of multiplicative depth. Add more primes (levels), reduce the global scale, or limit the number of multiplications.
MIT License
This project uses location data from the GeoNames dataset.
- Dataset URL: GeoNames All Countries
- Format: Tab-separated values (TSV), with latitude and longitude in columns 9 and 10.
- File:
allCountries.txt(included as a.zipfile alongside the code)
Make sure to extract allCountries.txt from the zip file and update the FILE_PATH in the script accordingly:
FILE_PATH = "/path/to/allCountries.txt"