예제 #1
0
        public void DoTestHelp(int paragraphCount, int letterCount, int turn)
        {
            CryptanalysisCore.Monoalphabetic cipher = new CryptanalysisCore.Monoalphabetic();

            for(int i = 0; i < paragraphCount; i++)
            {
                string par = texts.RandomParagraph(letterCount);
                string key = cipher.RandomKey();
                string ciphertext = cipher.Encrypt(par, key);
                try
                {
                    string crackKey = cipher.UnitTextFrequency(ciphertext, Form1.currentLanguage);
                    int similarity = KeySimilarity(key, crackKey);
                    success[paragraphCount * turn + i] = similarity;
                    notSuccess[paragraphCount * turn + i] = KeyNotSimilarity(key, crackKey);
                }
                catch (CryptanalysisCore.Exceptions.MatchNotFound)
                {
                    success[paragraphCount * turn + i] = -1;
                }

                progress();
            }

            done[turn] = 1;

            if (done.Sum() == Environment.ProcessorCount)
                afterFinish(String.Format("průměr: {0}, neprolomeno: {1} %, počet chybných substitucí: {2}.",
                    ((int)success.Where(x => x > -1).Average()).ToString(),
                    (int)((double)success.Where(x => x == -1).Count() / (double)success.Length * 100),
                    ((int)notSuccess.Sum()).ToString()));
        }
예제 #2
0
 public MonoTest(Action progress, Action<string> afterFinish, Texts texts)
     : base(progress, afterFinish, texts)
 {
     uniqueWords = File.ReadAllText(Storage.StatsFolderPath + "czech/" + "unique.txt").Split(' ');
     cipher = new Monoalphabetic();
 }