swisspost-evoting-go-poc/pkg/returncodes/encode.go
saymrwulf e8b6f30871 Swiss Post E-Voting Go PoC
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.
2026-02-13 19:53:09 +01:00

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
}