public void DecodeSSC(string input, string startState, string taps, string output)
        {
            synchronousStreamCipher = new SynchronousStreamCipher(startState, taps);
            var result = synchronousStreamCipher.Decrypt(input);

            Assert.AreEqual(output, result);
        }
示例#2
0
        private void SSCDecode(object sender, RoutedEventArgs e)
        {
            string seed       = SSCSeedDecodeInput.Text;
            string polynomial = SSCPolynomialDecodeInput.Text;
            string word       = SSCDecodeInput.Text;
            SynchronousStreamCipher cipher = new SynchronousStreamCipher(seed, polynomial);

            SSCDecodeOutput.Text = cipher.Decrypt(word);
        }
示例#3
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            string _seed                = seed.Text;
            string _polynominal         = polynominal.Text;
            string _inputfile           = inputfile.Text;
            string _outputfile          = outputfile.Text;
            SynchronousStreamCipher SSC = new SynchronousStreamCipher(_seed, _polynominal);

            SSC.Encrypt(_inputfile, _outputfile);
        }
示例#4
0
        public void DecryptTest()
        {
            List <bool> key = new List <bool> {
                true, false, false, false, true, false, true, true, true
            };
            string input    = "encrypted_ssc.bin";
            string expected = "00101110101001101100111000101110";

            SynchronousStreamCipher ssc = new SynchronousStreamCipher(key);
            PrivateObject           obj = new PrivateObject(ssc);

            BitArray output        = ssc.Decrypt(input);
            string   output_string = Convert.ToString(obj.Invoke("BitArrayToString", output));

            Assert.AreEqual(output_string, expected);
        }
示例#5
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
            {
            }
        }
示例#6
0
        static void Main(string[] args)
        {
            string[] userInputStrings = new string[3];

            while (true)
            {
                string option = "_";

                Console.WriteLine("1. LSFRGenerator\n" +
                                  "2. Synchronous Steam Cipher\n" +
                                  "3. Ciphertext Autokey\n" +
                                  "4. Exit");
                Console.Write("Option: ");
                option = Console.ReadLine();


                switch (option[0])
                {
                case '1':
                {
                    userInputStrings = AskForUserInput(false);
                    LSFRGenerator lsfr = new LSFRGenerator(userInputStrings[0],
                                                           userInputStrings[1],
                                                           int.Parse(userInputStrings[2]));

                    string[] output = lsfr.Generate();

                    Console.WriteLine("Generated codes: ");
                    foreach (var item in output)
                    {
                        Console.WriteLine(item);
                    }

                    Console.WriteLine("\nPress any key to continue.");
                    Console.ReadKey(true);
                }
                break;

                case '2':
                {
                    userInputStrings = AskForUserInput(true);
                    SynchronousStreamCipher ssc = new SynchronousStreamCipher(userInputStrings[0],
                                                                              userInputStrings[1],
                                                                              userInputStrings[2]);

                    string output = ssc.Encipher();

                    Console.WriteLine("Enciphered output: " + output);

                    Console.WriteLine("\nDeciphering:");
                    userInputStrings = AskForUserInput(true);
                    ssc = new SynchronousStreamCipher(userInputStrings[0],
                                                      userInputStrings[1],
                                                      userInputStrings[2]);

                    output = ssc.Encipher();

                    Console.WriteLine("Deciphered output: " + output);

                    Console.WriteLine("\nPress any key to continue.");
                    Console.ReadKey(true);
                }
                break;

                case '3':
                {
                    userInputStrings = AskForUserInput(true);
                    CiphertextAutokey cta = new CiphertextAutokey(userInputStrings[0],
                                                                  userInputStrings[1],
                                                                  userInputStrings[2]);

                    string output = cta.Encipher();

                    Console.WriteLine("Enciphered output: " + output);

                    Console.WriteLine("\nDeciphering:");
                    userInputStrings = AskForUserInput(true);
                    cta = new CiphertextAutokey(userInputStrings[0],
                                                userInputStrings[1],
                                                userInputStrings[2]);

                    output = cta.Decipher();

                    Console.WriteLine("Deciphered output: " + output);

                    Console.WriteLine("\nPress any key to continue.");
                    Console.ReadKey(true);
                }
                break;

                case '4':
                    return;

                default:
                    break;
                }
            }
        }