Exemple #1
0
        public override string Decriptare(string cript_text)
        {
            key = 3;
            StringBuilder solutie = new StringBuilder();

            for (int i = 0; i < cript_text.Length; i++)
            {
                int val = (int)(cript_text[i]);
                if (val != ' ')
                {
                    val = val - key;
                    val = Exces.EliminaExces(val);
                }
                solutie.Append((char)(val));
            }
            return(solutie + "");
        }
Exemple #2
0
        public override string Encriptare(string clear_text)
        {
            key = 3;
            StringBuilder solutie = new StringBuilder();

            clear_text = clear_text.ToUpper();
            for (int i = 0; i < clear_text.Length; i++)
            {
                int val = (int)(clear_text[i]);
                if (Char.IsLetter(clear_text[i]))
                {
                    val = val + key;
                    val = Exces.EliminaExces(val);
                }
                solutie.Append((char)(val));
            }
            return(solutie.ToString());
        }
Exemple #3
0
        public override string Decriptare(string cript_text)
        {
            string[]      lines   = System.IO.File.ReadAllLines(@"C:\Users\Dragos\source\repos\Criptografie1\Criptografie1\20k.txt");
            string[]      words   = cript_text.Split(' ');
            StringBuilder solutie = new StringBuilder();

            key = 0;
            for (int j = 1; j <= 26; j++)
            {
                key++;
                Console.WriteLine(key);
                for (int i = 0; i < words.Length; i++)
                {
                    solutie.Clear();
                    for (int p = 0; p < words[i].Length; p++)
                    {
                        int valoare = (int)(words[i][p]);
                        valoare = valoare - 1;
                        valoare = Exces.EliminaExces(valoare);
                        solutie.Append((char)(valoare));
                    }
                    Console.WriteLine(solutie);
                    words[i] = solutie + "";
                }
                Console.WriteLine();

                if (words.All(s => lines.Contains(s, StringComparer.OrdinalIgnoreCase)))
                {
                    Console.WriteLine("Cheia este:: " + key);
                    StringBuilder decript = new StringBuilder();
                    foreach (var w in words)
                    {
                        decript.Append(w);
                        decript.Append(" ");
                    }
                    return(decript + "");
                }
            }

            return("eroare nu avem solutie");
        }