Beispiel #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);
        }
Beispiel #2
0
        public string DecodeByKey(string encriptedText)
        {
            SubstitutionCipher decoder = new SubstitutionCipher();

            return(decoder.Decrypt(encriptedText, Key));
        }