Esempio n. 1
0
        public void Crack(string text, FormMainWindow wnd)
        {
            wnd.InitialiseProgressBar(1);
            wnd.SetProgressText("Step 1 of 1");

            string output = Encrypt(text);

            wnd.StepProgress();
            wnd.SetProgressText("ROT13 cipher cracked!");
            wnd.SetOutputText(output);
        }
Esempio n. 2
0
        public void Crack(string text, FormMainWindow wnd)
        {
            wnd.InitialiseProgressBar(311);

            string textRev = text.ReverseString();

            double best_score = 0.0;
            int    best_keya  = 0;
            int    best_keyb  = 0;

            for (int this_keya = 1; this_keya < 26; this_keya += 2)
            {
                if (this_keya == 13)
                {
                    continue;
                }

                for (int this_keyb = 1; this_keyb <= 26; this_keyb++)
                {
                    int i = ((this_keya - 1) / 2);
                    wnd.SetProgressText($"Step {(i > 6 ? i-1 : i)*26 + this_keyb - 1} of 311\nAttempting keys of {this_keya} and {this_keyb}...");

                    Affine cipher      = new Affine(this_keya, this_keyb);
                    string this_output = cipher.Decrypt(text);
                    double this_score  = NgramScore.MonogramScore.Score(this_output);
                    if (this_score > best_score)
                    {
                        best_score = this_score;
                        best_keya  = this_keya;
                        best_keyb  = this_keyb;
                    }

                    wnd.StepProgress();
                }
            }

            string output;

            if (
                NgramScore.QuadgramScore.Score(new Affine(best_keya, best_keyb).Decrypt(text)) >
                NgramScore.QuadgramScore.Score(new Affine(best_keya, best_keyb).Decrypt(textRev)))
            {
                output = new Affine(best_keya, best_keyb).Decrypt(text);
            }
            else
            {
                output = new Affine(best_keya, best_keyb).Decrypt(textRev);
            }

            wnd.SetOutputText(output.ToLower());
        }
Esempio n. 3
0
        public void Crack(string text, FormMainWindow wnd)
        {
            wnd.InitialiseProgressBar(26);

            string textRev = text.ReverseString();

            double best_score = 0.0;
            int    best_key   = 0;

            for (int this_key = 0; this_key < 26; this_key++)
            {
                wnd.SetProgressText($"Step {this_key+1} of 26\nAttempting key of {Util.alphabet[this_key]}...");

                Caesar cipher      = new Caesar(this_key);
                string this_output = cipher.Decrypt(text);
                double this_score  = NgramScore.MonogramScore.Score(this_output);
                if (this_score > best_score)
                {
                    best_score = this_score;
                    best_key   = this_key;
                }

                wnd.StepProgress();
            }

            string output;

            if (
                NgramScore.QuadgramScore.Score(new Caesar(best_key).Decrypt(text)) >
                NgramScore.QuadgramScore.Score(new Caesar(best_key).Decrypt(textRev)))
            {
                output = new Caesar(best_key).Decrypt(text);
            }
            else
            {
                output = new Caesar(best_key).Decrypt(textRev);
            }

            wnd.SetOutputText(output.ToLower());
        }