Пример #1
0
        public IActionResult AffineDecrypt([FromBody] AffineCipherViewModel viewModel)
        {
            AffineCipher cipher = new AffineCipher(viewModel.KeyA, viewModel.KeyB)
            {
                Alphabet = Alphabets.GetAlphabet((Alphabets.AlphabetType)viewModel.AlphabetType)
            };

            string decrypted = "";

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

            return(Json(decrypted));
        }
Пример #2
0
        public IActionResult AffineVisualization([FromBody] AffineCipherViewModel viewModel)
        {
            AffineCipher cipher = new AffineCipher(viewModel.KeyA, viewModel.KeyB)
            {
                Alphabet = Alphabets.GetAlphabet((Alphabets.AlphabetType)viewModel.AlphabetType)
            };

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

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

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

            input      = StringHelper.ReplaceWhitespace(input, "");
            input      = input.ToUpper();
            results[0] = cipher.Alphabet;
            results[2] = input;
            try
            {
                encrypted  = cipher.Encrypt(viewModel.Message);
                results[1] = encrypted;
            }
            catch (NullReferenceException)
            {
            }
            catch (Exception)
            {
                return(BadRequest(new { Result = false, Message = Text.InvalidCharacter }));
            }
            return(Json(results));
        }