示例#1
0
        public void UpdateSummaryPatch()
        {
            // Test is invalid now
            int slotCount = 4096;

            // Create the Test Data
            Random        rand       = new Random();
            List <double> list1      = new List <double>(slotCount);
            List <double> list2      = new List <double>(slotCount);
            List <double> resultGold = new List <double>(slotCount);

            for (int i = 0; i < slotCount; i++)
            {
                list1.Add((double)(rand.Next(0, 500)) / 10.0);
                list2.Add((double)(rand.Next(0, 500)) / 10.0);
                resultGold.Add(list1[i] + list2[i]);
            }

            // Create the Ciphertexts
            SEALWrapper sw          = new SEALWrapper(slotCount, true, false);
            String      list1base64 = sw.Encrypt(list1);
            String      list2base64 = sw.Encrypt(list2);

            // Perform the add with a new SEALWrapper to simulate the call from the server
            SEALWrapper serverSW = new SEALWrapper(slotCount);

            Assert.IsTrue(serverSW.AddCiphers(list1base64, list2base64));
            String resultBase64 = serverSW.getAdded();

            // Get the List result with the first SEALWrapper that has the keys still
            List <double> resultList = sw.Decrypt(resultBase64);

            // Test that the results match
            Assert.AreEqual(resultList.Count, resultGold.Count);
            for (int i = 0; i < slotCount; i++)
            {
                Assert.IsTrue(Math.Abs(resultList[i] - resultGold[i]) < 0.00001);
            }
        }
示例#2
0
        // Adds the two summary ciphers together
        public static string AddSummary(this SummaryItem summaryItem1, SummaryItem summaryItem2)
        {
            String resultBase64 = "";

            try
            {
                Trace.WriteLine("Start AddSummary ");

                SEALWrapper sw = new SEALWrapper(4096);
                sw.AddCiphers(summaryItem1.Summary, summaryItem2.Summary);
                resultBase64 = sw.getAdded();
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.TraceError("{%s} occurred while Adding Summary ", e);
            }

            Trace.WriteLine("End AddSummary ");

            // Convert to base64
            return(resultBase64);
        }