public static Dictionary <char, long> GetLettersOccurrences(EncodedText et) { Dictionary <char, long> result = CoincidenceKeyLengthAnalyzer.GetLetterOccurrenceDictionary(et.Alphabet); for (long i = 0, l = et.Length; i < l && et[i] != '\0'; ++i) { result[et[i]]++; } return(result); }
private static double GetCoincidenceIndex(EncodedText et) { Dictionary <char, long> lettersOccurences = CoincidenceKeyLengthAnalyzer.GetLettersOccurrences(et); long sum = 0; foreach (KeyValuePair <char, long> letterOccurrences in lettersOccurences) { sum += letterOccurrences.Value * letterOccurrences.Value; } return((double)sum / (et.Length * et.Length)); }
private List <KeyValuePair <char, long> > GetOftenLetters() { Dictionary <char, long> occurrences = CoincidenceKeyLengthAnalyzer.GetLettersOccurrences(encodedText); List <KeyValuePair <char, long> > result = new List <KeyValuePair <char, long> >(); foreach (KeyValuePair <char, long> occurrence in occurrences) { result.Add(new KeyValuePair <char, long>(occurrence.Key, occurrence.Value)); } result.Sort((firstPair, nextPair) => { return(nextPair.Value.CompareTo(firstPair.Value)); }); /* * for (int i = 10; result.Count > i; ) { * result.RemoveAt(i); * } */ return(result); }