mirror of
https://github.com/saymrwulf/swisspost-evoting-go-poc.git
synced 2026-05-14 20:58:03 +00:00
Proof-of-concept reimplementation of the Swiss Post e-voting cryptographic protocol in Go. Single binary, 52 source files, 2 dependencies. Covers ElGamal encryption, Bayer-Groth verifiable shuffles, zero-knowledge proofs, return codes, and a full election ceremony demo.
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package protocol
|
|
|
|
import (
|
|
"fmt"
|
|
"math/rand"
|
|
)
|
|
|
|
// RunDemoElection runs a complete election ceremony with the given parameters.
|
|
func RunDemoElection(numVoters, numOptions int) {
|
|
fmt.Println("========================================")
|
|
fmt.Println(" Swiss Post E-Voting Protocol PoC (Go)")
|
|
fmt.Println("========================================")
|
|
fmt.Printf(" Voters: %d, Options: %d, CCs: 4\n", numVoters, numOptions)
|
|
fmt.Println()
|
|
|
|
// Phase 1: Setup
|
|
fmt.Println("--- SETUP PHASE ---")
|
|
cfg := DefaultConfig(numVoters, numOptions)
|
|
fmt.Printf(" Group: %d-bit safe prime\n", cfg.Group.Q().BitLen())
|
|
event := Setup(cfg)
|
|
fmt.Printf(" Generated %d voting cards\n", numVoters)
|
|
fmt.Printf(" Mapping table: %d entries\n", event.MappingTable.Size())
|
|
fmt.Println(" Setup complete.")
|
|
|
|
// Phase 2: Voting
|
|
fmt.Println("\n--- VOTING PHASE ---")
|
|
for v := 0; v < numVoters; v++ {
|
|
// Randomly select 1 option for each voter
|
|
selected := []int{rand.Intn(numOptions)}
|
|
CastVote(event, v, selected)
|
|
}
|
|
fmt.Printf(" All %d votes cast.\n", numVoters)
|
|
|
|
// Phase 3: Tally
|
|
Tally(event)
|
|
|
|
// Phase 4: Verify
|
|
VerifyTally(event)
|
|
}
|