public void EncryptNoKeyTest()
        {
            ShiftCipher myCipher = new ShiftCipher();

            TestCtor(myCipher);
            myCipher.Encrypt(TEST_STR);
        }
        public void EncryptFileTest()
        {
            ShiftCipher shiftCipher = new ShiftCipher();

            shiftCipher.GenKey();
            shiftCipher.Encrypt(BASE_FILE, ENC_FILE);
            TestFileEnc();
        }
        public void EncryptStrTest()
        {
            ShiftCipher myCipher = new ShiftCipher();

            TestCtor(myCipher);
            myCipher.GenKey();
            TestStrEnc(myCipher, myCipher.Encrypt(TEST_STR));
        }
        public void Caesar()
        {
            ShiftCipher cipher = new ShiftCipher();

            const string plaintext  = "The quick brown fox jumps over the lazy dog.";
            const string ciphertext = "Wkh txlfn eurzq ira mxpsv ryhu wkh odcb grj.";

            Assert.AreEqual(ciphertext, cipher.Encrypt(plaintext, WellKnownShiftCipherKeys.Caesar));
            Assert.AreEqual(plaintext, cipher.Decrypt(ciphertext, WellKnownShiftCipherKeys.Caesar));
        }
        public void Rot13()
        {
            ShiftCipher cipher = new ShiftCipher();

            const string plaintext  = "Why did the chicken cross the road?";
            const string ciphertext = "Jul qvq gur puvpxra pebff gur ebnq?";

            Assert.AreEqual(ciphertext, cipher.Encrypt(plaintext, WellKnownShiftCipherKeys.Rot13));
            Assert.AreEqual(plaintext, cipher.Decrypt(ciphertext, WellKnownShiftCipherKeys.Rot13));
        }
        public void DecryptStrTest()
        {
            ShiftCipher myCipher = new ShiftCipher();

            TestCtor(myCipher);
            myCipher.GenKey();
            string encStr = myCipher.Encrypt(TEST_STR);

            TestStrEnc(myCipher, encStr);
            TestStrDec(encStr, myCipher.Decrypt(encStr));
        }
        public void ROT_13_TEST()
        {
            ShiftCipher myCipher = new ShiftCipher(ShiftCipher.MODE.ROT13);

            Assert.AreEqual(ShiftCipher.MODE.ROT13, myCipher.GetMode(), "default shift mode not set correctly");
            Assert.AreEqual(0, myCipher.GetKey(), "Incorrect defualt shift amount found");
            myCipher.GenKey();
            Assert.AreEqual(ROT_13_SHIFT, myCipher.GetKey(), "Incorrect shift amount found");
            string encStr = myCipher.Encrypt(TEST_STR);

            TestStrEnc(myCipher, encStr);
            TestStrDec(encStr, myCipher.Decrypt(encStr));
        }
 public ActionResult Index(string inputString, string encrypt)
 {
     if (encrypt == "encrypt")
     {
         var shiftAmount = 3;
         ShiftCipher shifter = new ShiftCipher();
         var outputString = shifter.Encrypt(inputString, shiftAmount);
         ViewBag.outputString = outputString;
         return View();
     }
     else
     {
         var shiftAmount = -3;
         ShiftCipher shifter = new ShiftCipher();
         var outputString = shifter.Decrypt(inputString, shiftAmount);
         ViewBag.outputString = outputString;
         return View();
     }
 }
        /// <summary>
        /// Computes every possible transformations of the input text.
        /// </summary>
        /// <param name="text">The input text to transform.</param>
        /// <param name="charset">Charset of the input text.</param>
        /// <returns></returns>
        public static IReadOnlyDictionary <int, string> Analyze(string text, string charset = Charsets.English)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            if (charset == null)
            {
                throw new ArgumentNullException(nameof(charset));
            }


            var cipher = new ShiftCipher(charset);

            return(Enumerable.Range(0, charset.Length)
                   .ToDictionary(k => k, k => cipher.Encrypt(text, k))
                   );
        }