Esempio n. 1
0
 public static BigInteger Encrypt(int val, PublicKey publicKey)
 {
     BigInteger core = 0;
     var r = RandomNumberGenerator.Create();
     byte[] randomBuff = new byte[1];
     for(int i = 0; i < publicKey.KeyParts.Length; i++)
     {
         r.GetBytes(randomBuff);
         if(i == 0 || randomBuff[0] % 2 == 1)
             core = core + publicKey.KeyParts[i];
     }
     r.GetNonZeroBytes(randomBuff);
     return core + (publicKey.MaxNum * randomBuff[0]) + val;
 }
Esempio n. 2
0
 private static BigInteger Encrypt(int m, PublicKey publicKey)
 {
     BigInteger b = 0;
     var r = RandomNumberGenerator.Create();
     for(int i = 0; i < publicKey.KeyParts.Length; i++)
     {
         byte[] bb = new byte[1];
         r.GetBytes(bb);
         var random = bb[0]%2;
         Console.Write(random);
         if(i == 0 || random == 1)
             b = b + publicKey.KeyParts[i];
     }
     Console.WriteLine();
     return b + m;
 }
Esempio n. 3
0
 public static BigInteger[] EncryptVector(int[] vector, PublicKey publicKey)
 {
     return vector.Select(i => Encrypt(i, publicKey)).ToArray();
 }
Esempio n. 4
0
 private static void Vote(string host, KeyValuePair<User, int[]>[] voters, Guid id, PublicKey publicKey)
 {
     log.Info("Voting in parallel...");
     var candidateTasks = voters.Select(kvp => ElectroClient.VoteAsync(host, Program.PORT, kvp.Key.Cookies, id, HomoCrypto.EncryptVector(kvp.Value, publicKey))).ToArray();
     try
     {
         Task.WaitAll();
         log.InfoFormat("Voted by {0} users", voters.Length);
     }
     catch(Exception e)
     {
         throw new ServiceException(ExitCode.DOWN, string.Format("Failed to vote by {0} users in parallel: {1}", candidateTasks.Length, e));
     }
 }