コード例 #1
0
        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);
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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);
        }