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.
27 lines
821 B
Go
27 lines
821 B
Go
package returncodes
|
|
|
|
import (
|
|
"math/big"
|
|
|
|
emath "github.com/user/evote/pkg/math"
|
|
)
|
|
|
|
// EncodeVote encodes a set of selected option indices as a product of small primes.
|
|
// Each option index maps to a small prime; the vote is the product of selected primes.
|
|
func EncodeVote(selectedIndices []int, primes []*big.Int) *big.Int {
|
|
result := big.NewInt(1)
|
|
for _, idx := range selectedIndices {
|
|
result.Mul(result, primes[idx])
|
|
}
|
|
return result
|
|
}
|
|
|
|
// EncodeVoteAsGqElement encodes a vote and returns it as a GqElement.
|
|
func EncodeVoteAsGqElement(selectedIndices []int, primes []*big.Int, group *emath.GqGroup) emath.GqElement {
|
|
product := EncodeVote(selectedIndices, primes)
|
|
elem, err := emath.NewGqElement(product, group)
|
|
if err != nil {
|
|
panic("encoded vote is not a group member: " + err.Error())
|
|
}
|
|
return elem
|
|
}
|