Exemplo n.º 1
0
        public void DecodeTestEng()
        {
            string text     = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            string expected = "ZYXWVUTSRQPONMLKJIHGFEDCBA";

            ICipher cipher = new Atbash();
            string  actual = cipher.Decode(text);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 2
0
        public void EncodeTestMixed()
        {
            string text     = "ZYX123cbaщЩщ";
            string expected = "ABC123xyzжЖж";

            ICipher cipher = new Atbash();
            string  actual = cipher.Encode(text);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 3
0
        public void DecodeTestRus()
        {
            string text     = "ЯЮЭЬЫЪЩШЧЦХФУТСРПОНМЛКЙИЗЖЕДГВБА";
            string expected = "АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ";

            ICipher cipher = new Atbash();
            string  actual = cipher.Decode(text);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 4
0
        public void Multigraph_AtbashTest()
        {
            Atbash atbash = new Atbash(Utility.KeyedEnglishAlphabet("KRYPTOS").ToStringArray());

            for (int i = 0; i < 25; i++)
            {
                generated = atbash.GenerateRandomLetters();

                cipher = atbash.Encrypt(generated);
                clear  = atbash.Decrypt(cipher);

                CollectionAssert.AreEqual(generated, clear);
            }
        }
Exemplo n.º 5
0
    static void Main(string[] args)
    {
        Console.WriteLine("Атбаш шифрование");
        var atbash = new Atbash();

        Console.Write("Введите текст сообщения: ");
        var message          = Console.ReadLine();
        var encryptedMessage = atbash.Encrypt(message);

        Console.WriteLine("Зашифрованное сообщение: {0}", encryptedMessage);
        var decryptedMessage = atbash.Decrypt(encryptedMessage);

        Console.WriteLine("Расшифрованное сообщение: {0}", decryptedMessage);
        Console.ReadLine();
    }
Exemplo n.º 6
0
        public void Unigraph_AtbashTest()
        {
            Atbash atbash = new Atbash(Utility.KeyedEnglishAlphabet("KRYPTOS"));

            cipher    = "";
            clear     = "";
            generated = "";
            for (int i = 0; i < 25; i++)
            {
                generated = atbash.GenerateRandomString();

                cipher = atbash.Encrypt(generated);
                clear  = atbash.Decrypt(cipher);

                Assert.AreEqual(generated, clear);
            }
        }
Exemplo n.º 7
0
        public void cipher_test2()
        {
            Caesar.set_key(5, 123);
            Vigenere.set_key("FBI", 123);
            Atbash.set_key(123);
            Caesar   c2 = new Caesar();
            Vigenere v2 = new Vigenere();
            Atbash   a  = new Atbash();

            string t = "Hi bob";

            Assert.IsTrue(t == c2.decrypt(c2.encrypt(t)));
            Assert.IsTrue(t == v2.decrypt(v2.encrypt(t)));
            Assert.IsTrue(t == a.decrypt(a.encrypt(t)));
            t = "Not yet";
            Assert.IsTrue(t == c2.decrypt(c2.encrypt(t)));
            Assert.IsTrue(t == v2.decrypt(v2.encrypt(t)));
            t = "The American Dream is a national ethos of the United States";
            Assert.IsTrue(t == c2.decrypt(c2.encrypt(t)));
            Assert.IsTrue(t == v2.decrypt(v2.encrypt(t)));
            t = "just test it";
            Assert.IsTrue(t == c2.decrypt(c2.encrypt(t)));
            Assert.IsTrue(t == v2.decrypt(v2.encrypt(t)));
        }
Exemplo n.º 8
0
 public string Encodes_words_using_atbash_cipher(string words)
 {
     return(Atbash.Encode(words));
 }
Exemplo n.º 9
0
 public void Encodes_words_using_atbash_cipher(string words, string expected)
 {
     Assert.Equal(expected, Atbash.Encode(words));
 }
Exemplo n.º 10
0
        private ICipher GetCipherObject(bool crack)
        {
            ICipher cipher;

            switch (CipherWindowProperties.Cipher)
            {
            case CipherWindowProperties.CipherType.ATBASH:
                cipher = new Atbash();
                break;

            case CipherWindowProperties.CipherType.ROT13:
                cipher = new Rot13();
                break;

            case CipherWindowProperties.CipherType.CAESAR:
                if (crack)
                {
                    cipher = new Caesar('A');
                    break;
                }
                if (textBoxKey1.Text.Length != 1)
                {
                    MessageBox.Show("Key 1 is invalid: length must be 1.", "Invalid Key");
                    throw new InvalidOperationException();
                }
                cipher = new Caesar(new string(textBoxKey1.Text[0], 1).ToUpper()[0]);
                break;

            case CipherWindowProperties.CipherType.AFFINE:
                if (crack)
                {
                    cipher = new Affine(1, 1);
                    break;
                }
                int a, b;
                try
                {
                    a = Convert.ToInt32(textBoxKey1.Text);
                }
                catch
                {
                    MessageBox.Show("Key 1 is invalid: must be an integer.", "Invalid Key");
                    throw new InvalidOperationException();
                }
                try
                {
                    b = Convert.ToInt32(textBoxKey2.Text);
                }
                catch
                {
                    MessageBox.Show("Key 2 is invalid: must be an integer.", "Invalid Key");
                    throw new InvalidOperationException();
                }
                if (Util.ModInverse(a, 26) == -1 || a < 1 || a > 26)
                {
                    MessageBox.Show("Key 1 is invalid: it must be an odd number that is not 13, and between 0 and 26.", "Invalid Key");
                    throw new InvalidOperationException();
                }
                if (b < 1 || b > 26)
                {
                    MessageBox.Show("Key 2 is invalid: it must be between 0 and 26.", "Invalid Key");
                    throw new InvalidOperationException();
                }
                cipher = new Affine(Convert.ToInt32(textBoxKey1.Text), Convert.ToInt32(textBoxKey2.Text));
                break;

            default:
                return(null);
            }

            return(cipher);
        }
Exemplo n.º 11
0
 public IActionResult at_encrypt(Atbash at)
 {
     at.encrypt(Request.Form["plaintext"]);
     return(View("Atbash", at));
 }
Exemplo n.º 12
0
        public IActionResult Atbash()
        {
            Atbash at = new Atbash();

            return(View("Atbash", at));
        }