コード例 #1
0
        public string Analyze()
        {
            for (int a = 1; a < M; a++)
            {
                if (SimpleMaths.GCD(a, M) != 1)
                {
                    continue;
                }

                for (int b = 0; b < M; b++)
                {
                    AffineCipher affine = new AffineCipher(a, b);
                    string       text   = affine.DecryptText(cipherText);

                    double score = NgramStatistics.CountTextScore(text);

                    if (score > rate)
                    {
                        rate = score;
                        this.decryptedText = text;
                    }
                }
            }

            return(decryptedText);
        }
コード例 #2
0
        public AffineCipher(int a, int b)
        {
            if (SimpleMaths.GCD(a, M) != 1)
            {
                throw new ArgumentException("Error:"
                                            + " \"a\" parameter and modulus M should be coprime.");
            }

            this.a = a;
            this.b = b;
        }