예제 #1
0
 public RunDES()
 {
     this.kg = null;
     this.mg = null;
     this.f  = null;
     msgPart = null;
 }
예제 #2
0
        public string RunDecrypt()
        {
            string output    = "";
            string hexoutput = "";

            for (int i = 0; i < msgPart.Count; i++)
            {
                mg = new MsgGenerator(msgPart[i]);

                bool[] fcn;     // result for the f function
                bool[] lXORfcn; // temporary storage for the Lside and Rside swap

                for (int j = 0; j <= 15; j++)
                {
                    fcn     = f.fFunction(mg.GetRight(), kg.GetKKeyNumber(16 - j));
                    lXORfcn = mg.L_XOR_f(fcn);
                    mg.SetLeft(mg.GetRight());
                    mg.SetRight(lXORfcn);
                }

                mg.IPinvPermutation(mg.RconcatL());

                hexoutput += mg.GetMsgAsHexString() + " ";
                //output += mg.GetMsgAsText();
                output += mg.GetMsgAsHexString();
            }

            Console.WriteLine("\n\nDecrypted HEX output id:\n" + hexoutput);
            Console.WriteLine("\nDecrypted TEXT output is:\n" + output);

            return(output);
        }
예제 #3
0
        public string RunEncrypt()
        {   // this encryption uses the MsgGenerator and KeyGenerators
            string hexoutput  = "";
            string textoutput = "";

            for (int i = 0; i < msgPart.Count; i++)      // loop for msg
            {
                mg = new MsgGenerator(msgPart[i]);

                bool[] fcn;                   // result for the f function
                bool[] lXORfcn;               // temporary storage for the Lside and Rside swap

                for (int j = 0; j <= 15; j++) // loop for rounds
                {
                    Console.Write("L" + j + ": " + PrintBoolArray(mg.GetLeft()));
                    Console.WriteLine("   R" + j + ": " + PrintBoolArray(mg.GetRight()));

                    fcn = f.fFunction(mg.GetRight(), kg.GetKKeyNumber(j + 1));
                    Console.WriteLine("fcn: " + PrintBoolArray(fcn));

                    lXORfcn = mg.L_XOR_f(fcn);
                    mg.SetLeft(mg.GetRight());
                    mg.SetRight(lXORfcn);
                }

                Console.Write("L16: " + PrintBoolArray(mg.GetLeft()));
                Console.WriteLine("   R16: " + PrintBoolArray(mg.GetRight()));

                mg.IPinvPermutation(mg.RconcatL());

                Console.WriteLine("msg: " + Helper.printBoolArray(mg.GetMsg(), 8));

                //textoutput += mg.GetMsgAsText();
                textoutput += mg.GetMsgAsHexString();
                hexoutput  += mg.GetMsgAsHexString() + " ";
            }

            Console.WriteLine("\nEncrypted Hex output is:\n" + hexoutput + "|");
            //MessageBox.Show("HEX output:\n"+hexoutput);
            //Console.WriteLine("\nEncrypted Text output:\n"+textoutput+"|");

            return(textoutput);
        }
예제 #4
0
        public string RunEncrypt(string key, string msg)
        {   // use this encryption ONLY if the string is in HEX
            // else use the Constuctor and the RunEncrypt() methods above
            string output = "";

            kg = new KeyGenerators(key);
            f  = new Functions();

            bool[] fcn;     // result for the f function
            bool[] lXORfcn; // temporary storage for the Lside and Rside swap

            msg = Helper.AddPaddingToMsg(msg, 16, "0");
            List <string> msgPart = Helper.SplitMsgBySize(msg, 16);

            for (int i = 0; i < msgPart.Count; i++)     // loop for msg
            {
                mg = new MsgGenerator(msgPart[i]);

                for (int j = 0; j <= 15; j++)       // loop for rounds
                {
                    Console.Write("L" + j + ": " + PrintBoolArray(mg.GetLeft()));
                    Console.WriteLine("   R" + j + ": " + PrintBoolArray(mg.GetRight()));

                    fcn = f.fFunction(mg.GetRight(), kg.GetKKeyNumber(j + 1));
                    Console.WriteLine("fcn: " + PrintBoolArray(fcn));

                    lXORfcn = mg.L_XOR_f(fcn);
                    mg.SetLeft(mg.GetRight());
                    mg.SetRight(lXORfcn);
                }

                mg.IPinvPermutation(this.mg.RconcatL());
                output += mg.GetMsgAsHexString();
            }

            return(output);
        }