swisspost-evoting-go-poc/pkg/returncodes/decode.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

28 lines
596 B
Go

package returncodes
import (
"math/big"
)
// DecodeVote factorizes a vote product back into the indices of selected options.
func DecodeVote(product *big.Int, primes []*big.Int) []int {
remaining := new(big.Int).Set(product)
var selected []int
for idx, p := range primes {
for {
quo, rem := new(big.Int).DivMod(remaining, p, new(big.Int))
if rem.Sign() == 0 {
selected = append(selected, idx)
remaining = quo
} else {
break
}
}
}
if remaining.Cmp(big.NewInt(1)) != 0 {
panic("factorization failed: remaining = " + remaining.String())
}
return selected
}