}                                                               // 此LoopHandler管理的代码块

        public LoopHandler(BlockCipherParser parser,
                           string loopCode, string[] codeContext) : base(parser)
        {
            loopCode = loopCode.Trim();
            string[] loopDetails = loopCode.Split(' ');

            LoopKey  = loopDetails[1];
            LoopFrom = int.Parse(loopDetails[2]);
            LoopTo   = int.Parse(loopDetails[3]);

            CodeContext = codeContext;
        }
        public SplitHandler(
            BlockCipherParser parser, string splitCode, string[] codeContext) : base(parser)
        {
            CodeContext = codeContext;

            // @TOOD: 解析得到SplitKey和SplitCount
            Regex  reg          = new Regex(@"(?<=\().+(?=\))");
            Match  match        = reg.Match(splitCode);
            string splitContext = match.Value.Trim();

            string[] splitContexts = splitContext.Split(',');

            VariableKey = splitContexts[0].Trim();
            SplitCount  = int.Parse(splitContexts[1].Trim());
        }
        static void Main(string[] args)
        {
            //BitArray test = new BitArray(new bool[] { true, false, false });
            //Console.WriteLine(BlockCipherUtil.BitArrayToString(test));

            //string temp = "state(88)";
            //string length = Regex.Match(temp, "((\\d+))").Value;
            //string key = Regex.Match(temp, "(\\w+)").Value;

            //test = new BitArray(8);
            //Console.WriteLine(BlockCipherUtil.BitArrayToString(test));

            // 输入置换和S盒
            string psCount = Console.ReadLine();

            string[] psCounts = psCount.Split(' ');
            PSData[] permutes = InputPSData(int.Parse(psCounts[0]));
            PSData[] sBoxs    = InputPSData(int.Parse(psCounts[1]));

            // 输入未经处理的上下文
            string[] rawContext = InputRawContext();


            // 创建加密算法解析器
            BlockCipherParser parser = new BlockCipherParser(permutes, sBoxs, rawContext);

            // 输入state和key并进行加密
            int runCount = int.Parse(Console.ReadLine());

            while (runCount-- > 0)
            {
                string state = Console.ReadLine();
                string key   = Console.ReadLine();

                parser.Run(state, key);

                Console.WriteLine("state::" + parser.GetState());
                Console.WriteLine("key::" + parser.GetKey());
            }

            Console.WriteLine("Well Done!");
            Console.ReadKey();
        }
 public BaseHandler(BlockCipherParser parser)
 {
     Parser = parser;
 }
Ejemplo n.º 5
0
 public ExpressionParser(BlockCipherParser parser)
 {
     Parser = parser;
 }