コード例 #1
0
ファイル: Program.cs プロジェクト: Maklevskiy/SergHomeWork
 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 Dencrypt_WhenEmptyStringIsPassed_ReturnEmptyString()
        {
            var cipher = new CeasarCipher(offset: 0);

            var encrypted = cipher.Decrypt("");

            Assert.IsEmpty(encrypted);
        }
コード例 #3
0
        public void Dencrypt_WhenEmptyStringIsPassed_ReturnEmptyString()
        {
            var cipher = new CeasarCipher(offset: 0);

            var encrypted = cipher.Decrypt("");

            Assert.IsEmpty(encrypted);
        }
コード例 #4
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));
        }
コード例 #5
0
        public void Decrypt_WithOverflow_ShouldStartFromBegingingOfAlphabet()
        {
            var cipher = new CeasarCipher(offset: 1);
            var word   = "!";

            var encrypted = cipher.Decrypt(word);

            Assert.AreEqual("~", encrypted);
        }
コード例 #6
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));
        }
コード例 #7
0
        public void Decrypt_WithOverflow_ShouldStartFromBegingingOfAlphabet()
        {
            var cipher = new CeasarCipher(offset: 1);
            var word = "!";

            var encrypted = cipher.Decrypt(word);

            Assert.AreEqual("~", encrypted);
        }
コード例 #8
0
        public void Dencrypt_WhenPassedNull_ThrowsArgumentNullException()
        {
            var cipher = new CeasarCipher(offset: 0);

            Assert.Throws<ArgumentNullException>(() =>
            {
                cipher.Decrypt(null);
            });
        }
コード例 #9
0
        public void Decrypt_WithZeroOffset_ReturnTheSameWord()
        {
            var cipher = new CeasarCipher(offset: 0);
            var word = "random";

            var encrypted = cipher.Decrypt(word);

            Assert.AreEqual(word, encrypted);
        }
コード例 #10
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));
        }
コード例 #11
0
        public void Decrypt_WithOneOffset_ShiftsSymbolsOnOnePosition()
        {
            var cipher = new CeasarCipher(offset: 1);
            var word = "b";

            var encrypted = cipher.Decrypt(word);

            Assert.AreEqual("a", encrypted);
        }
コード例 #12
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));
        }
コード例 #13
0
        public void Decrypt_WithNegativeOffsetOverflow_ShouldStartFromBeginningOfAlphabet()
        {
            var cipher = new CeasarCipher(offset: -1);
            var word = "~";

            var decrypted = cipher.Decrypt(word);

            Assert.AreEqual("!", decrypted);
        }
コード例 #14
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));
        }
コード例 #15
0
        public void Decrypt_WithOneOffset_ShiftsSymbolsOnOnePosition()
        {
            var cipher = new CeasarCipher(offset: 1);
            var word   = "b";

            var encrypted = cipher.Decrypt(word);

            Assert.AreEqual("a", encrypted);
        }
コード例 #16
0
        public void Decrypt_WithZeroOffset_ReturnTheSameWord()
        {
            var cipher = new CeasarCipher(offset: 0);
            var word   = "random";

            var encrypted = cipher.Decrypt(word);

            Assert.AreEqual(word, encrypted);
        }
コード例 #17
0
        public void Dencrypt_WhenPassedNull_ThrowsArgumentNullException()
        {
            var cipher = new CeasarCipher(offset: 0);

            Assert.Throws <ArgumentNullException>(() =>
            {
                cipher.Decrypt(null);
            });
        }
コード例 #18
0
        public void Dencrypt_WhenPassedWrongSymbol_ThrowsArgumentOutOfRangeException()
        {
            var cipher = new CeasarCipher(offset: 0);
            var nonSymbol = (char)127;
            var nonSymbolString = new string(new[] { nonSymbol });

            Assert.Throws<ArgumentOutOfRangeException>(() =>
            {
                cipher.Decrypt(nonSymbolString);
            });
        }
コード例 #19
0
        public void Dencrypt_WhenPassedWrongSymbol_ThrowsArgumentOutOfRangeException()
        {
            var cipher          = new CeasarCipher(offset: 0);
            var nonSymbol       = (char)127;
            var nonSymbolString = new string(new[] { nonSymbol });

            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                cipher.Decrypt(nonSymbolString);
            });
        }
コード例 #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));
        }