예제 #1
0
        public MainWindow()
        {
            InitializeComponent();
            DataContext = new VigenereCipherViewModel();
            string tmp = VigenereCipher.EncryptMessage("ATTACKATDAWN", "LEMONLEMONLE");

            VigenereCipher.DecryptMessage(tmp, "LEMONLEMONLE");
            VigenereCipher.test();
        }
예제 #2
0
        public IActionResult VigenereVisualization([FromBody] VigenereCipherViewModel viewModel)
        {
            VigenereCipher cipher = new VigenereCipher
                                        (viewModel.Key, Alphabets.GetAlphabet((Alphabets.AlphabetType)viewModel.AlphabetType));

            cipher.Alphabet = Alphabets.GetAlphabet((Alphabets.AlphabetType)viewModel.AlphabetType);

            string[] results = new string[4] {
                "alphabet", "output", "input", "key"
            };
            string encrypted = "";
            string input     = viewModel.Message;

            input = StringHelper.ReplaceWhitespace(input, "");
            input = input.ToUpper();
            int alphabetLength = cipher.Alphabet.Length;

            results[0] = cipher.Alphabet;
            results[2] = input;
            try
            {
                encrypted  = cipher.Encrypt(viewModel.Message);
                results[1] = encrypted;
                var key      = new StringBuilder();
                int keyIndex = 0;
                for (int i = 0; i < input.Length; i++)
                {
                    key.Append(cipher.Key[keyIndex]);

                    keyIndex++;
                    if (keyIndex >= cipher.Key.Length)
                    {
                        keyIndex = 0;
                    }
                }
                results[3] = key.ToString();
            }
            catch (NullReferenceException)
            {
            }
            catch (Exception)
            {
                return(BadRequest(new { Result = false, Message = Text.InvalidCharacter }));
            }
            return(Json(results));
        }
예제 #3
0
        public IActionResult VigenereDecrypt([FromBody] VigenereCipherViewModel viewModel)
        {
            VigenereCipher cipher = new VigenereCipher
                                        (viewModel.Key, Alphabets.GetAlphabet((Alphabets.AlphabetType)viewModel.AlphabetType));

            string decrypted = "";

            try
            {
                decrypted = cipher.Decrypt(viewModel.Message);
            }
            catch (Exception e)
            {
                return(BadRequest(new { Result = false, Message = e.Message }));
            }

            return(Json(decrypted));
        }