コード例 #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);
        }
コード例 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string str = richTextBox1.Text;

            char[] EncText = sub.EncodingText(str, key);
            string Encod   = new string(EncText);

            richTextBox2.Text = Encod;
        }