public void TestCezar()
        {
            string tested   = "SEND MORE MONEY";
            string expected = "HZBY TCGZ TCBZS";

            Assert.AreEqual(expected, cezar.Encrypt(tested));
            Assert.AreEqual(tested, cezar.Decrypt(expected));
        }
Esempio n. 2
0
        public void ReturnsEncryptedWord()
        {
            string input    = "CRYPTOGRAPHY";
            string expected = "FUBSWRJUDSKB";

            Cezar cezar = new Cezar(3);

            string encrypted = cezar.Encrypt(input);

            Assert.AreEqual(expected, encrypted);
        }
Esempio n. 3
0
        void makeCezar()
        {
            if (textBox.Text != "" & keyBox.Text != "" && keyWordBox.Text != "")
            {
                try
                {
                    Cezar cezar = new Cezar(keyWordBox.Text, Convert.ToByte(keyBox.Text), language);
                    alphabetBox.Text = cezar.alphabetString;

                    codedTextBox.Text   = cezar.Encrypt(textBox.Text);
                    decodedTextBox.Text = cezar.Decrypt(codedTextBox.Text);
                    entropyBox.Text     = Entropy.Calculate(textBox.Text).ToString();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Esempio n. 4
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
            {
            }
        }