Exemple #1
0
        public override string ToString()
        {
            LetterConverter lc   = new LetterConverter();
            string          from = "A  B  C  D  E  F  G  H  I  J  K  L  M  N  O  P  Q  R  S  T  U  V  W  X  Y  Z\n";
            string          to   = "";

            for (int i = 0; i < this.rotor.Length; i++)
            {
                to += lc.GetNumLet(this.rotor[i]) + "  ";
            }
            return(from + to);
        }
Exemple #2
0
        public string EncryptDecrypt(string plain)
        {
            LetterConverter lc = new LetterConverter();

            //Console.WriteLine("R Rotor:\n" + rRotor);
            //Console.WriteLine("M Rotor\n" + mRotor);
            //Console.WriteLine("L Rotor\n" + lRotor);
            //Console.WriteLine("Mirror\n" + mirror);
            //Console.WriteLine("  Plugs\n" + pBoard);
            //Console.WriteLine(" plain text:"+plain+":");

            String cipher = "";

            char[] letArray = plain.ToCharArray();
            int    x;

            for (int i = 0; i < letArray.Length; i++)
            {
                TurnRotor();

                //if (i==0) {
                Console.WriteLine("\n\n\nR Rotor:\n" + rRotor);
                Console.WriteLine("M Rotor\n" + mRotor);
                Console.WriteLine("L Rotor\n" + lRotor);
                Console.WriteLine(" Mirror\n" + mirror);
                Console.WriteLine("  Plugs\n" + pBoard);
                //}

                String a = letArray[i].ToString();
                //Console.WriteLine("processing:-"+a+"-");
                Console.Write("P Board in: " + a);
                x = pBoard.LetterIn(a);
                Console.WriteLine("  out: " + lc.GetNumLet(x) + x);

                Console.Write("E Rotor in: " + lc.GetNumLet(x) + x);
                x = eRotor.In(x);
                Console.WriteLine("  out: " + lc.GetNumLet(x) + x);

                Console.Write("R Rotor in: " + lc.GetNumLet(x) + x);
                x = rRotor.In(x);
                Console.WriteLine("  out: " + lc.GetNumLet(x) + x);

                Console.Write("M Rotor in: " + lc.GetNumLet(x) + x);
                x = mRotor.In(x);
                Console.WriteLine("  out: " + lc.GetNumLet(x) + x);

                Console.Write("L Rotor in: " + lc.GetNumLet(x) + x);
                x = lRotor.In(x);
                Console.WriteLine("  out: " + lc.GetNumLet(x) + x);
                if (mType == true)
                {
                    x = M4Rotor.In(x);
                    x = mirror.getInOut(x);
                    x = M4Rotor.Out(x);
                }
                else
                {
                    //Console.Write(" Mirror in: " + lc.GetNumLet(x) + x);
                    x = mirror.getInOut(x);
                    Console.WriteLine("  out: " + lc.GetNumLet(x) + x);
                }

                Console.Write("L Rotor in: " + lc.GetNumLet(x) + x);
                x = lRotor.Out(x);
                Console.WriteLine("  out: " + lc.GetNumLet(x) + x);

                Console.Write("M Rotor in: " + lc.GetNumLet(x) + x);
                x = mRotor.Out(x);
                Console.WriteLine("  out: " + lc.GetNumLet(x) + x);

                Console.Write("R Rotor in: " + lc.GetNumLet(x) + x);
                x = rRotor.Out(x);
                Console.WriteLine("  out: " + lc.GetNumLet(x) + x);

                Console.Write("E Rotor in: " + lc.GetNumLet(x) + x);
                x = eRotor.Out(x);
                Console.WriteLine("  out: " + lc.GetNumLet(x) + x);

                //Console.Write("P Board in: " + lc.GetNumLet(x) + x);
                cipher += pBoard.LetterOut(x);
                //Console.WriteLine("  out: " + cipher[cipher.Length-1]);
                //Console.WriteLine("================");
                //TurnRotor();
            }

            return(cipher);
        }
Exemple #3
0
 public String LetterOut(int x)
 {
     return(lc.GetNumLet(FindPlug(x)));
 }