示例#1
0
 static void Main(string[] args)
 {
     #region Citire din textclar.txt si scriere in textcriptat.txt
     using (StreamReader reader = new StreamReader("../../textclar.txt"))
     {
         string line;
         int    cheie = 3;
         try
         {
             cheie = int.Parse(reader.ReadLine().Trim());
         } catch (Exception e)
         {
             Console.WriteLine("Nu s-a gasit pe prima linie cheia!");
         }
         CifruN encoder = new CifruN(cheie);
         using (StreamWriter writer = new StreamWriter("../../textcriptat.txt"))
         {
             while ((line = reader.ReadLine()) != null)
             {
                 writer.WriteLine(encoder.Criptare(line.Trim()));
             }
             writer.Close();
             reader.Close();
         }
     }
     #endregion
 }
示例#2
0
        public static string CriptoAnaliza(string text, HashSet <string> set, int cheie, out int nr)
        {
            CifruN encoder = new CifruN(cheie);
            string result  = encoder.Decriptare(text);

            string[] cuv = result.Split(new char[] { ',', '.', '-', '!', '?', ' ', '`', '/', '\\', '!', ';' },
                                        StringSplitOptions.RemoveEmptyEntries);
            nr = 0;
            for (int i = 0; i < cuv.Length; i++)
            {
                if (set.Contains(cuv[i].ToLower()))
                {
                    nr++;
                }
            }
            return(result);
        }
        static void Main()
        {
            CifruN cifru = new CifruN();

            Console.WriteLine(cifru.Cheie);

            string[] tests =
            {
                "aabbcc",
                "AaBbCc",
                "yzxYZX",
                "C",
                "The brown fox, tralalalalalalalalalalalalalalalalala"
            };
            Util.TestCriptare(cifru, tests);
            Console.WriteLine("==================");
            Util.TestCriptare(cifru, Util.GetAlphabet());
        }
        static void Main()
        {
            HashSet <string> cuvinte = Util.GetWordsFromFile("../../dictionary.txt",
                                                             new char[] { ' ', '.', ',', '!', '?', '-', ':', ';' });

            Console.WriteLine(string.Join("\n", cuvinte));
            StreamReader reader = new StreamReader("../../textcriptat.txt");
            string       line;

            while ((line = reader.ReadLine()) != null)
            {
                Console.WriteLine("Rezultate pentru :\n" + line);

                for (int cheie = 1; cheie <= 25; cheie++)
                {
                    int    nr;
                    string result = CifruN.CriptoAnaliza(line, cuvinte, cheie, out nr);
                    if (nr >= line.Split(new char[] { ' ' }).Length / 2)
                    {
                        Console.WriteLine(result);
                    }
                }
            }
        }