Пример #1
0
 private static void Main(string[] args)
 {
     CeasarCipher start = new CeasarCipher(1);
     start.Encrypt("home work 2");
     Console.WriteLine(start.Encrypt("home work 2"));
     string nemp = start.Encrypt("home work 2");
     start.Decrypt(nemp);
     Console.WriteLine(start.Decrypt(nemp));
 }
Пример #2
0
        public void Encrypt_WhenEmptyStringIsPassed_ReturnEmptyString()
        {
            var cipher = new CeasarCipher(offset: 0);

            var encrypted = cipher.Encrypt("");

            Assert.IsEmpty(encrypted);
        }
Пример #3
0
        public void Encrypt_WithLargeOffset_ShouldStartFromBegingingOfAlphabet()
        {
            var cipher = new CeasarCipher(offset: 109);
            var word   = "~";

            var encrypted = cipher.Encrypt(word);

            Assert.AreEqual("!", encrypted);
        }
Пример #4
0
        public void EncryptDecrypt_WithRandomSting_plus_enter()
        {
            var cipher = new CeasarCipher(offset: 5);
            var word = "Testing with \r some random string";

            var encrypted = cipher.Encrypt(word);

            Assert.AreEqual(word, cipher.Decrypt(encrypted));
        }
Пример #5
0
        public void EncryptDecrypt_WithRandomSting_ProducesTheSameResult()
        {
            var cipher = new CeasarCipher(offset: 5);
            var word   = "Testing with some random string";

            var encrypted = cipher.Encrypt(word);

            Assert.AreEqual(word, cipher.Decrypt(encrypted));
        }
Пример #6
0
        public void EncryptDecrypt_WithRandomSting_ProducesTheSameResult()
        {
            var cipher = new CeasarCipher(offset: 5);
            var word = "Testing with some random string";

            var encrypted = cipher.Encrypt(word);

            Assert.AreEqual(word, cipher.Decrypt(encrypted));
        }
Пример #7
0
        public void EncryptDecrypt_WithOffsetLargerThanAlphabet_ProducesTheSameResult()
        {
            var cipher = new CeasarCipher(offset: 5);
            var word = "Test string";

            var encrypted = cipher.Encrypt(word);

            Assert.AreEqual(word, cipher.Decrypt(encrypted));
        }
Пример #8
0
        public void EncryptDecrypt_WithMinOffset()
        {
            var cipher = new CeasarCipher(offset: int.MinValue);
            var word   = "Testing with some random string";

            var encrypted = cipher.Encrypt(word);

            Assert.AreEqual(word, cipher.Decrypt(encrypted));
        }
Пример #9
0
        public void Encrypt_WithOneOffset_ShiftsSymbolsOnOnePositionRight()
        {
            var cipher = new CeasarCipher(offset: 1);
            var word   = "a";

            var encrypted = cipher.Encrypt(word);

            Assert.AreEqual("b", encrypted);
        }
Пример #10
0
        public void Encrypt_WithZeroOffset_ReturnTheSameWord()
        {
            var cipher = new CeasarCipher(offset: 0);
            var word   = "random";

            var encrypted = cipher.Encrypt(word);

            Assert.AreEqual(word, encrypted);
        }
Пример #11
0
        public void Encrypt_WhenPassedNull_ThrowsArgumentNullException()
        {
            var cipher = new CeasarCipher(offset: 0);

            Assert.Throws <ArgumentNullException>(() =>
            {
                cipher.Encrypt(null);
            });
        }
Пример #12
0
        public void Encrypt_WhenPassedWrongSymbol_ThrowsArgumentOutOfRangeException()
        {
            var cipher          = new CeasarCipher(offset: 0);
            var nonSymbol       = (char)127;
            var nonSymbolString = new string(new[] { nonSymbol });

            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                cipher.Encrypt(nonSymbolString);
            });
        }
Пример #13
0
        public void Encrypt_WhenEmptyStringIsPassed_ReturnEmptyString()
        {
            var cipher = new CeasarCipher(offset: 0);

               var encrypted = cipher.Encrypt("");

               Assert.IsEmpty(encrypted);
        }
Пример #14
0
        public void Encrypt_WithZeroOffset_ReturnTheSameWord()
        {
            var cipher = new CeasarCipher(offset: 0);
            var word = "random";

            var encrypted = cipher.Encrypt(word);

            Assert.AreEqual(word, encrypted);
        }
Пример #15
0
        public void Encrypt_WithOverflow_ShouldStartFromBegingingOfAlphabet()
        {
            var cipher = new CeasarCipher(offset: 1);
            var word = "~";

            var encrypted = cipher.Encrypt(word);

            Assert.AreEqual("!", encrypted);
        }
Пример #16
0
        public void Encrypt_WithOneOffset_ShiftsSymbolsOnOnePositionRight()
        {
            var cipher = new CeasarCipher(offset: 1);
            var word = "a";

            var encrypted = cipher.Encrypt(word);

            Assert.AreEqual("b", encrypted);
        }
Пример #17
0
        public void Encrypt_WhenPassedWrongSymbol_ThrowsArgumentOutOfRangeException()
        {
            var cipher = new CeasarCipher(offset: 0);
            var nonSymbol = (char)127;
            var nonSymbolString = new string(new[] { nonSymbol });

            Assert.Throws<ArgumentOutOfRangeException>(() =>
            {
                cipher.Encrypt(nonSymbolString);
            });
        }
Пример #18
0
        public void Encrypt_WhenPassedNull_ThrowsArgumentNullException()
        {
            var cipher = new CeasarCipher(offset: 0);

            Assert.Throws<ArgumentNullException>(() =>
            {
                cipher.Encrypt(null);
            });
        }
        public void Encrypt_WithNegativeOffsetOverflow_ShouldStartFromEndOfAlphabet()
        {
            var cipher = new CeasarCipher(offset: -1);
            var word = "!";

            var encrypted = cipher.Encrypt(word);

            Assert.AreEqual("~", encrypted);
        }
Пример #20
0
        public void EncryptDecrypt_WithMinOffset()
        {
            var cipher = new CeasarCipher(offset: int.MinValue);
            var word = "Testing with some random string";

            var encrypted = cipher.Encrypt(word);

            Assert.AreEqual(word, cipher.Decrypt(encrypted));
        }