コード例 #1
0
        public void Bacon()
        {
            BaconCipher cipher = new BaconCipher();

            const string plaintext  = "HELLO WORLD";
            const string ciphertext = "AABBBAABAAABABAABABAABBAB BABAAABBABBAAAAABABAAAABB";

            Assert.AreEqual(ciphertext, cipher.Encrypt(plaintext), true);
            Assert.AreEqual(plaintext, cipher.Decrypt(ciphertext), true);
        }
コード例 #2
0
        public IActionResult BaconDecrypt([FromBody] BaconCipherViewModel viewModel)
        {
            BaconCipher cipher = new BaconCipher();

            string decrypted = "";

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

            return(Json(decrypted));
        }
コード例 #3
0
        public IActionResult BaconVisualization([FromBody] BaconCipherViewModel viewModel)
        {
            BaconCipher cipher = new BaconCipher();

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

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