Exemplo n.º 1
0
        public double CalculateFitness(string cipherText)
        {
            double             fitness   = 0;
            SubstitutionCipher cipher    = new SubstitutionCipher();
            string             decrypted = cipher.Decrypt(cipherText, Key);
            //var trigramCounts = new FrequenciesCalculation();

            var decrTrigramCounts = FrequenciesCalculation.getTrigramCounts(decrypted);

            foreach (var trigram in decrTrigramCounts.Keys)
            {
                double defTrigramCount = FrequenciesCalculation.getCount(trigram);
                if (defTrigramCount != 0)
                {
                    fitness += decrTrigramCounts[trigram] * Math.Log(defTrigramCount, 2.0);
                }
            }

            return(fitness);
        }
Exemplo n.º 2
0
        public void SimulationStart()
        {
            FrequenciesCalculation frequenciesCalculation = new FrequenciesCalculation();

            FrequenciesCalculation.PopulateDefTrigramCounts();

            Pool pool1 = new Pool(PoolSize, EncryptedText);

            pool1.CreateInitialPool();
            Pool pool2 = new Pool(PoolSize, EncryptedText);

            pool2.CreateInitialPool();

            pool1.EnsureDistinctPool();
            pool2.EnsureDistinctPool();

            gen.CreateFirstGeneration(pool1, pool2);
            gen.EnsureDistinctPools();
            gen.GenerationSample[0].PossibleKeys.Sort(ComparatorForSorting);
            gen.GenerationSample[1].PossibleKeys.Sort(ComparatorForSorting);
        }