Exemplo n.º 1
0
        private void RefreshKey()
        {
            try
            {
                if (!IsRefreshKeyNeeded)
                {
                    return;
                }

                Cipher             = new MagicSquareCipher(new MagicSquare(KeyTextBox.Text), FillerCharTextBox.Text.First());
                IsRefreshKeyNeeded = false;

                if (Cipher.Key.IsMagic)
                {
                    MagicSquareInfoTextBlock.Text = "Квадрат магический";
                }
                else if (Cipher.Key.IsDistinct)
                {
                    MagicSquareInfoTextBlock.Text = "Квадрат не магический, но шифрование возможно";
                }
                else
                {
                    MagicSquareInfoTextBlock.Text = "Квадрат не магический, шифрование будет с ошибками";
                }
            }
            catch (Exception ex)
            {
                ExceptionMessageBox(ex);
            }
        }
Exemplo n.º 2
0
        public void Test1()
        {
            var a = new MagicSquare("2 7 6\n9 5 1\n4 3 8");

            var c = new MagicSquareCipher(a);

            const string t  = "ABCQWEZXC";
            const string ct = "BZECWAQCX";

            var ct1 = c.Crypt(t);

            Assert.AreEqual(ct, ct1);

            var t1 = c.Encrypt(ct);

            Assert.AreEqual(t, t1);
        }