示例#1
0
文件: Form1.cs 项目: EthanC/ADFGX
        /// <summary>
        /// The BackgroundWorker Function responsible for checking Versions and Populating inital data on the application from the server.
        /// </summary>
        private void InitServerWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            //init's class to communicate with external server
            ADFGXService.ServiceClient ADFGXserv = new ADFGXService.ServiceClient();

            //Gets the News Information from Server and populates the News Textbox
            var retNews = ADFGXserv.GetNews();
            if (retNews.Contains("ERROR:"))
                this.newsText.Invoke(new MethodInvoker(delegate () { this.newsText.Text = "An error occured while attempting to contact server! Please contact [email protected] to report the below error..." + Environment.NewLine + Environment.NewLine + retNews; }));
            else
                this.newsText.Invoke(new MethodInvoker(delegate () { this.newsText.Text = retNews; }));

            //Gets the Top20 results from Server and populates the Results Textbox
            var retTop = ADFGXserv.GetTop20();
            if (retTop.Contains("ERROR:"))
                this.resultsText.Invoke(new MethodInvoker(delegate () { this.resultsText.Text = "An error occured while attempting to contact server! Please contact [email protected] to report the below error..." + Environment.NewLine + Environment.NewLine + retTop; }));
            else
                this.resultsText.Invoke(new MethodInvoker(delegate () { this.resultsText.Text = retTop; }));

            //Gets the currently being worked on Cipher
            var retCipher = ADFGXserv.GetCipher();
            if (retTop.Contains("ERROR:"))
            {
                MessageBox.Show("An error occured while attempting to obtain the cipher to work on from the server. This is commonly because of a lack of internet connection. This application needs the internet to run. If this error continues after being connected, please ensure you can view the site http://fascinatinginformation.com/ and contact [email protected]" + Environment.NewLine + Environment.NewLine + retCipher, "ADFGX Cloud Factoring App");
            }
            else
                Cipher = retCipher;

            //Gets the Version information from Server and exits if the Version is incorrect
            retVer = ADFGXserv.GetVersion();
            if (retVer.Contains("ERROR:"))
            {
                MessageBox.Show("An error occured while attempting to check the version of the application with the server. This is commonly because of a lack of internet connection. This application needs the internet to run. If this error continues after being connected, please ensure you can view the site http://fascinatinginformation.com/ and contact [email protected]" + Environment.NewLine + Environment.NewLine + retVer, "ADFGX Cloud Factoring App");
                Environment.Exit(0);
            }
            else if (retVer == "")
            {
                MessageBox.Show("An error occured while attempting to check the version of the application with the server. This is commonly because of a lack of internet connection. This application needs the internet to run. If this error continues after being connected, please ensure you can view the site http://fascinatinginformation.com/ and contact [email protected] . Exiting application to avoid wasting resources.", "ADFGX Cloud Factoring App");
                Environment.Exit(0);
            }
            else
            {
                if (retVer != "3")
                {
                    MessageBox.Show("A new version of the application has been released, thus running this version would be a waste. When exiting this messagebox the new version will be downloaded and ran.", "ADFGX Cloud Factoring App");
                    System.Net.WebClient myWebClient = new System.Net.WebClient();
                    myWebClient.DownloadFile("http://fascinatinginformation.com/ADFGX_Cloud_Solver.exe", "ADFGX_Cloud_Solver_" + retVer + ".exe");
                    System.Diagnostics.Process.Start("ADFGX_Cloud_Solver_" + retVer + ".exe");
                    Environment.Exit(0);
                }
            }
        }
示例#2
0
文件: Form1.cs 项目: EthanC/ADFGX
 /// <summary>
 /// The BackgroundWorker Function responsible for Brute Forcing the cipher. This is the 'Bread and Butter' of the app
 /// </summary>
 private void BruteForceWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     //init's class to communicate with external server
     ADFGXService.ServiceClient ADFGXserv = new ADFGXService.ServiceClient();
     //Alphabet to start with when Brute Forcing
     string Alpha = new string(new[] { 'Z', 'O', 'M', 'B', 'I', 'E', 'F', 'G', 'H', 'K', 'L', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'A', 'C', 'D' });
     //Set Max CPU usage
     var opts = new ParallelOptions();
     if (CPUperc == "LOW")
         opts.MaxDegreeOfParallelism = 4;
     //Set Cancel Token for Brute Force Thread
     opts.CancellationToken = cts.Token;
     //Load Ngrams
     GenericScoring.ngram_score.LoadNgarmDoubleFile(Properties.Resources.english_trigrams, Properties.Resources.english_quadgrams);
     //Start the Brute Forcing Loop
     try
     {
         Parallel.ForEach(Infinite(), opts, new Action<bool>((val) =>
         {
             opts.CancellationToken.ThrowIfCancellationRequested();
         //Shuffle the Alphabet and get a random Cipher Key
         string C_Aplha = Alpha.Shuffle();
         //Decipher the ciphertext by Substitution
         var ret = Cipher.Substitute(C_Aplha);
                 //------var ret = SubstitutionSolve(Cipher, C_Aplha);---//
         //Get Score of the return by calculating the English Ngram Frequencies in it
         var Sscore = GenericScoring.ngram_score.ScoreDouble(ret);
         //If the Score in above -120 (Average English Ngram Score for a 34 length Sentence), send to server
         if (Sscore > -280)
             {
                 GoodCount++;
                 ADFGXserv.SetData(ret, C_Aplha, Convert.ToInt32(Sscore), ContributerName);
             }
         //Log best score so far for UI log
         if (Sscore > BestScore)
             {
                 BestScore = Sscore;
                 GlobalUpdateString = "Your Best Score So Far: " + Environment.NewLine + "Key: " + C_Aplha + Environment.NewLine + "Result: " + ret + Environment.NewLine + "Score: " + Sscore;
             }
             TotalCount++;
         }));
     }//Catch when user cancels the process by hitting the stop button.
     catch (OperationCanceledException ex)
     {
     }
     finally
     {
         cts.Dispose();
     }
 }