Ejemplo n.º 1
0
        static int KeyLengthSelection(string text)
        {
            Console.Write("Discard single-occurence key lengths (1/0)?> ");
            bool discardSingle = int.Parse(Console.ReadLine()) != 0;

            Repetition[]          repetitions         = Repetition.GetTextRepetitions(text);
            Dictionary <int, int> keyLengthWeightings = KeyLengthDeduction.GetKeyLengthWeights(repetitions, discardSingle);
            Dictionary <int, int> factoredWeightings  = KeyLengthDeduction.GetFactoredKeyLengthWeights(keyLengthWeightings);

            Console.Write("View how many top lengths?> ");
            int topLengthsCount = int.Parse(Console.ReadLine());

            int requestCount = topLengthsCount < factoredWeightings.Count ? topLengthsCount : factoredWeightings.Count;
            Dictionary <int, int> topLengths = ProgramMath.GetTopDictionaryKeysByValue(factoredWeightings, requestCount);

            Console.WriteLine();
            Console.WriteLine("(English average IOC is about 0.0667)");
            Console.WriteLine("Top Key Lengths:");

            foreach (int length in topLengths.Keys)
            {
                decimal ioc = KeyLengthDeduction.GetAverageIOCOfTextByOffset(text, length);

                Console.WriteLine($"{length} (weighting = {topLengths[length]}) - Average IOC = {ioc}");
            }

            Console.Write("Select chosen key length> ");

            int keyLengthSelection = int.Parse(Console.ReadLine());

            return(keyLengthSelection);
        }