Ejemplo n.º 1
0
        public void FindKeyLengthTest(string fileName, int expectedKeyLength)
        {
            string text = File.ReadAllText(fileName);

            text = text.Replace(" ", "").Replace("-", "").Replace("\r", "").Replace("\n", "").ToLower();
            Regex rgx = new Regex("[^a-zA-Z0-9 -]");

            text = rgx.Replace(text, "");

            int keyLength = Kasiski.FindKeyLength(text);

            Assert.Equal(expectedKeyLength, keyLength);
        }
Ejemplo n.º 2
0
        private static void TestKasiski()
        {
            // Read file, clean text
            string fileName = "Kasiski method/Tests/test.txt";
            string text     = File.ReadAllText(fileName);

            text = text.Replace(" ", "").Replace("\r", "").Replace("\n", "").ToLower();
            Regex rgx = new Regex("[^a-zA-Z0-9 -]");

            text = rgx.Replace(text, "");

            Kasiski.MinDigramLength = 2;
            Kasiski.MaxDigramLength = 2;
            Kasiski.PrintResult     = true;
            int keyLength = Kasiski.FindKeyLength(text);

            Console.WriteLine($"Key length: {keyLength}");
        }