예제 #1
0
        static void Main(string[] args)
        {
            // TODO: Check that plain_message contains only characters
            if (args.Length == 0)
            {
                PrintUsage("OTP length is required.");
                return;
            }

            int length;

            if (!int.TryParse(args[0], out length) || length > MAX_OTP_LENGTH)
            {
                PrintUsage(String.Format("Length argument is invalid. Max length is {0:N0}.", MAX_OTP_LENGTH));
                return;
            }

            var    otpGenerator = new OtpGenerator();
            string otp          = otpGenerator.Generate(length);

            if (args.Length >= 2)
            {
                var    cipher       = new VigenereCipher();
                string plainMessage = args[1];
                Console.WriteLine("{0} {1}", otp, cipher.Encrypt(otp, plainMessage));
            }
            else
            {
                Console.WriteLine(otp);
            }
        }
        static void Main(string[] args)
        {
            // TODO: Check that plain_message contains only characters
            if (args.Length == 0) {
                PrintUsage("OTP length is required.");
                return;
            }

            int length;
            if (!int.TryParse(args[0], out length) || length > MAX_OTP_LENGTH) {
                PrintUsage(String.Format("Length argument is invalid. Max length is {0:N0}.", MAX_OTP_LENGTH));
                return;
            }

            var otpGenerator = new OtpGenerator();
            string otp = otpGenerator.Generate(length);

            if (args.Length >= 2) {
                var cipher = new VigenereCipher();
                string plainMessage = args[1];
                Console.WriteLine("{0} {1}", otp, cipher.Encrypt(otp, plainMessage));
            } else {
                Console.WriteLine(otp);
            }
        }