Skip to content

YuD1405/Voting_Homomorphic-Encryption

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🗳️ Voting System with Homomorphic Encryption

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.


📌 Features

  • 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.

🗂️ Project Structure


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)


🚀 Getting Started

1️⃣ Clone the repository

git clone https://github.com/yourusername/voting_homomorphic_encryption.git
cd voting_homomorphic_encryption

2️⃣ Set up Backend

cd backend
pip install -r requirements.txt
python app.py
  • Server runs on http://localhost:5000

3️⃣ Set up Frontend

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

🔐 Encryption Flow

  1. Public Key Fetching: Frontend fetches the public key from Flask server.
  2. Vote Encryption: When a vote is submitted, it's encrypted using the Paillier method directly on the frontend.
  3. Vote Submission: The encrypted vote is sent to the backend.
  4. Homomorphic Addition: Encrypted votes are added directly without decryption.
  5. Result Decryption: Only the backend with the private key can decrypt and tally votes.

🔄 API Endpoints

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

📦 Dependencies

  • Flask
  • Flask-CORS
  • phe (Paillier Homomorphic Encryption)
  • JSON
  • OS

Install all dependencies using:

pip install -r requirements.txt

🛡️ Security Considerations

  • 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.json to maintain state.

Future Improvements

  • Realtime vote count update.
  • User authentication for verified voting.
  • Encrypted proof of vote for transparency.
  • Admin dashboard for vote monitoring.

🤝 Acknowledgements

  • 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?

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published