Exemple #1
0
        double GetFitness(Chromosome a, char[] key, string s)
        {
            Substitution sub1   = new Substitution();
            FileStream   stream = new FileStream("myDictionary1.txt", FileMode.Open);
            StreamReader reader = new StreamReader(stream);
            string       str    = reader.ReadToEnd();

            stream.Close();
            string firsttext = s;

            str = s + str;
            string[] words      = str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            char[]   encText    = sub1.EncodingText(firsttext, key);
            char[]   GotText    = sub1.DecodingText(encText, this.gens);
            string   GotTextStr = new string(GotText);

            string[] words2     = GotTextStr.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            int      knownwords = 0;

            for (int x = 0; x < words2.Length; x++)
            {
                for (int y = 0; y < words.Length; y++)
                {
                    if (words2[x] == words[y])
                    {
                        knownwords++;
                        break;
                    }
                }
            }
            double result = 100 * (words2.Length - knownwords) / words2.Length;

            return(result);
        }
Exemple #2
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            string str = richTextBox1.Text;

            char[] res   = this.go(key, str);
            string Decod = new string(res);

            char[] check = richTextBox2.Text.ToCharArray();
            char[] rs    = sub.DecodingText(check, res);
            string fin   = new string(rs);

            richTextBox3.Text = fin;
            for (int i = 0; i < tb2.Length; i++)
            {
                tb2[i].Text = " " + Decod[i].ToString();
            }
        }