private void AddMissingTranslationToStatistics(List <LanguageStatistics> statistics, string language, string modName) { if (statistics.Any(ls => ls.LanguageName == language)) { var languageStatistics = statistics.First(ls => ls.LanguageName == language); if (languageStatistics.MissingModStrings.ContainsKey(modName)) { // increment languageStatistics.MissingModStrings[modName] = languageStatistics.MissingModStrings[modName] + 1; } else { languageStatistics.MissingModStrings.Add(modName, 1); } } else { var languageStatistics = new LanguageStatistics(); languageStatistics.LanguageName = language; languageStatistics.MissingModStrings = new Dictionary <string, int>(); languageStatistics.MissingModStrings.Add(modName, 1); statistics.Add(languageStatistics); } }
public void Execute() { this.genAttacker = new GeneticAttacker(); this.dicAttacker = new DictionaryAttacker(); this.hillAttacker = new HillclimbingAttacker(); Boolean inputOK = true; // Clear presentation ((AssignmentPresentation)Presentation).Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback) delegate { try { ((AssignmentPresentation)Presentation).Entries.Clear(); } catch (Exception ex) { GuiLogMessage("Exception while clearing entries list:" + ex.Message, NotificationLevel.Error); } }, null); // Prepare the cryptanalysis of the ciphertext ciphertext = ciphertext.ToLower(); // Set alphabets string lang = LanguageStatistics.LanguageCode(settings.Language); grams = new Tetragrams(lang, settings.UseSpaces); plaintextalphabet = grams.Alphabet; ciphertextalphabet = String.IsNullOrEmpty(CiphertextAlphabet) ? new string(Ciphertext.ToLower().Distinct().OrderBy(c => c).ToArray()).Replace("\r", "").Replace("\n", "") : new string(CiphertextAlphabet.ToLower().Distinct().OrderBy(c => c).ToArray()).Replace("\r", "").Replace("\n", ""); if (ciphertextalphabet[0] == ' ') { ciphertextalphabet = ciphertextalphabet.Trim() + " "; } ptAlphabet = new Alphabet(plaintextalphabet); ctAlphabet = new Alphabet(ciphertextalphabet); if (settings.ChooseAlgorithm == 1) { ciphertext = ciphertext.ToLower(); plaintextalphabet = plaintextalphabet.ToLower(); ciphertextalphabet = plaintextalphabet; ptAlphabet = new Alphabet(plaintextalphabet); ctAlphabet = new Alphabet(ciphertextalphabet); // Dictionary try { langDic = new Dictionary(LanguageStatistics.LanguageCode(settings.Language) + "-small.dic", plaintextalphabet.Length); } catch (Exception ex) { GuiLogMessage(Resources.error_dictionary + ": " + ex.Message, NotificationLevel.Error); } // Dictionary correct? if (this.langDic == null) { GuiLogMessage(Resources.no_dictionary, NotificationLevel.Warning); } } // Plaintext Alphabet this.plaintextalphabetoutput = plaintextalphabet; OnPropertyChanged("PlaintextAlphabetOutput"); if (ciphertext != null) { this.cText = new Text(ciphertext.ToLower(), this.ctAlphabet, settings.TreatmentInvalidChars); } else { this.cText = null; } // PTAlphabet correct? if (this.ptAlphabet == null) { GuiLogMessage(Resources.no_plaintext_alphabet, NotificationLevel.Error); inputOK = false; } // CTAlphabet correct? if (this.ctAlphabet == null) { GuiLogMessage(Resources.no_ciphertext_alphabet, NotificationLevel.Error); inputOK = false; } // Ciphertext correct? if (this.cText == null) { GuiLogMessage(Resources.no_ciphertext, NotificationLevel.Error); inputOK = false; } // Check length of ciphertext and plaintext alphabet if (this.ctAlphabet.Length > this.ptAlphabet.Length) { //if ciphertext alphabet is too long, we fallback to the plaintext alphabet GuiLogMessage(String.Format(Resources.error_alphabet_length, ciphertextalphabet, ciphertextalphabet.Length, plaintextalphabet, plaintextalphabet.Length), NotificationLevel.Warning); ctAlphabet = ptAlphabet; } // If input incorrect return otherwise execute analysis lock (this.stopFlag) { if (this.stopFlag.Stop) { return; } } if (!inputOK) { inputOK = true; return; } this.UpdateDisplayStart(); //this.masPresentation.DisableGUI(); this.masPresentation.UpdateOutputFromUserChoice = this.UpdateOutput; this.keyCandidates = new List <KeyCandidate>(); /* Algorithm: * 0 = Hillclimbing CPU * 1 = Genetic & Dictionary */ if (settings.ChooseAlgorithm == 0) { AnalyzeHillclimbing(false); totalKeys = hillAttacker.TotalKeys; } else if (settings.ChooseAlgorithm == 1) { if (this.langDic != null) { AnalyzeDictionary(); } AnalyzeGenetic(); } this.UpdateDisplayEnd(); //set final plugin progress to 100%: OnPluginProgressChanged(this, new PluginProgressEventArgs(1.0, 1.0)); }