using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml; using System.IO; using ExtensionMethods; namespace CryptanalysisCore { public class LangCharacteristic { public LangCharacteristic(Storage.Languages language) { string targetFolder = Storage.ConfPath + language.ToString() + "/"; UniqueWords = File.ReadAllText(targetFolder + Storage.UniqueFile).Split(' '); Dictionary = File.ReadAllText(targetFolder + Storage.DictionaryFile).Split(' '); SortedDictionary = ExtensionMethods.Dictionary.Create(Dictionary, x => x.Length); XmlDocument lang = new XmlDocument(); lang.Load(targetFolder + Storage.FrequencyFile); Letters = GetOccurrance(lang.SelectNodes("//letters/info")); Bigrams = GetOccurrance(lang.SelectNodes("//bigrams/info")); Trigrams = GetOccurrance(lang.SelectNodes("//trigrams/info")); StartLetters = GetOccurrance(lang.SelectNodes("//startLetters/info")); EndLetters = GetOccurrance(lang.SelectNodes("//endLetters/info")); NextLetters = GetOccurrance(lang.SelectNodes("//nextLetters/info")); PrevLetters = GetOccurrance(lang.SelectNodes("//prevLetters/info")); } private Dictionary GetOccurrance(XmlNodeList occurrances) { Dictionary occurrence = new Dictionary(); foreach(XmlNode occ in occurrances) occurrence[occ.Attributes["letters"].InnerText] = double.Parse(occ.InnerText); return occurrence; } /// /// Obsahuje relativní počet výskytů písmene v textu /// public Dictionary Letters { get; private set; } /// /// Obsahuje relativní počet výskytů bigramů v textu /// public Dictionary Bigrams { get; private set; } /// /// Obsahuje relativní počet výskytů trigramů v textu /// public Dictionary Trigrams { get; private set; } /// /// Obsahuje relativní počet výskytů písmen na začátku slova /// public Dictionary StartLetters { get; private set; } /// /// Obsahuje relativní počet výskytů písmen na konci slova /// public Dictionary EndLetters { get; private set; } /// /// Obsahuje průměrný počet výskytů daného písmene za nějakým jiným písmenem /// public Dictionary NextLetters { get; private set; } /// /// Obsahuje průměrný počet výskytů daného písmene před nějakým jiným písmenem /// public Dictionary PrevLetters { get; private set; } /// /// Obsahuje unikátní slova /// public string[] UniqueWords { get; private set; } /// /// Obsahuje nesetříděný seznam všech slov /// public string[] Dictionary { get; private set; } /// /// Obsahuje setříděný seznam všech slov podle délky slova /// public Dictionary SortedDictionary { get; private set; } } }