// Add takes an arbitrary number of cyphertexts and returns one that encodes
// their sum.
//
// It's possible because Paillier is a homomorphic encryption scheme, where
// the product of two ciphertexts will decrypt to the sum of their corresponding
// plaintexts:
//
// D( (E(m1) * E(m2) mod n^2) ) = m1 + m2 mod n
Add takes an arbitrary number of cyphertexts and returns one that encodes
their sum.

It's possible because Paillier is a homomorphic encryption scheme, where
the product of two ciphertexts will decrypt to the sum of their corresponding
plaintexts.


// Add takes an arbitrary number of cyphertexts and returns one that encodes // their sum . // // It ' s possible because Paillier is a homomorphic encryption scheme where // the product of two ciphertexts will decrypt to the sum of their corresponding // plaintexts : // // D ( ( E ( m1 ) * E ( m2 ) mod n^2 ) ) = m1 + m2 mod n
func (pk *PublicKey) Add(cypher ...*Cypher) *Cypher {
	accumulator := big.NewInt(1)
	for _, c := range cypher {
		accumulator = new(big.Int).Mod(
			new(big.Int).Mul(accumulator, c.C),
			pk.GetNSquare(),
		)
	}
	return &Cypher{
		C: accumulator,
	}
}
func ( pk * PublicKey ) Add ( cypher ... * Cypher ) * Cypher { accumulator := big . NewInt ( 1 ) for _ , c := range cypher { accumulator = new ( big . Int ) . Mod ( new ( big . Int ) . Mul ( accumulator , c . C ) , pk . GetNSquare ( ) , ) } return & Cypher { C : accumulator , } }
Add takes an arbitrary number of cyphertexts and returns one that encodes
their sum.
Add takes an arbitrary number of cyphertexts and returns one that encodes their sum .