Ejemplo n.º 1
0
 public void CalcRKN()
 {
     k  = Xk.Count();
     r  = (int)Math.Ceiling(Math.Log(k, 2) + 1);
     n  = k + r;
     Gx = GetPolynom(r);
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            bool[]   Xk, Yk, Xr, Xn, Yn, Yr_, Yr, S, YnDecrypted;
            bool[][] H;
            int      r = 0, k = 0;
            bool     isCode, isModifyied = false;

            try
            {
                for (;;)
                {
                    Console.WriteLine("Vvedi slovo");
                    Xk = EnterWord(true, out isCode);
                    r  = CalcR(Xk);
                    k  = Xk.Count();
                    Console.WriteLine("Would u like  2 use modifyied Hemming code?(y/n)");
                    if (Console.ReadKey(true).KeyChar == 'y')
                    {
                        isModifyied = true;
                        r          += 1;
                    }
                    Encrypt(r, k, Xk, isModifyied, out H, out Xr, out Xn);
                    Console.WriteLine("H:");
                    printM(H);
                    PrintAnswer(Xn, Xk, Xr, 'X');
                    Console.WriteLine("Input Yn");
                    YnDecrypted = Decrypt(r, k, isCode, isModifyied, Xn, Xk, Xr, out Yn, out Yk, out Yr, out Yr_, out S);
                    PrintAnswer(Yn, Yk, Yr, 'Y');
                    Console.WriteLine("Yr':");
                    printM(Yr_);
                    Console.WriteLine("S:");
                    printM(S);
                    // isCode = true;
                    if (isCode)
                    {
                        Console.WriteLine("Corrected Yn:");
                        printM(YnDecrypted);
                    }
                    else
                    {
                        bool[] _Yk = new bool[k];
                        for (int i = 0; i < k; i++)
                        {
                            _Yk[i] = YnDecrypted[i];
                        }
                        Console.WriteLine("Corrected Yk:" + BinToWord(_Yk));
                    }
                }
            }
            catch (IndexOutOfRangeException e)
            {
                Console.WriteLine(e.Message + '\n' + e.Source + '\n' + e.StackTrace);
                Program.Main(new string[] { });
            }
        }