Exemplo n.º 1
0
        public override (string, double) Break(string cipher = null)
        {
            if (cipher == null)
            {
                cipher = this.Cipher;
            }

            string plain   = cipher;
            double maxProb = FrequencyAnalyst.Analyze(cipher);

            for (int i = 1; i < LetterSetSize; i++)
            {
                (string str, bool ok)result = Decode(cipher, i.ToString());
                if (result.ok)
                {
                    double prob = FrequencyAnalyst.Analyze(result.str);
                    if (prob > maxProb)
                    {
                        plain   = result.str;
                        maxProb = prob;
                    }
                }
            }

            this.Plain = plain;
            ProcessLog.Enqueue(plain);
            ProcessLog.Enqueue("");
            return(plain, Math.Pow(Math.E, maxProb));
        }
Exemplo n.º 2
0
        public override (string, double) Break(string cipher = null)
        {
            if (cipher == null)
            {
                cipher = this.Cipher;
            }

            string plain   = cipher;
            double maxProb = FrequencyAnalyst.Analyze(cipher);

            for (int i = 0; i < LetterSetSize; i++)
            {
                if (NumberTheory.Gcd(i, LetterSetSize) == 1)
                {
                    for (int j = 0; j < LetterSetSize; j++)
                    {
                        string a  = i.ToString();
                        string b  = j.ToString();
                        string ab = a + "," + b;
                        (string str, bool ok)result = Decode(cipher, ab);
                        if (result.ok)
                        {
                            double prob = FrequencyAnalyst.Analyze(result.str);
                            if (prob > maxProb)
                            {
                                plain   = result.str;
                                maxProb = prob;
                            }
                        }
                    }
                }
            }

            this.Plain = plain;
            ProcessLog.Enqueue(plain);
            ProcessLog.Enqueue("");
            return(plain, Math.Pow(Math.E, maxProb));
            //throw new NotImplementedException();
        }