Exemple #1
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);
        }
Exemple #2
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);
        }