Beispiel #1
0
        public static void BFrotorsANDgroundset(int[,] order, int[,] grdSet, string cryb, string msg)
        {   // uses brute force on rotor order and ground settings
            // order set and ground setting set are created previously (order array and grdSet array)

            MachineRun ma;

            // plug board is set to: no plugs used
            string[] plugs = { null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null };
            Rotor    rl, rm, rr;

            StreamWriter file = new StreamWriter("C:\\EnigmaTests\\Stopwatch\\BFrotorsANDgroundset\\BFrotorANDgroundset_B_orderANDgrdSet_" + cryb + ".txt");

            file.WriteLine("\ncryb: " + cryb);
            file.WriteLine("\n msg: " + msg + "\r\n");
            file.Flush();

            Stopwatch timer = new Stopwatch();

            timer.Start();

            string line  = "";
            int    count = 0;                                  // count for all possible calculations

            for (int ord = 1; ord < order.GetLength(0); ord++) // order set row
            {
                Console.WriteLine("running code for row: " + ord);
                for (int grd = 1; grd < grdSet.GetLength(0); grd++) // grdSet set row
                {
                    count++;

                    //Console.WriteLine(order[orderRow, 1] + ":" + order[orderRow, 2] + ":" + order[orderRow, 3] + ":" + gpl + ":" + gpm + ":" + gpr);

                    rl = new Rotor(order[ord, 1], grdSet[grd, 1], 0);      //  left rotor , A -> Z, ring setting a.
                    rm = new Rotor(order[ord, 2], grdSet[grd, 2], 0);      //  middle rotor , A -> Z, ring setting a.
                    rr = new Rotor(order[ord, 3], grdSet[grd, 3], 0);      //  right rotor , A -> Z, ring setting a.

                    // mirror position is set to "B" and entry rotor is set to "O"
                    ma = new MachineRun("B", rl, rm, rr, "O", plugs);
                    string decMsg = ma.EncryptDecrypt(msg);

                    if (decMsg.Contains(cryb.ToUpper()))
                    {
                        line  = "FOUND at rotor order: " + order[ord, 1] + order[ord, 2] + order[ord, 3] + "  at GS: " + grdSet[grd, 1] + "." + grdSet[grd, 2] + "." + grdSet[grd, 3];
                        line += Environment.NewLine + "decoded: " + decMsg;
                        //Console.WriteLine(line);
                        file.WriteLine(line);
                        file.Flush();
                    }
                }
            }
            file.WriteLine("\r\n\r\n" + count);
            timer.Stop();
            TimeSpan ts = timer.Elapsed;

            file.WriteLine("running time at " + ts.Days + ":" + ts.Hours + ":" + ts.Minutes + ":" + ts.Seconds + "." + ts.Milliseconds / 10);
            file.Flush();
            file.Close();
        }
Beispiel #2
0
        public static string EncryptParallelMachineRotorGroundRing(int rsL, int rsM, int rsR, int gsL, int gsM, int gsR, int ringL, int ringM, int ringR, string msg)
        {   // encrypts the message for each rotor order for all possible settings of rind and ground
            // plug board is set to: no plugs used
            //string[] plugs = { "H", "X", "E", "Y", "L", "Z", "O", "W", "A", "B", "C", "D", "F", "G", "I", "J", "K", "M", "N", "P", "Q", "R", null, null, null, null };
            string[] plugs = { "A", "V", "B", "S", "C", "G", "D", "L", "F", "U", "H", "Z", "I", "N", "K", "M", "O", "W", "R", "X", null, null, null, null, null, null };
            //string[] plugs = { null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null };

            // mirror position is set to "B" and entry rotor is set to "O"
            MachineRun ma     = new MachineRun("B", new Rotor(rsL, gsL, ringL), new Rotor(rsM, gsM, ringM), new Rotor(rsR, gsR, ringR), "O", plugs);
            string     decMsg = ma.EncryptDecrypt(msg);

            return(decMsg); // +" |" + rsL + rsM + rsR + "|" + gsL + "." + gsM + "." + gsR + "|" + ringL + "." + ringM + "." + ringR;
        }
