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); }