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.
28 lines
596 B
Go
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
|
|
}
|