Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            var IP = new Encoder();

            int m = 7;

            //матрица-ключ
            string[,] G = new string[5, 5];/* { {"A", "B", "C", "D", "E" },
                                           *  {"F", "G", "H", "I", "K" },
                                           *  {"L", "M", "N", "O", "P" },
                                           *  {"Q", "R", "S", "T", "U" },
                                           *  {"V", "W", "X", "Y", "Z" }, };*/
            string[] alph = new string[25] {
                "A", "B", "C", "D", "E", "F", "G", "H", "I", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
            };

            string[] inw  = new string[m]; //входное слово
            string[] key  = new string[m]; //ключ
            string[] outw = new string[m]; //выходное слово


            inw = IP.Read("DInput.txt");
            for (int i = 0; i < inw.Length; i++)
            {
                textBox1.Text += inw[i] + " ";
            }

            key  = IP.Read("Key.txt");
            G    = IP.Key_Gen(key, alph);
            outw = IP.Decode(inw, G);
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    richTextBox1.Text += G[i, j] + " ";
                }
                richTextBox1.Text += Environment.NewLine;
            }

            for (int i = 0; i < outw.Length; i++)
            {
                textBox2.Text += outw[i] + " ";
            }
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            var IP = new Encoder();

            int       m  = 7; // число символов в алфавите
            int       dw = 5; // число символов в слове
            const int N  = 32;

            string[] alph = new string[N] {
                "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"
            };
            string[] bin = new string[N] {
                "00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111", "01000", "01001", "01010", "01011", "01100", "01101", "01110", "01111", "10000", "10001", "10010", "10011", "10100", "10101", "10110", "10111", "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111"
            };
            string[] erp = new string[9] {
                "0101", "1011", "1100", "0110", "0011", "1000", "0100", "0010", "0001"
            };
            int[,] G = new int[5, 9] {
                { 1, 0, 0, 0, 0, 0, 1, 0, 1 },
                { 0, 1, 0, 0, 0, 1, 0, 1, 1 },
                { 0, 0, 1, 0, 0, 1, 1, 0, 0 },
                { 0, 0, 0, 1, 0, 0, 1, 1, 0 },
                { 0, 0, 0, 0, 1, 0, 0, 1, 1 }
            };

            int[,] Ht = new int[9, 4] {
                { 0, 1, 0, 1 },
                { 1, 0, 1, 1 },
                { 1, 1, 0, 0 },
                { 0, 1, 1, 0 },
                { 0, 0, 1, 1 },
                { 1, 0, 0, 0 },
                { 0, 1, 0, 0 },
                { 0, 0, 1, 0 },
                { 0, 0, 0, 1 },
            };

            string[] inw = new string[dw]; //входное слово
            string[] fxw = new string[dw]; //исправленное входное слово

            var sep = new char[] { ' ' };

            string[] binalph = new string[m];
            string   bs      = "";
            string   fl      = "";

            binalph = IP.Bicode(bin, G);

            inw = IP.Read("DInput.txt");

            fl = IP.Errors(alph, inw, binalph);

            fxw = IP.Fix(erp, inw, Ht);

            bs = IP.Decode(alph, fxw, binalph);

            for (int i = 0; i < binalph.Length; i++)
            {
                richTextBox1.Text += alph[i] + ": " + bin[i] + ": " + binalph[i] + Environment.NewLine;
            }

            for (int i = 0; i < inw.Length; i++)
            {
                textBox1.Text += inw[i] + " ";
            }

            textBox2.Text = bs;
            textBox3.Text = fl;
            for (int i = 0; i < fxw.Length; i++)
            {
                textBox4.Text += fxw[i] + " ";
            }
        }
Example #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            var IP = new Encoder();

            int m  = 7;                     // число символов в алфавите
            int dw = 5;                     // число символов в слове

            double[] p1   = new double[m];  //распределение
            double[] q    = new double[m];  //кумулятивная вероятность
            double[] sigm = new double[m];  //кодировка в десятичной форме
            string[] alp  = new string[m];  //алфавит слов
            string[] alph = new string[m];  //кодировка в двоичной форме
            string[] en   = new string[m];  // алфавит кодов
            string[] inw  = new string[dw]; //входное слово
            int[]    wl   = new int[m];
            string   bf   = "";
            string   buf  = "";
            var      sep  = new char[] { ' ' };

            if (radioButton1.Checked)
            {
                p1 = IP.ReadArray("P1.txt");
            }
            if (radioButton2.Checked)
            {
                p1 = IP.ReadArray("P2.txt");
            }
            if (radioButton3.Checked)
            {
                p1 = IP.ReadArray("Rav.txt");
            }

            alp = IP.Read("ALP.txt");
            inw = IP.Read("DInput.txt");
            for (int i = 0; i < inw.Length; i++)
            {
                buf += inw[i];
                buf += " ";
            }
            textBox1.Text = buf;

            q    = IP.Cumul_Prob(p1, m);
            sigm = IP.Alphabet(m, p1, q);
            wl   = IP.Words_len(p1, m);
            alph = IP.TenToBin(wl, sigm, m);

            bf = IP.Decode(alp, inw, alph);
            var st1 = bf.Split(sep, StringSplitOptions.RemoveEmptyEntries);

            string[] t = new string[st1.Length];
            for (int i = 0; i < st1.Length; i++)
            {
                t[i] = st1[i];
            }
            IP.Write("DOutput.txt", t);
            textBox2.Clear();
            textBox2.Text = bf;

            textBox6.Clear();
            for (int j = 0; j < m; j++)
            {
                // Вывод закодированного алфавита
                textBox6.Text += alp[j].ToString() + ": " + alph[j].ToString() + Environment.NewLine;
            }
        }