示例#1
0
        public TableAdjacentClasses(int n, int k)
        {
            binaryArythmetic = new BinaryArythmetic();
            EvenParity evenParity = new EvenParity();

            table = new string[(int)Math.Pow(2, k), (int)Math.Pow(2, n - k)];
            List <string> allCombinationForK = binaryArythmetic.GenerateAllBinaryByLength(k);
            List <string> allCombinationForN = binaryArythmetic.GenerateAllBinaryByLength(n);

            for (int j = 0; j < table.GetLength(1); ++j)
            {
                string value = allCombinationForK[j];
                while (value.Length < n)
                {
                    value += evenParity.GetEven(value);
                }
                table[0, j] = value;
                allCombinationForN.RemoveAt(allCombinationForN.IndexOf(value));
            }
            for (int i = 1; i < table.GetLength(0); ++i)
            {
                table[i, 0] = GetElementWithMinWeight(allCombinationForN);
                allCombinationForN.RemoveAt(allCombinationForN.IndexOf(table[i, 0]));
                for (int j = 1; j < table.GetLength(1); ++j)
                {
                    string element = binaryArythmetic.Xor(table[0, j], table[i, 0]);
                    table[i, j] = element;
                    allCombinationForN.RemoveAt(allCombinationForN.IndexOf(element));
                }
            }
        }
示例#2
0
文件: FormMain.cs 项目: SheldiA/tk1
        private void bt_do_Click(object sender, EventArgs e)
        {
            rtb_allError.Text = "";
            BinaryArythmetic binaryArythmetic = new BinaryArythmetic();
            Code             code             = codeAlgorithmFactory.GetCodeAlgorithm(cb_chooseCode.Text, Int32.Parse(tb_n.Text));
            string           codeWord         = code.GetCodeWord(rtb_message.Text);
            List <string>    allChanges       = binaryArythmetic.GenerateAllBinaryByLength(codeWord.Length);

            foreach (String element in allChanges)
            {
                rtb_allError.Text += (binaryArythmetic.Xor(codeWord, element) + '\n');
            }
        }