Example #1
0
        /// <summary>
        /// Najde všechny unikátní slova a uloží je
        /// </summary>
        public static void Save(string language)
        {
            string targetFolder = Storage.ConfPath + language + "/";
            string fileSavePath = targetFolder + "unique.txt";
            string fileTextsPath = targetFolder + "texts.txt";

            string text = File.ReadAllText(fileTextsPath);
            string[] texts = TextAnalysis.ToWords(text);
            CryptanalysisCore.UniqueWords uniqueWords = new CryptanalysisCore.UniqueWords(texts);
            var uniqueWordsList = uniqueWords.GetUniqueWords();

            StringBuilder sb = new StringBuilder();
            foreach (var words in uniqueWordsList)
            {
                foreach (var word in words)
                {
                    sb.AppendFormat("{0} ", word);
                }
            }
            File.WriteAllText(fileSavePath, sb.ToString());
        }
Example #2
0
        /// <summary>
        /// Provede frekvenční analýzu na slovech, tj. text musí obsahovat mezery
        /// jako hranice pro slova.
        /// </summary>
        /// <param name="ciphertext">Šifrový text</param>
        /// <param name="language">Jazyk, který byl text zašifrován</param>
        /// <returns>Seznam možných klíčů</returns>
        public List<string> FrequencyAnalysisWithSpaces(string ciphertext, Storage.Languages language)
        {
            string key;
            string[] words = TextAnalysis.ToWords(ciphertext);
            UniqueWords uniqueWords = new UniqueWords(Storage.GetLangChar(language).UniqueWords);

            var result = uniqueWords.GetLettersSubst(words);

            if (result != null)
            {
                WordsCompleter completer = new WordsCompleter(words, result, language);
                var subst = completer.Complete();
                key = GetKey(subst);
            }
            else
            {
                throw new Exceptions.MatchNotFound();
            }

            return new List<string>() { key };
        }