public void PlayfairTestEnc4()
        {
            PlayFair algorithm = new PlayFair();
            string   cipher    = algorithm.Encrypt(largePlain, largeKey);

            Assert.IsTrue(cipher.Equals(largeCipher, StringComparison.InvariantCultureIgnoreCase));
        }
        public void PlayfairTestNewDec()
        {
            PlayFair algorithm = new PlayFair();
            string   plain     = algorithm.Decrypt(newCipher, newKey);

            Assert.IsTrue(plain.Equals(newPlain, StringComparison.InvariantCultureIgnoreCase));
        }
        public void PlayfairTestDec2()
        {
            PlayFair algorithm = new PlayFair();
            string   plain     = algorithm.Decrypt(mainCipher1, mainKey1);

            Assert.IsTrue(plain.Equals(mainPlain1, StringComparison.InvariantCultureIgnoreCase));
        }
Beispiel #4
0
        private static string Cipher(string input, bool encipher)
        {
            string aux    = string.Empty;
            string retVal = string.Empty;

            CesarCypher _cesar      = new CesarCypher();
            PlayFair    _playerFair = new PlayFair();

            if (encipher)
            {
                for (int i = 0; i < numberOfEncipher; i++)
                {
                    aux = _cesar.Encipher(input, cesarKey);
                    aux = _playerFair.Encipher(input, playerFairKey);
                }
            }
            else
            {
                for (int i = 0; i < numberOfEncipher; i++)
                {
                    aux = _cesar.Decipher(input, cesarKey);
                    aux = _playerFair.Decipher(input, playerFairKey);
                }
            }
            retVal = aux;
            return(retVal);
        }
Beispiel #5
0
        private void button17_Click(object sender, EventArgs e)
        {
            PlayFair playfair = new PlayFair();
            string   result   = playfair.Decrypt(PlayFairCTBox.Text, PalyFairKeyBox.Text);

            PlayFairPTBox.Text = result;
        }
        public void PlayfairTestNewEnc()
        {
            PlayFair algorithm = new PlayFair();
            string   cipher    = algorithm.Encrypt(newPlain, newKey);

            Console.WriteLine(cipher);
            Assert.IsTrue(cipher.Equals(newCipher, StringComparison.InvariantCultureIgnoreCase));
        }
Beispiel #7
0
        public void PlayfairTestEnc3()
        {
            PlayFair algorithm = new PlayFair();
            string   cipher    = algorithm.Encrypt(mainPlain2, mainKey2);

            Assert.IsTrue(cipher.Equals(mainCipher2, StringComparison.InvariantCultureIgnoreCase) ||
                          cipher.Equals(mainCipher22, StringComparison.InvariantCultureIgnoreCase));
        }
        public void PlayfairTestDec4()
        {
            PlayFair algorithm = new PlayFair();
            string   plain     = algorithm.Decrypt(largeCipher, largeKey);

            Console.WriteLine(largePlain);
            Assert.IsTrue(plain.Equals(largePlain, StringComparison.InvariantCultureIgnoreCase));
        }
Beispiel #9
0
        public void PlayfairTestBonusAnalysis()
        {
            PlayFair algorithm = new PlayFair();
            string   plain     = algorithm.Analyse(largeCipher);
            int      count     = Enumerable.Range(0, largePlainForAnlysis.Length)
                                 .Count(i => largePlainForAnlysis[i] == plain[i]);

            Assert.IsTrue(count * 100 / largePlain.Length > 50);
        }
