Ejemplo n.º 1
0
        public void VigenereEncrypt_CorrectData_ReturnList()
        {
            var text = new string[] { "QWERTY", "qwerty" };
            var key  = "test";

            var result = vigenere.Encrypt(text, key);

            result.Should().Contain("jawkmc");
        }
Ejemplo n.º 2
0
        public void EncryptBasic()
        {
            Vigenere v             = new Vigenere("PALIMPSEST", new CipherNet.Common.Alphabet("KRYPTOS"));
            var      encryptedText = v.Encrypt("BETWEENSUBTLESHADINGANDTHEABSENCEOFLIGHTLIESTHENUANCEOFIQLUSION");

            Assert.AreEqual("EMUFPHZLRFAXYUSDJKZLDKRNSHGNFIVJYQTQUXQBQVYUVLLTREVJYQTMKYRDMFD", encryptedText);
        }
Ejemplo n.º 3
0
        public void Encrypt(string source, string key, string expected)
        {
            var    crypto = new Vigenere();
            string actual = crypto.Encrypt(source, key);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            string texteClair   = null;
            string key          = null;
            string texteChiffre = null;

            Console.WriteLine("Quelle phrase voulez-vous encoder :");
            texteClair = Console.ReadLine();
            Console.WriteLine("Entrez votre clef :");
            key = Console.ReadLine();

            Vigenere vigenere = new Vigenere();

            texteChiffre = vigenere.Encrypt(texteClair, key);

            Console.WriteLine("\nTexte en claire : " + texteClair);
            Console.WriteLine("Cléf : " + key + "  ");
            Console.WriteLine("Texte chiffré : " + texteChiffre);

            texteClair = vigenere.Decrypt(texteChiffre, key);

            Console.WriteLine("\nTexte chiffré : " + texteChiffre);
            Console.WriteLine("Cléf : " + key + "  ");
            Console.WriteLine("Texte claire : " + texteClair);

            Console.Read();
        }
Ejemplo n.º 5
0
        public void Encrypt_NullKeyProvided_ThrowException()
        {
            var source = "Hello";
            var cipher = new Vigenere();

            Assert.Throws(typeof(ArgumentNullException), delegate { cipher.Encrypt(source, null); });
        }
Ejemplo n.º 6
0
        public void Encrypt_IncorrectInput_ThrowException()
        {
            var source = "Hello!";
            var key    = "key";
            var cipher = new Vigenere();

            Assert.Throws(typeof(ArgumentException), delegate { cipher.Encrypt(source, key); });
        }
