Exemplo n.º 1
0
        public void fromMenu()
        {
            string direction;
            string identifier;

            do
            {
                identifier = displayAlgorithmMenu();
                direction  = displayDirectionMenu(identifier);
            } while (direction == id_back);

            Console.Clear();
            Console.WriteLine("Wpisz tekst (potwierdź enterem)\n");
            string input = Console.ReadLine();

            Console.Clear();

            CipherAlgorithm algorithm = getAlgorithm(identifier);

            if (direction == id_from)
            {
                Console.WriteLine(algorithm.from(input));
            }
            else
            {
                Console.WriteLine(algorithm.to(input));
            }

            Console.ReadKey(true);
        }
Exemplo n.º 2
0
        public void fromArgs(String inFile, String outFile, String algorithm, String direction = "to")
        {
            CipherAlgorithm alg = getAlgorithm(algorithm);

            if (getAlgorithm(algorithm) == null)
            {
                displayHelp();
                return;
            }
            if (direction != id_from && direction != id_to)
            {
                displayHelp();
                return;
            }

            string inText = "";

            try
            {
                inText = System.IO.File.ReadAllText(inFile);
            }
            catch (Exception e)
            {
                Console.WriteLine("(!) Failed to read from file\n");
                displayHelp();
            }

            string result = "";

            if (direction == id_from)
            {
                result = alg.from(inText);
            }
            else
            {
                result = alg.to(inText);
            }
            System.IO.File.WriteAllText(outFile, result);
            Console.WriteLine("Zapisałem do pliku {0}", outFile);
        }