示例#1
0
        static Numeric Test(BigInteger val, BigInteger[] patterns, int patternLen, SubdomainPrivacy sdp, double statdomProb, bool isAbnormal)
        {
            System.Diagnostics.Debug.Assert(patternLen <= Config.NumericBits);
            BigInteger mask = Numeric.oneMaskMap[patternLen];
            var        code =
                @"
            {
                int v = " + val + ((sdp == SubdomainPrivacy.None) ? "" :
                                   ((sdp == SubdomainPrivacy.STATDOM) ? (@"[0, " + ((BigInteger.One << (Config.NumericBits - 1)) - 1) + @", " + statdomProb + @"]") :
                                    @"[0, " + ((BigInteger.One << (Config.NumericBits - 1)) - 1) + @"]")) + @";
                int x = 0(none);";

            if (sdp == SubdomainPrivacy.None || isAbnormal)
            {
                foreach (var ptn in patterns)
                {
                    var pattern = ptn;
                    for (int i = 0; i < Config.NumericBits - patternLen; ++i)
                    {
                        code +=
                            @"
                        if(v & " + mask + @"(none) == " + pattern + @"(none))
                        {
                            x = 1(none);
                        }
                    ";
                        pattern <<= 1;
                        mask    <<= 1;
                    }
                }
            }

            code +=
                @" 
                return x;
            }";
            Parser  parser  = new Parser(code);
            Program program = parser.GetProgram();

            program.Translate();
            var programEnc = program.EncProgram();

            Party.RunAllParties(program, programEnc);

            return((Numeric)program.vTable["x"]);
        }
        static Numeric Test(int v, SubdomainPrivacy sdp, double statdomProb)
        {
            var code =
                @"
            {
                int v = " + v + ((sdp == SubdomainPrivacy.None) ? "" : ((sdp == SubdomainPrivacy.STATDOM) ? (@"[50, 1000, " + statdomProb + @"]") : @"[50, 1000]")) + @";
                double x;
                if(v > 50(none))
                {
                    if(v > 700)
                    {
                        x = " + a[7] + @" * System.Math.Sin(v);
                    }
                    else
                    {
                        if(v > 600)
                        {
                            x = " + a[6] + @" * System.Math.Sin(v);
                        }
                        else
                        {
                            if(v > 500)
                            {
                                x = " + a[5] + @" * System.Math.Sin(v);
                            }
                            else
                            {
                                if(v > 400)
                                {
                                    x = " + a[4] + @" * System.Math.Sin(v);
                                }
                                else
                                {
                                    if (v > 300)
                                    {
                                        x = " + a[3] + @" * System.Math.Sin(v);
                                    }
                                    else
                                    {
                                        if (v > 200)
                                        {
                                            x = " + a[2] + @" * System.Math.Sin(v);
                                        }
                                        else
                                        {
                                            x = " + a[1] + @" * System.Math.Sin(v);
                                        }
                                    }
                                }
                            }
                        }
                    }                   
                }
                else
                {
                    x = " + a[0] + @" * System.Math.Sin(v);
                }
                return x;
            }";
            Parser  parser  = new Parser(code);
            Program program = parser.GetProgram();

            program.Translate();
            var programEnc = program.EncProgram();

            Party.RunAllParties(program, programEnc);

            return((Numeric)program.vTable["x"]);
        }