Beispiel #3
0
        public static void MachineRotorGroundPlug(int rsl, int rsm, int rsr, int gsl, int gsm, int gsr, string[] plugs, string cryb, string msg, StreamWriter fileOut)
        {
            // mirror position is set to "B" and entry rotor is set to "O"
            MachineRun ma     = new MachineRun("B", new Rotor(rsl, gsl, 0), new Rotor(rsm, gsm, 0), new Rotor(rsr, gsr, 0), "O", plugs);
            string     decMsg = ma.EncryptDecrypt(msg);

            //Console.WriteLine(rsl + ":" + rsm + ":" + rsr + "|" + gsl + ":" + gsm + ":" + gsr + "|");
            if (decMsg.Equals(cryb.ToUpper()))
            {
                string line = "FOUND at rotor order: " + rsl + rsm + rsr + "  at GS: " + gsl + "." + gsm + "." + gsr + "|" + PrintPlugs(plugs);
                line += Environment.NewLine + "decoded: " + decMsg;
                Console.WriteLine(line);
                //PrintPlugs(plugs);
                fileOut.WriteLine(line);
                fileOut.Flush();
            }
        }
Beispiel #4
0
        public static void MachineRotorGround(int rsl, int rsm, int rsr, int gsl, int gsm, int gsr, string cryb, string msg, StreamWriter file)
        {
            //Console.WriteLine("working task ..."+rsl+":"+rsm+":"+rsr+"|"+gsl+"."+gsm+"."+gsr);

            // plug board is set to: no plugs used
            string[] plugs = { null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null };

            // mirror position is set to "B" and entry rotor is set to "O"
            MachineRun ma     = new MachineRun("B", new Rotor(rsl, gsl, 0), new Rotor(rsm, gsm, 0), new Rotor(rsr, gsr, 0), "O", plugs);
            string     decMsg = ma.EncryptDecrypt(msg);

            if (decMsg.Contains(cryb.ToUpper()))
            {
                string line = "FOUND at rotor order: " + rsl + rsm + rsr + "  at GS: " + gsl + "." + gsm + "." + gsr;
                line += Environment.NewLine + "decoded: " + decMsg;
                Console.WriteLine(line);
                file.WriteLine(line);
                file.Flush();
            }
        }
Beispiel #5
0
        public static void MachineRotorGroundRing(int rsL, int rsM, int rsR, int gsL, int gsM, int gsR, int ringL, int ringM, int ringR, string cryb, string msg, StreamWriter file)
        {
            //Console.WriteLine("working task ..."+rsL+":"+rsM+":"+rsR+"|"+gsL+"."+gsM+"."+gsR+"|"+ringL+"."+ringM+"."+ringR);

            // plug board is set to: no plugs used
            //string[] plugs = { "H", "X", "E", "Y", "L", "Z", "O", "W", "A", "B", "C", "D", "F", "G", "I", "J", "K", "M", "N", "P", "Q", "R", null, null, null, null };
            string[] plugs = { null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null };

            // mirror position is set to "B" and entry rotor is set to "O"
            MachineRun ma     = new MachineRun("B", new Rotor(rsL, gsL, ringL), new Rotor(rsM, gsM, ringM), new Rotor(rsR, gsR, ringR), "O", plugs);
            string     decMsg = ma.EncryptDecrypt(msg);

            //Console.WriteLine("msg: "+decMsg);
            if (decMsg.Contains(cryb.ToUpper()))
            {
                totalFound++;
                string line = "" + rsL + rsM + rsR + "|" + gsL + "." + gsM + "." + gsR + "|" + ringL + "." + ringM + "." + ringR;
                //line += Environment.NewLine + "decoded: " + decMsg;
                ////Console.WriteLine(line);
                file.WriteLine(line);
                file.Flush();
            }
        }
