This is a secure, verifiable voting system implementation using homomorphic encryption. The system ensures voter privacy and verifiability while allowing votes to be tallied without decrypting individual ballots.
- Homomorphic encryption using the Paillier cryptosystem
- Secure ballot creation and verification
- Anonymous voting with voter receipts
- Homomorphic vote tallying
- Election lifecycle management
- Vote verification without compromising privacy
The system consists of several key components:
-
Cryptographic Layer (
pkg/crypto/paillier.go
)- Implementation of the Paillier cryptosystem
- Key generation, encryption, and decryption
- Homomorphic addition of encrypted votes
-
Voting System (
pkg/voting/
)ballot.go
: Ballot creation and verificationelection.go
: Election management and vote tallying
- Homomorphic encryption ensures votes remain encrypted during tallying
- Voter anonymity through hashed voter IDs
- Verifiable voting receipts
- Prevention of double voting
- Secure key generation and management
- Go 1.20 or later
- Dependencies (managed via Go modules):
- github.com/stretchr/testify
- golang.org/x/crypto
- Clone the repository
- Install dependencies:
go mod download
go test ./...
// Create a new election
options := []string{"Option A", "Option B", "Option C"}
startTime := time.Now()
endTime := startTime.Add(24 * time.Hour)
election, err := voting.NewElection("Test Election", "Test Description", options, startTime, endTime)
if err != nil {
log.Fatal(err)
}
// Start the election
err = election.Start()
if err != nil {
log.Fatal(err)
}
// Cast a vote
ballot, err := election.Cast("voter1", 0)
if err != nil {
log.Fatal(err)
}
// Get voter receipt
receipt := ballot.GetVoterReceipt()
// End election and tally votes
err = election.End()
if err != nil {
log.Fatal(err)
}
results, err := election.TallyVotes()
if err != nil {
log.Fatal(err)
}
- Key Management: The system generates strong encryption keys, but proper key management in production is crucial.
- Voter Authentication: This implementation focuses on the cryptographic aspects; production systems should implement strong voter authentication.
- Network Security: When deploying, ensure all communications are encrypted using TLS.
- Audit Trail: Consider implementing additional audit mechanisms for production use.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.