1 package civitas.common.encryptedchoice;
2
3 import org.springframework.beans.factory.annotation.Autowired;
4 import org.springframework.stereotype.Controller;
5
6 import civitas.common.VoteChoice;
7 import civitas.crypto.ciphertextlist.CiphertextList;
8 import civitas.crypto.oneoflreencryption.ConstructElGamal1OfLReencryption;
9 import civitas.crypto.oneoflreencryption.ElGamal1OfLReencryption;
10 import civitas.crypto.publickey.ElGamalPublicKey;
11 import civitas.crypto.reencryptfactor.ElGamalReencryptFactor;
12 import civitas.crypto.reencryptfactor.GenerateElGamalReencryptFactor;
13
14 @Controller
15 public class EncryptChoice {
16
17 @Autowired
18 ConstructElGamal1OfLReencryption constructElGamal1OfLReencryption;
19
20 @Autowired
21 GenerateElGamalReencryptFactor generateElGamalReencryptFactor;
22
23 public EncryptedChoice apply(
24 final ElGamalPublicKey key, final CiphertextList ciphertexts, final VoteChoice[] cbMatrix, final int pos) {
25 VoteChoice choice = cbMatrix[pos];
26 ElGamalReencryptFactor encChoiceFactor = generateElGamalReencryptFactor.apply(key.params);
27 ElGamal1OfLReencryption encChoice =
28 constructElGamal1OfLReencryption.apply(key, ciphertexts, choice.ordinal(), encChoiceFactor);
29 return new EncryptedChoice(encChoiceFactor, encChoice);
30 }
31 }