A secure voting system that leverages Paillier Homomorphic Encryption for private and secure vote tallying. The project is designed to ensure votes are encrypted on the client side and only decrypted during result tallying, enhancing privacy and preventing tampering.
- Homomorphic Encryption: Votes are encrypted on the frontend, preventing unauthorized access to vote data.
- Secure Tallying: Encrypted votes are aggregated directly without decryption, ensuring security during counting.
- JSON Storage: Votes are stored in encrypted form and persist across server restarts.
- CORS Enabled: Frontend and Backend communicate seamlessly across different ports.
voting\_homomorphic\_encryption/
│
├── backend/
│ ├── app.py # Flask server to handle API requests
│ ├── paillier\_crypto.py # Handles Paillier Encryption and decryption logic
│ ├── vote\_data.json # Persistent storage of encrypted votes
│ └── public\_key.json # Public key for FE encryption
│
├── frontend/
│ ├── index.html # Main HTML structure
│ ├── main.js # Logic for encryption and API communication
│ └── style.css # Styling for the voting interface
│
├── README.md # Project documentation
├── requirements.txt # List of dependencies
└── .env # Environment variables (if needed)
git clone https://github.com/yourusername/voting_homomorphic_encryption.git
cd voting_homomorphic_encryptioncd backend
pip install -r requirements.txt
python app.py- Server runs on
http://localhost:5000
cd frontend
# Open index.html in your browser or use Live Server extension on VSCode- Frontend accessible at
http://127.0.0.1:5500/index.html
- Public Key Fetching: Frontend fetches the public key from Flask server.
- Vote Encryption: When a vote is submitted, it's encrypted using the Paillier method directly on the frontend.
- Vote Submission: The encrypted vote is sent to the backend.
- Homomorphic Addition: Encrypted votes are added directly without decryption.
- Result Decryption: Only the backend with the private key can decrypt and tally votes.
| Method | Endpoint | Description |
|---|---|---|
GET |
/public_key |
Fetches the public key for encryption |
POST |
/vote |
Submits an encrypted vote |
GET |
/result |
Retrieves the current vote tally |
- Flask
- Flask-CORS
- phe (Paillier Homomorphic Encryption)
- JSON
- OS
Install all dependencies using:
pip install -r requirements.txt- Homomorphic Encryption: Votes are encrypted and only decrypted when tallying.
- CORS Protection: Only requests from the frontend origin are accepted.
- Persistent Storage: Encrypted votes are saved in
vote_data.jsonto maintain state.
- Realtime vote count update.
- User authentication for verified voting.
- Encrypted proof of vote for transparency.
- Admin dashboard for vote monitoring.
- Paillier Encryption for enabling secure homomorphic operations.
- Flask for lightweight backend API.
- Flask-CORS for seamless FE-BE communication.
---
## 🎯 **Tiếp theo bạn muốn mình làm gì?**
1. Tạo sơ đồ luồng dữ liệu từ Frontend ➔ Backend ➔ JSON Store?
2. Hoàn chỉnh code Frontend + Backend để gửi lên GitHub?
3. Làm slide trình bày ấn tượng cho báo cáo?
Bạn muốn mình bắt đầu với cái nào trước?