Ejemplo n.º 1
0
        public void Test()
        {
            TI_Searcher ts = new TI_Searcher(2, s);

            ts.ComputeCoef();
            int[] con = { 1, 1 };
            for (int k = 0; k < s; k++)
            {
                int[] tempTI = ts.GetCorrectTerm(con, 2);
                for (int i = 0; i < tempTI.Length; i++)
                {
                    if (TI_Form[i] == 1 && tempTI[i] == 1)
                    {
                        System.Console.WriteLine("Error!");
                    }
                    TI_Form[i] ^= tempTI[i];
                }
                ts.Shift1();
            }
            System.Console.WriteLine("最终a*b对应的TI和形式为");
            int sum = 0;

            for (int i = 0; i < TI_Form.Length; i++)
            {
                System.Console.Write("{0}\t", TI_Form[i]);
                sum += TI_Form[i];
            }
            System.Console.WriteLine("\n共有{0}项", sum);

            Print_RealTruthTable();
        }
Ejemplo n.º 2
0
        //从ANF开始计算TI
        public void Compute_From_ANF()
        {
            for (int i = 0; i < Ori_ANF.Length; i++)
            {
                if (Ori_ANF[i] == 0)
                {
                    continue;
                }
                //对原始ANF中的每一项
                int[] con = new int[v];
                int   d   = 0;
                for (int j = 0; j < v; j++)
                {
                    if (GetBit(i, j) == 1)//修改
                    {
                        con[j] = 1;
                        d++;
                    }
                }
                //d表示次数,con表示其中含有的bit
                if (d == 0)
                {
                    TI_Form[0] ^= 1;
                    continue;
                }
                TI_Searcher ts = new TI_Searcher(d, s);
                ts.ComputeCoef();
                //2018.3.26 Ensure y0 contains x0,x1, do not have x2
                //ts.Shift1();


                int[] tempTI = ts.GetCorrectTerm(con, v);



                //验证用,加和所有share---------------
                //ts.Shift1();
                //for (int k = 1; k < s; k++)
                //{
                //    int[] temp = ts.GetCorrectTerm(con, v);
                //    for (int j = 0; j < tempTI.Length; j++)
                //    {
                //        tempTI[j] ^= temp[j];
                //    }
                //    ts.Shift1();
                //}
                //实际使用中应该去掉这部分---------------

                for (int j = 0; j < tempTI.Length; j++)
                {
                    TI_Form[j] ^= tempTI[j];
                }
            }
            //Print_RealTruthTable();
            //System.Console.WriteLine("最终的TI和形式为");
            //int sum = 0;
            //for (int i = 0; i < TI_Form.Length; i++)
            //{
            //    System.Console.Write("{0}\t", TI_Form[i]);
            //    sum += TI_Form[i];
            //}
            //System.Console.WriteLine("\n共有{0}项", sum);
        }