Ejemplo n.º 7
0
        public void EncryptEnumerable(string[] sources, string key, string[] expected)
        {
            var crypto = new Vigenere();

            string[] actual = crypto.Encrypt(sources, key).ToArray();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 8
0
        private void VigenereEncode(object sender, RoutedEventArgs e)
        {
            Vigenere vigenere = new Vigenere();
            string   value    = VigenereEncodeInput.Text;
            string   key      = VigenereEncodeKeyInput.Text;

            VigenereEncodeOutput.Text = vigenere.Encrypt(value, key);
        }
Ejemplo n.º 9
0
        public void TestEncrypt()
        {
            IEnumerable <string> source = Program.Preprocess("ALPHA");
            string key      = "OMEGA";
            string expected = "OXTNA";
            string actual   = Vigenere.Encrypt(source, key).FirstOrDefault();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 10
0
 private void chiffrerBtn_Click(object sender, EventArgs e)
 {
     if (textBox1.TextLength != 0 || textBox2.TextLength != 0)
     {
         Vigenere vigenere = new Vigenere();
         textBox3.Text       = vigenere.Encrypt((textBox1.Text), textBox2.Text);
         chiffrerBtn.Enabled = false;
     }
 }
Ejemplo n.º 11
0
        public void Encrypt_EmptyInput_EmptyOutput()
        {
            var source    = "";
            var key       = "key";
            var cipher    = new Vigenere();
            var encrypted = cipher.Encrypt(source, key);

            Assert.IsEmpty(encrypted);
        }
Ejemplo n.º 12
0
        public void Encrypt_EmptyEnumerableInput_Empty()
        {
            var source    = new List <string>();
            var key       = "key";
            var cipher    = new Vigenere();
            var encrypted = cipher.Encrypt(source, key);

            Assert.IsEmpty(encrypted);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Performs one of the possible actions: encrypts or decrypts data.
        /// </summary>
        /// <param name="text">Data to be encrypted / decrypted.</param>
        /// <param name="key">The key for the encryption / decryption algorithm.</param>
        /// <param name="typeOfChiper">The name of the encryption / decryption algorithm.</param>
        /// <param name="action">Action to be taken (encrypt / decrypt).</param>
        /// <returns>The result of encryption / decryption.</returns>
        private static string PerformAction(string text, string key,
                                            TypesOfCiphers typeOfChiper, Model.Ciphers.Action action)
        {
            switch (typeOfChiper)
            {
            case TypesOfCiphers.RailFence:
                RailFence railFence = new RailFence();
                if (action == Model.Ciphers.Action.Encrypt)
                {
                    return(railFence.Encrypt(text, key));
                }
                else
                {
                    return(railFence.Decrypt(text, key));
                }

            case TypesOfCiphers.RotatingSquare:
                RotatingGrill rotatingSquare = new RotatingGrill();
                if (action == Model.Ciphers.Action.Encrypt)
                {
                    return(rotatingSquare.Encrypt(text));
                }
                else
                {
                    return(rotatingSquare.Decrypt(text));
                }

            case TypesOfCiphers.Vigenere:
                Vigenere vigener = new Vigenere();
                if (action == Model.Ciphers.Action.Encrypt)
                {
                    try
                    {
                        return(vigener.Encrypt(text, key));
                    }
                    catch (DivideByZeroException)
                    {
                        return(text);
                    }
                }
                else
                {
                    try
                    {
                        return(vigener.Decrypt(text, key));
                    }
                    catch (DivideByZeroException)
                    {
                        return(text);
                    }
                }

            default:
                return(null);
            }
        }
Ejemplo n.º 14
0
        public void Encrypt_CorrectInputString_CorrectEncrypted()
        {
            var source    = "Hello";
            var key       = "key";
            var cipher    = new Vigenere();
            var encrypted = cipher.Encrypt(source, key);
            var expected  = "RIJVS";

            Assert.AreEqual(expected, encrypted);
        }
Ejemplo n.º 15
0
        public void ReturnsEncryptedWordForKeyMatchingWordLength()
        {
            string input    = "CRYPTOGRAPHY";
            string expected = "DICPDPXVAZIP";

            Vigenere vigenere = new Vigenere("BREAKBREAKBR");

            string encrypted = vigenere.Encrypt(input);

            Assert.AreEqual(expected, encrypted);
        }
Ejemplo n.º 16
0
        public void ReturnsEncryptedWordForKeyShorterThanWordWithSmallLetters()
        {
            string input    = "cryptography";
            string expected = "DICPDPXVAZIP";

            Vigenere vigenere = new Vigenere("break");

            string encrypted = vigenere.Encrypt(input);

            Assert.AreEqual(expected, encrypted);
        }
Ejemplo n.º 17
0
        public void ReturnsEncryptedWordForKeyShorterThanWord()
        {
            string input    = "CRYPTOGRAPHY";
            string expected = "DICPDPXVAZIP";

            Vigenere vigenere = new Vigenere("BREAK");

            string encrypted = vigenere.Encrypt(input);

            Assert.AreEqual(expected, encrypted);
        }
Ejemplo n.º 18
0
        public void Vigenere_EncryptTest()
        {
            //Arrange
            SecurityAlgorithm target = new Vigenere("lemon");
            string            plain  = "attackatdawn";
            string            cypher = "lxfopvefrnhr";

            //Act
            string actual = target.Encrypt(plain);

            //Assert
        }
Ejemplo n.º 19
0
        public void Encrypt_CorrectInputEnumerable_CorrectEncrypted()
        {
            var source = new List <string> {
                "Hello", "Vigenere", "cipher"
            };
            var key       = "key";
            var cipher    = new Vigenere();
            var encrypted = cipher.Encrypt(source, key);
            var expected  = new List <string> {
                "RIJVS", "FMEORCBI", "MMNRIP"
            };

            CollectionAssert.AreEqual(expected, encrypted);
        }
Ejemplo n.º 20
0
        public void EncryptDencryptTest()
        {
            string source = "ФРАЗА ДЛЯ ТЕСТА";
            string key = "КЛЮЧ";
            string encrypted, dencrypted;

            Vigenere v = new Vigenere();

            encrypted  = v.Encrypt(source, key);
            dencrypted = v.Dencrypt(encrypted, key);


            Assert.AreEqual(source, dencrypted);
        }
Ejemplo n.º 21
0
        public void Unigraph_VigenereTest()
        {
            Vigenere vigenere = new Vigenere(Utility.KeyedEnglishAlphabet("KRYPTOS"));

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

                generated = vigenere.GenerateRandomString();

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

                Assert.AreEqual(generated, clear);
            }
        }
Ejemplo n.º 22
0
        private void encryptDecryptPressed(object sender, RoutedEventArgs e)
        {
            string buttonName = ((Button)sender).Name;

            string userInput = mTextBox.Text.ToString();
            string userKey   = keyTextBox.Text.ToString();

            string encrypted = "";
            string decrypted = "";

            bool normalDialog = true;

            switch (currentAlgorithm)
            {
            case "RAIL_FENCE":
                if (mTextBox.Text == "")
                {
                    MessageBox.Show("Rail fence text input is empty. Please type in something.");
                    return;
                }
                if (validateRailfenceFields(keyTextBox.Text.ToString()))
                {
                    int i = int.Parse(userKey);
                    rf        = new RailFence(i);
                    encrypted = rf.Encrypt(userInput);
                    decrypted = rf.Decrypt(userInput);
                }
                break;

            case "COLUMNAR_TRANSP":
                if (mTextBox.Text == "")
                {
                    MessageBox.Show("Columanr transp text input is empty. Please type in something.");
                    return;
                }
                int[] inputTab = parseColumnarTranspKey(userKey);
                if (validateColumnarTranspkey(inputTab))
                {
                    ct        = new ColumnarTransposition(parseColumnarTranspKey(userKey));
                    encrypted = ct.Encrypt(userInput);
                    decrypted = ct.Decrypt(userInput);
                }
                else
                {
                    return;
                }
                break;

            case "MATRIX_TRANSP":
                if (mTextBox.Text == "")
                {
                    MessageBox.Show("Matrix transp text input is empty. Please type in something.");
                    return;
                }
                if (validateMatrixTransp(userKey))
                {
                    mt        = new MatrixTransp(parseMatrixTranspKey(userKey));
                    encrypted = mt.Encrypt(userInput);
                    decrypted = mt.Decrypt(userInput);
                }
                else
                {
                    return;
                }
                break;

            case "COLUMNAR_C":
                if (mTextBox.Text == "")
                {
                    MessageBox.Show("Matrix transp version C text input is empty. Please type in something.");
                    return;
                }
                if (validateMatrixTranspVerCKey(userKey) && validateMatrixTranspVerCWord(userInput))
                {
                    ctc       = new ColumnarTranspositionC(userKey);
                    encrypted = ctc.Encrypt(userInput);
                    decrypted = ctc.Decrypt(userInput);
                }
                else
                {
                    return;
                }
                break;

            case "ViGENERE":
                if (mTextBox.Text == "")
                {
                    MessageBox.Show("Winegret text input is empty. Please type in something.");
                    return;
                }
                if (validateVinegretKey(userKey) && validateVinegretWord(userInput))
                {
                    vig       = new Vigenere(userKey);
                    encrypted = vig.Encrypt(userInput);
                    decrypted = vig.Decrypt(userInput);
                }
                else
                {
                    return;
                }
                break;

            case "CEZAR":
                if (mTextBox.Text == "")
                {
                    MessageBox.Show("Cezar text input is empty. Please type in something.");
                    return;
                }
                if (validateCezarKey(userKey) && validateCezarWord(userInput))
                {
                    int i = int.Parse(userKey);
                    cz        = new Cezar(i);
                    encrypted = cz.Encrypt(userInput);
                    decrypted = cz.Decrypt(userInput);
                }
                else
                {
                    return;
                }
                break;

            case "SYNC":
                if (syncFileName.Content.ToString() == " ")
                {
                    MessageBox.Show("SYNC file input is empty. Please type in something.");
                    return;
                }
                if (keyTextBox.Text == "")
                {
                    MessageBox.Show("SYNC key text input is empty. Please type in something.");
                    return;
                }
                if (!syncKeyGenerated)
                {
                    MessageBox.Show("SYNC key needs to be generated first, please press run and then stop button before proceeding.");
                    return;
                }
                normalDialog            = false;
                synchronousStreamCipher = new SynchronousStreamCipher(lsfrGen.GetSequence());
                TextWriter  tw                    = new StreamWriter("LFSR KEY USED.txt");
                List <bool> listOfBools           = lsfrGen.GetSequence();
                char        boolOutcome           = ' ';
                string      boolOutcomeCollection = "";
                int         ij                    = 0;
                foreach (bool b in listOfBools)
                {
                    if (b == true)
                    {
                        boolOutcome = '1';
                    }
                    else
                    {
                        boolOutcome = '0';
                    }
                    boolOutcomeCollection += boolOutcome;
                    ij++;

                    if (ij > 100)
                    {
                        ij = 0;
                        tw.WriteLine(boolOutcomeCollection);
                        boolOutcomeCollection = "";
                    }
                }
                tw.WriteLine(boolOutcomeCollection);
                tw.Close();

                if (buttonName == "encrypt")
                {
                    synchronousStreamCipher.Encrypt(syncFileName.Content.ToString());
                }
                else
                {
                    synchronousStreamCipher.Decrypt(syncFileName.Content.ToString());
                }
                MessageBox.Show("Encrypted/decrypted file is located in folder where your .exe file is ( most probably bin/debug ). You will also find text file that contains LFSR key in it there.");
                break;

            case "DES":
                if (syncFileName.Content.ToString() == " ")
                {
                    MessageBox.Show("DES file input is empty. Please type in something.");
                    return;
                }
                if (keyTextBox.Text == "")
                {
                    MessageBox.Show("DES key text input is empty. Please type in something.");
                    return;
                }
                if (!validateDesKey(userKey))
                {
                    return;
                }
                des = new DES(desKeyParsing(userKey));

                if (buttonName == "encrypt")
                {
                    des.EncryptFile(syncFileName.Content.ToString());
                }
                else
                {
                    des.DecryptFile(syncFileName.Content.ToString());
                }

                MessageBox.Show("Encrypted/decrypted file is located in folder where your .exe file is ( most probably bin/debug ).");
                break;

            default:
                break;
            }


            int length = encrypted.Length;

            outcomeLabel.FontSize = 30;
            if (length > 10)
            {
                outcomeLabel.FontSize = 20;
            }
            if (length > 20)
            {
                outcomeLabel.FontSize = 15;
            }

            if (normalDialog)
            {
                if (buttonName == "encrypt")
                {
                    if (encrypted != "")
                    {
                        outcomeTypeLabel.Content = "Encrypted:";
                    }
                    outcomeLabel.Content = encrypted;
                }
                else
                {
                    if (decrypted != "")
                    {
                        outcomeTypeLabel.Content = "Decrypted:";
                    }
                    outcomeLabel.Content = decrypted;
                }
            }
            else
            {
            }
        }
        public void EncodeVigenere(string input, string key, string output)
        {
            var result = vigenere.Encrypt(input, key);

            Assert.AreEqual(output, result);
        }
Ejemplo n.º 24
0
 private void VigenereEncrypt_Click(object sender, EventArgs e)
 {
     VigenereOutput.Text = Vigenere.Encrypt(VigenereInput.Text, VigenereKeyword.Text);
 }