Example #1
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Commandline Parameter Error");
                Console.WriteLine("Example:  SolveMe_Riddle.exe <Wordfile Filename> <Cipher Filename>");
                Console.WriteLine("Arguments = " + String.Join(';', args));
            }
            else
            {
                var      WordFilename = args[0];
                WordFile theWordfile  = GetWordfile(WordFilename);

                var    CipherFilename = args[1];
                Cipher theCipherFile  = GetCipher(CipherFilename);

                Debug.Print(theCipherFile.GetBytes.Length.ToString());

                if (theWordfile is null)
                {
                    Console.WriteLine("Error loading Wordfile.");
                }
                else if (theCipherFile is null)
                {
                    Console.WriteLine("Error loading CipherFile.");
                }
                else
                {
                    Console.WriteLine("Start Processing...");

                    byte[] nextKeys;
                    var    theKeygen      = new Keygen();
                    var    theDecrypter   = new Decrypter();
                    var    theWordtester  = new WordTester(theWordfile);
                    var    theLogger      = new Logger("Logger.txt");
                    var    DecryptedBytes = new byte[theCipherFile.GetBytes.Length];

                    while (!theKeygen.AllKeysDelivered)
                    {
                        nextKeys       = theKeygen.GetNextKeys();
                        DecryptedBytes = theDecrypter.DecryptBytes(theCipherFile.GetBytes, nextKeys);
                        bool TestText = theWordtester.TestAsciiBytes(DecryptedBytes);

                        if (TestText && theWordtester.LastMatchCollection.Count >= 8)
                        {
                            Console.WriteLine(":)");
                            Console.Write("{0} - Found Key : {1,3} {2,3} {3,3} -> ", DateTime.Now.ToString(), nextKeys[0], nextKeys[1], nextKeys[2]);
                            Console.WriteLine("");
                            Console.WriteLine("Anzahl an Wort Treffer ---> {0}", theWordtester.LastMatchCollection.Count);
                            foreach (Match m in theWordtester.LastMatchCollection)
                            {
                                Console.WriteLine("---> {0}", m.Value);
                            }

                            Console.WriteLine("{0}", theWordtester.LastMatchCollection);

                            Console.WriteLine("");
                            Console.WriteLine(System.Text.ASCIIEncoding.ASCII.GetString(theDecrypter.DecryptedBytes));
                            Console.WriteLine("");
                            Console.WriteLine("");
                        }
                    }
                    Console.WriteLine("Finish.");
                }
            }
        }