Beispiel #10
0
 private void PlayFairDecryptClick(object sender, EventArgs e)
 {
     try
     {
         if (string.IsNullOrWhiteSpace(textBoxPlayFairkey.Text))
         {
             MessageBox.Show("Introduceti cheia!", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         if (string.IsNullOrEmpty(textBoxPlayFairInput.Text))
         {
             MessageBox.Show("Introduceti mesajul de decriptat!", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         var crypto = new PlayFair(textBoxPlayFairkey.Text);
         textBoxPlayFairOutput.Text = crypto.Decrypt(textBoxPlayFairInput.Text);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Beispiel #11
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (comboBox1.Text.Contains("Ceaser"))
     {
         Ceaser c   = new Ceaser();
         string Res = c.Encrypt(textBox1.Text.ToString(), int.Parse(textBox3.Text.ToString()));
         textBox4.Text = Res;
     }
     else if (comboBox1.Text.Contains("Monoalphabetic"))
     {
         Monoalphabetic c   = new Monoalphabetic();
         string         Res = c.Encrypt(textBox1.Text.ToString(), textBox3.Text.ToString());
         textBox4.Text = Res;
     }
     else if (comboBox1.Text.Contains("Columnar"))
     {
         Columnar   c   = new Columnar();
         List <int> key = new List <int>();
         for (int i = 0; i < textBox3.Text.Length; i++)
         {
             key.Add(int.Parse(textBox3.Text[i].ToString()));
         }
         string Res = c.Encrypt(textBox1.Text.ToString(), key);
         textBox4.Text = Res;
     }
     else if (comboBox1.Text.Contains("HillCipher"))
     {
         HillCipher c          = new HillCipher();
         List <int> key1       = new List <int>();
         List <int> Plaintext1 = new List <int>();
         string     Res        = "";
         List <int> ResDig     = new List <int>();
         if (char.IsDigit(textBox3.Text[0]) && char.IsDigit(textBox1.Text[0]))
         {
             for (int i = 0; i < textBox1.Text.Length; i++)
             {
                 Plaintext1.Add(int.Parse(textBox1.Text[i].ToString()));
             }
             for (int i = 0; i < textBox3.Text.Length; i++)
             {
                 key1.Add(int.Parse(textBox3.Text[i].ToString()));
             }
             ResDig        = c.Encrypt(Plaintext1, key1);
             textBox4.Text = ResDig.ToString();
         }
         else
         {
             Res           = c.Encrypt(textBox1.Text.ToString(), textBox3.Text.ToString());
             textBox4.Text = Res;
         }
     }
     else if (comboBox1.Text.Contains("PlayFair"))
     {
         PlayFair c   = new PlayFair();
         string   Res = c.Encrypt(textBox1.Text.ToString(), textBox3.Text.ToString());
         textBox4.Text = Res;
     }
     else if (comboBox1.Text.Contains("RailFence"))
     {
         RailFence c   = new RailFence();
         string    Res = c.Encrypt(textBox1.Text.ToString(), int.Parse(textBox3.Text.ToString()));
         textBox4.Text = Res;
     }
     else if (comboBox1.Text.Contains("RepeatingKeyVigenere"))
     {
         RepeatingkeyVigenere c = new RepeatingkeyVigenere();
         string Res             = c.Encrypt(textBox1.Text.ToString(), textBox3.Text.ToString());
         textBox4.Text = Res;
     }
     else if (comboBox1.Text.Contains("AutokeyVigenere"))
     {
         AutokeyVigenere c   = new AutokeyVigenere();
         string          Res = c.Encrypt(textBox1.Text.ToString(), textBox3.Text.ToString());
         textBox4.Text = Res;
     }
     else if (comboBox1.Text.Contains("RSA"))
     {
         RSA      c   = new RSA();
         string   s   = textBox1.Text.ToString();
         string[] str = s.Split(' ');
         int      p   = int.Parse(str[0]);
         int      q   = int.Parse(str[1]);
         int      M   = int.Parse(str[2]);
         int      ee  = int.Parse(str[3]);
         int      Res = c.Encrypt(p, q, M, ee);
         textBox4.Text = Res.ToString();
     }
     else if (comboBox1.Text.Contains("AES"))
     {
         AES    c   = new AES();
         string Res = c.Encrypt(textBox1.Text.ToString(), textBox3.Text.ToString());
         textBox4.Text = Res;
     }
     else if (comboBox1.Text.Contains("MD5"))
     {
         MD5    c   = new MD5();
         string Res = c.GetHash(textBox1.Text.ToString());
         textBox4.Text = Res;
     }
 }
Beispiel #12
0
        static void Main(string[] args)
        {
            string filePath = V;

            PlayFair         _playFair   = new PlayFair();
            Dictionary       _dictionary = new Dictionary();
            Stopwatch        sw          = new Stopwatch();
            List <TestFiles> results     = new List <TestFiles>();
            var csv = new StringBuilder();

            _dictionary.CreateDic();

            Console.WriteLine("Dictionary with " + _dictionary.Dic.Count);

            //string cypherText = "UhtohkmrmitrrbtupclZ";

            string cypherText = "EIBZSGTLQPLVOMVTMORFTAOCVCAKETZGTOLTISAKTOQRIQXDHOIOOKPWNWQRIQCLHKZGQAQTQPAKRTKSAKLTKAQISCRESIVYOVOGKHVQASNWTIHOIVISEVTQXNQPZGPWNWNPBVMFREQTOCIWLTICDXFQPOTOIOLTSVPCWVOGPOOMFRERIWTQLTQFARERITRCPQVRDKLCLFETSVTLTVINCPROAKLTKARTNYRYVYOVPNNWXDPQAKTIVQVTZHVWASDKFLVUASITNZKGFLVUASVWASDXREEOYVITICKSECWONWVENCTEIWTOTFVUCRFYYVQAOGAKSRQCOIREOCTOOMKZITMOCTIESVRYTLCONONASIQWQTNSYVVRHGTLIWSVNWTOWVISEVVQCWROSWOPHOVEWOASITNOWIVCPCLCLFETOBRERCOIEIVQVERYTQVTMKAEQAPQVQVRVTWBPCMAWOZGQARXKAALTOBXTOINERPGRVREFRFRZHTORYVRLFKARCSITYFRTCPNASFR1869OVHKUNVCFQIEBICIRERCAFRVZHFUAMUNVWONQTPZQTSVRTNYRVAPVOOPPTKKPNRQAPNQTEPNTETOQIVTKAPQPNNZOCFAADRCTVETQTSVPNIWSVPNFLWHCISIORUNRCWCWITLMATEOWQPAPSUTRHKCSNPSUTRHKCSNTTECRFRFYYVOVNINWATICEVTOQVITPUUVOBOWOTDWDATQFANYAFINAHROVQALERARZHCINVAHUNTIHWCRVEMOVTAFPOZGVOVTVRWIPOZGVOVTTVCWVEMOVTNYFQTANWZHCRNYFQQFQGLAMOCRYHAMITINERCOSVTEICIEETZGRTSBVQINOTKCTROPCKOGXVNPNYRQAPLFAKWVFVKARCTLHOIVIWARANNSYVWIPOLVFAZGTQLTZNQTUNPATQANNQPCALPGMWTEIWKZHKCSNYTROVVZETWTORETFATQVRADINERPBWCQRDKCODRETORERATKFVYKGPNITMOFVKYIQOGRECIVTETNSYVVTHIPOERCPVIZHVOKCRCRYTQVTRENPHGAKQAZGTOCSVRPGWIVYEOYVKYIENOVBVQQTOGXVTONYAFNCETISTWYHIWISZHDARQFLVUTEAQVZCPMONPTRCPADVXRTITNYFQLVAPTROVVZETWTTOITMOHOAMITQTSVERUNTOVZCPMONPVYSZVHMKLTIQVBPACWOPPZNPKMHYZGETCLOVCP";


            sw.Start();
            Parallel.ForEach(
                _dictionary.Dic,
                (currentWord) =>
            {
                string plainText  = _playFair.Decipher(cypherText, currentWord);
                int numberOfWords = 0;
                for (int i = 0; i < _dictionary.Dic.Count; i++)
                {
                    if (plainText.Contains(_dictionary.Dic[i].ToUpper().Trim()))
                    {
                        numberOfWords++;
                    }
                }
                if (numberOfWords > 0)
                {
                    TestFiles _test = new TestFiles(numberOfWords, currentWord);
                    var newLine     = string.Format("{0} , {1} ", currentWord, numberOfWords);
                    csv.AppendLine(newLine);
                    results.Add(_test);
                }
            }
                );

            sw.Stop();

            File.WriteAllText(filePath, csv.ToString());

            if (results.Count == 0)
            {
                Console.WriteLine("Nao existe palavras chaves que possa quebrar no dicionario");
            }
            else
            {
                TestFiles _bestFileGuess = results[0];
                for (int i = 0; i < results.Count; i++)
                {
                    if (results[i].NumberOfWords > _bestFileGuess.NumberOfWords)
                    {
                        _bestFileGuess = results[i];
                    }
                }
                Console.WriteLine("Executou a busca em ={0}", sw.Elapsed);
                Console.WriteLine("a palavra que teve melhor desempenho foi :" + _bestFileGuess.Word);
                Console.WriteLine("Texto resultante : " + _playFair.Decipher(cypherText, _bestFileGuess.Word));
            }

            Console.ReadKey(true);
        }