Beispiel #6
0
        public static void BFrotorsEveryTwo(int[,] order, string cryb, string msg)
        {   // brute force through order of rotors and their ground settings  NOT including ring settings and NOT including the plugboard
            // uses the B mirror
            // runs two enigmas consecutively

            StreamWriter file = new StreamWriter("C:\\EnigmaTests\\Stopwatch\\BFrotors\\BFrotorsEveryTwo_B_orderOf8" + cryb + ".txt");

            // plug board is set to: no plugs used
            string[] plugs = { null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null };

            file.WriteLine("\ncryb: " + cryb);
            file.WriteLine("\n msg: " + msg + "\r\n");
            file.Flush();

            Stopwatch timer = new Stopwatch();

            timer.Start();

            int count = 0;        // count for all possible calculations

            string line     = ""; // for output to the file
            string decMsg_1 = "";
            string decMsg_2 = "";

            Rotor      rl_1, rm_1, rr_1, rl_2, rm_2, rr_2;
            MachineRun ma_1, ma_2;


            for (int orderRow = 1; orderRow < order.GetLength(0); orderRow += 2)
            {
                //Console.WriteLine("Checking row: " + orderRow);

                for (int gpl = 0; gpl <= 25; gpl++)                           // ground position of left rotor
                {
                    for (int gpm = 0; gpm <= 25; gpm++)                       // ground position of middle rotor
                    {
                        for (int gpr = 0; gpr <= 25; gpr++)                   // ground position right rotor
                        {
                            rl_1 = new Rotor(order[orderRow, 1], gpl, 0);     //  left rotor , A -> Z, ring setting a.
                            rm_1 = new Rotor(order[orderRow, 2], gpm, 0);     //  middle rotor , A -> Z, ring setting a.
                            rr_1 = new Rotor(order[orderRow, 3], gpr, 0);     //  right rotor , A -> Z, ring setting a.

                            rl_2 = new Rotor(order[orderRow + 1, 1], gpl, 0); //  left rotor , A -> Z, ring setting a.
                            rm_2 = new Rotor(order[orderRow + 1, 2], gpm, 0); //  middle rotor , A -> Z, ring setting a.
                            rr_2 = new Rotor(order[orderRow + 1, 3], gpr, 0); //  right rotor , A -> Z, ring setting a.

                            // mirror position is set to "B" and entry rotor is set to "O"
                            ma_1 = new MachineRun("B", rl_1, rm_1, rr_1, "O", plugs);
                            ma_2 = new MachineRun("B", rl_2, rm_2, rr_2, "O", plugs);

                            decMsg_1 = ma_1.EncryptDecrypt(msg);
                            count++;

                            decMsg_2 = ma_2.EncryptDecrypt(msg);
                            count++;

                            //Console.WriteLine(order[orderRow, 1]+":"+ order[orderRow, 2]+":"+order[orderRow, 3]+":"+gpl+":"+gpm+":"+gpr);
                            //Console.WriteLine(order[orderRow+1, 1] + ":" + order[orderRow+1, 2] + ":" + order[orderRow+1, 3] + ":" + gpl + ":" + gpm + ":" + gpr);

                            if (decMsg_1.Contains(cryb.ToUpper()))
                            {
                                line  = "FOUND at rotor order: " + order[orderRow, 1] + order[orderRow, 2] + order[orderRow, 3] + "  at GS: " + gpl + "." + gpm + "." + gpr;
                                line += Environment.NewLine + "decoded: " + decMsg_1;
                                //Console.WriteLine(line);
                                file.WriteLine(line);
                                file.Flush();
                            }

                            if (decMsg_2.Contains(cryb.ToUpper()))
                            {
                                line  = "FOUND at rotor order: " + order[orderRow + 1, 1] + order[orderRow + 1, 2] + order[orderRow + 1, 3] + "  at GS: " + gpl + "." + gpm + "." + gpr;
                                line += Environment.NewLine + "decoded: " + decMsg_2;
                                //Console.WriteLine(line);
                                file.WriteLine(line);
                                file.Flush();
                            }
                        }
                    }
                }
            }
            file.WriteLine("\r\n\r\n" + count);
            timer.Stop();
            TimeSpan ts = timer.Elapsed;

            file.WriteLine("running time at " + ts.Days + ":" + ts.Hours + ":" + ts.Minutes + ":" + ts.Seconds + "." + ts.Milliseconds / 10);
            file.Flush();
            file.Close();
        }