Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //Task 1
            Console.WriteLine(new string('-', 50));
            Console.WriteLine("TASK 1\n");
            RailFenceCipher railFenceCipher = new RailFenceCipher();

            Console.WriteLine(railFenceCipher.EncryptRail("WEAREDISCOVEREDFLEEATONCE", 3));
            Console.WriteLine(railFenceCipher.DecryptRail("WECRLTEERDSOEEFEAOCAIVDEN", 3) + "\n");

            //Task 2
            Console.WriteLine(new string('-', 50));
            Console.WriteLine("TASK 2\n");
            var sideSquare     = 1.1234D;
            var radiusCircle   = 0.1234D;
            var baseTriangle   = 5D;
            var heightTriangle = 2D;
            var shapes         = new List <Shape> {
                new Square(sideSquare), new Circle(radiusCircle), new Triangle(baseTriangle, heightTriangle)
            };

            shapes.Sort();

            foreach (var item in shapes)
            {
                Console.WriteLine(item.GetType() + " = " + item.GetArea());
            }
        }
Exemplo n.º 2
0
        public void DecryptRailTest(string decryptText, int numberOfRails, string expected)
        {
            RailFenceCipher railFenceCipher = new RailFenceCipher();
            var             actual          = railFenceCipher.DecryptRail(decryptText, numberOfRails);

            Assert.Equal(expected, actual);
        }
Exemplo n.º 3
0
        private CipherStrIntModel FindCipherStrInt(int s)
        {
            CipherStrIntModel cipherStrIntModel = new CipherStrIntModel();

            switch (s)
            {
            case 1:
                CaesarVariation caesarVariation = new CaesarVariation();
                cipherStrIntModel.Decode  = caesarVariation.Decode;
                cipherStrIntModel.Encode  = caesarVariation.Encode;
                cipherStrIntModel.GetCode = caesarVariation.GetCode;
                return(cipherStrIntModel);

            case 2:
                RailFenceCipher caesarVariation1 = new RailFenceCipher();
                cipherStrIntModel.Decode  = caesarVariation1.Decode;
                cipherStrIntModel.Encode  = caesarVariation1.Encode;
                cipherStrIntModel.GetCode = caesarVariation1.GetCode;
                return(cipherStrIntModel);

            default:
                CaesarVariation caesarVariation2 = new CaesarVariation();
                cipherStrIntModel.Decode  = caesarVariation2.Decode;
                cipherStrIntModel.Encode  = caesarVariation2.Encode;
                cipherStrIntModel.GetCode = caesarVariation2.GetCode;
                return(cipherStrIntModel);
            }
        }
        public void EncodeDecode_Successful()
        {
            var result = RailFenceCipher.Decode(
                RailFenceCipher.Encode(TestMessage, MinAllowedRailCount), MinAllowedRailCount);

            Assert.AreEqual(TestMessage, result);
        }
Exemplo n.º 5
0
    public void Decode_with_three_rails()
    {
        var railFenceCipher = new RailFenceCipher(3);
        var actual          = railFenceCipher.Decode("TEITELHDVLSNHDTISEIIEA");
        var expected        = "THEDEVILISINTHEDETAILS";

        Assert.That(actual, Is.EqualTo(expected));
    }
Exemplo n.º 6
0
    public void Encode_with_ending_in_the_middle()
    {
        var msg      = "EXERCISES";
        var sut      = new RailFenceCipher(4);
        var expected = "ESXIEECSR";

        Assert.Equal(expected, sut.Encode(msg));
    }
Exemplo n.º 7
0
    public void Encode_with_three_rails()
    {
        var railFenceCipher = new RailFenceCipher(3);
        var actual          = railFenceCipher.Encode("WEAREDISCOVEREDFLEEATONCE");
        var expected        = "WECRLTEERDSOEEFEAOCAIVDEN";

        Assert.That(actual, Is.EqualTo(expected));
    }
Exemplo n.º 8
0
    public void Decode_with_three_rails()
    {
        var msg      = "TEITELHDVLSNHDTISEIIEA";
        var sut      = new RailFenceCipher(3);
        var expected = "THEDEVILISINTHEDETAILS";

        Assert.Equal(expected, sut.Decode(msg));
    }
Exemplo n.º 9
0
    public void Decode_with_six_rails()
    {
        var railFenceCipher = new RailFenceCipher(6);
        var actual          = railFenceCipher.Decode("133714114238148966225439541018335470986172518171757571896261");
        var expected        = "112358132134558914423337761098715972584418167651094617711286";

        Assert.That(actual, Is.EqualTo(expected));
    }
Exemplo n.º 10
0
    public void Decode_with_five_rails()
    {
        var msg      = "EIEXMSMESAORIWSCE";
        var sut      = new RailFenceCipher(5);
        var expected = "EXERCISMISAWESOME";

        Assert.Equal(expected, sut.Decode(msg));
    }
Exemplo n.º 11
0
        public void Decode_with_three_rails()
        {
            var sentence = "WECRLTEERDSOEEFEAOCAIVDEN";
            var rail     = new RailFenceCipher(3);
            var expected = "WEAREDISCOVEREDFLEEATONCE";

            Assert.AreEqual(expected, rail.Decode(sentence));
        }
Exemplo n.º 12
0
        public void Encode_with_two_rails()
        {
            var sentence = "HELLO WORLD";
            var rail     = new RailFenceCipher(2);
            var expected = "HLOWRDEL OL";

            Assert.AreEqual(expected, rail.Encode(sentence));
        }
Exemplo n.º 13
0
    public void Decode_with_six_rails()
    {
        var msg      = "133714114238148966225439541018335470986172518171757571896261";
        var sut      = new RailFenceCipher(6);
        var expected = "112358132134558914423337761098715972584418167651094617711286";

        Assert.Equal(expected, sut.Decode(msg));
    }
Exemplo n.º 14
0
    public void Encode_with_two_rails()
    {
        var msg      = "XOXOXOXOXOXOXOXOXO";
        var sut      = new RailFenceCipher(2);
        var expected = "XXXXXXXXXOOOOOOOOO";

        Assert.Equal(expected, sut.Encode(msg));
    }
Exemplo n.º 15
0
    public void Decode_with_five_rails()
    {
        var railFenceCipher = new RailFenceCipher(5);
        var actual          = railFenceCipher.Decode("EIEXMSMESAORIWSCE");
        var expected        = "EXERCISMISAWESOME";

        Assert.That(actual, Is.EqualTo(expected));
    }
Exemplo n.º 16
0
    public void Encode_with_three_rails()
    {
        var msg      = "WEAREDISCOVEREDFLEEATONCE";
        var sut      = new RailFenceCipher(3);
        var expected = "WECRLTEERDSOEEFEAOCAIVDEN";

        Assert.Equal(expected, sut.Encode(msg));
    }
Exemplo n.º 17
0
    public void Encode_with_two_rails()
    {
        var railFenceCipher = new RailFenceCipher(2);
        var actual          = railFenceCipher.Encode("XOXOXOXOXOXOXOXOXO");
        var expected        = "XXXXXXXXXOOOOOOOOO";

        Assert.That(actual, Is.EqualTo(expected));
    }
Exemplo n.º 18
0
    public void Encode_with_ending_in_the_middle()
    {
        var railFenceCipher = new RailFenceCipher(4);
        var actual          = railFenceCipher.Encode("EXERCISES");
        var expected        = "ESXIEECSR";

        Assert.That(actual, Is.EqualTo(expected));
    }
Exemplo n.º 19
0
        public void DecodeStringTest()
        {
            string encodedString  = Convert.ToString(TestContext.DataRow["encodedString"]);
            int    numberOfRails  = Convert.ToInt32(TestContext.DataRow["numberOfRails"]);
            string expectedResult = Convert.ToString(TestContext.DataRow["decodedString"]);

            string actualResult = RailFenceCipher.DecodeString(encodedString, numberOfRails);

            Assert.AreEqual(expectedResult, actualResult, "expected and actual results are not equal.\ndecodedString = " + encodedString + "\nnumberOfRails = " + numberOfRails);
        }
Exemplo n.º 20
0
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     try
     {
         DecodeLable.Content = RailFenceCipher.Encode(DecodeInput.Text, Convert.ToInt32(RailsInput.Text));
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 21
0
 public void DecodeSampleTests()
 {
     string[][] decodes =
     {
         new[] { "159246837",                 "123456789"                 },
         new[] { "WECRLTEERDSOEEFEAOCAIVDEN", "WEAREDISCOVEREDFLEEATONCE" }, // 3 rails
         new[] { "H !e,Wdloollr",             "Hello, World!"             }, // 4 rails
         new[] { "",                          ""                          } // 3 rails (even if...)
     };
     int[] rails = { 3, 3, 4, 3 };
     for (int i = 0; i < decodes.Length; i++)
     {
         Assert.AreEqual(decodes[i][1], RailFenceCipher.Decode(decodes[i][0], rails[i]));
     }
 }
Exemplo n.º 22
0
        public void Decode_Tests()
        {
            string[][] decodes =
            {
                new[] { "WECRLTEERDSOEEFEAOCAIVDEN", "WEAREDISCOVEREDFLEEATONCE" },
                new[] { "H !e,Wdloollr",             "Hello, World!"             },
                new[] { "",                          ""                          }
            };

            int[] rails = { 3, 4, 3 };

            for (int i = 0; i < decodes.Length; i++)
            {
                Assert.AreEqual(decodes[i][1], RailFenceCipher.Decode(decodes[i][0], rails[i]));
            }
        }
Exemplo n.º 23
0
 private string DecodeSI(int a, string code, string eMessage)
 {
     if (code == "F")
     {
         RailFenceCipher railFenceCipher = new RailFenceCipher();
         return(railFenceCipher.Decode(eMessage, a));
     }
     if (code == "S")
     {
         RailFenceCipher railFenceCipher = new RailFenceCipher();
         return(railFenceCipher.Decode(eMessage, a));
     }
     else if (code == "C")
     {
         CaesarVariation caesarVariation = new CaesarVariation();
         return(caesarVariation.Decode(eMessage, a));
     }
     else
     {
         return("Error");
     }
 }
Exemplo n.º 24
0
        public void PublisherIdentityPermission()
        {
            //string[][] encodes =
            //{
            //    new[] { "WEAREDISCOVEREDFLEEATONCE", "WEEEAALTRFOEDNDECIRESECVO" },
            //    new[] { "WADCEFACTLROIREESVEEOENED", "WEAREDISCOVEREDFLEEATONCE" }
            //};
            //int[] rails1 = { 10, 8 };
            //for (int i = 0; i < encodes.Length; i++)
            //{
            //    Assert.AreEqual(encodes[i][1], RailFenceCipher.Encode(encodes[i][0], rails1[i]));
            //}

            string[][] decodes =
            {
                new[] { "WEAREDISCOVEREDFLEEATONCE", "WADCEFACTLROIREESVEEOENED" },
            };
            int[] rails2 = { 8 };
            for (int i = 0; i < decodes.Length; i++)
            {
                Assert.AreEqual(decodes[i][1], RailFenceCipher.Decode(decodes[i][0], rails2[i]));
            }
        }
        public void DecodeMessage_Successful(string encodedMessage, int railCount, string originalMessage)
        {
            var result = RailFenceCipher.Decode(encodedMessage, railCount);

            Assert.AreEqual(originalMessage, result);
        }
 public void DecodeMessage_WrongRailCount_ThrowException(int railCount)
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => RailFenceCipher.Decode(TestMessage, railCount));
 }
Exemplo n.º 27
0
        static void Main(string[] args)
        {
            Console.WriteLine("Choose alghorithm\n" +
                              "1. RailFence\n" +
                              "2. Transposition A\n" +
                              "3. Transposition B\n" +
                              "4. Transposition C\n" +
                              "5. Caesar\n" +
                              "6. Vigenere\n" +
                              "7. Exit\n");

            Console.WriteLine("Choose: ");

            int option = ReadInt();

            string wordToEncrypt = "";
            string encryptedWord = "";
            string decryptedWord = "";

            Console.WriteLine("Enter your word: ");
            wordToEncrypt = Console.ReadLine();

            ICipher cs = new RailFenceCipher(0);

            switch (option)
            {
            case 1:
                // RailFence
            {
                Console.WriteLine("Give key [Integer]: ");
                int key = ReadInt();

                cs = new RailFenceCipher(key);

                Console.WriteLine("Using RailFence Cipher");

                Console.WriteLine("\nWord given: " + wordToEncrypt);

                encryptedWord = cs.Encrypt(wordToEncrypt);
                Console.WriteLine("Encrypted word: " + encryptedWord);


                Console.WriteLine("Give word to decrypt: ");
                wordToEncrypt = Console.ReadLine();
                Console.WriteLine("Give key [Integer]: ");
                key = ReadInt();

                cs = new RailFenceCipher(key);

                decryptedWord = cs.Decrypt(wordToEncrypt);
                Console.WriteLine("Decrypted word: " + decryptedWord);
            }
            break;

            case 2:
                // Transposition A
            {
                cs = new TranspositionCipherA();

                Console.WriteLine("Using Transposition A Cipher");

                Console.WriteLine("\nWord given: " + wordToEncrypt);

                encryptedWord = cs.Encrypt(wordToEncrypt);
                Console.WriteLine("Encrypted word: " + encryptedWord);


                Console.WriteLine("Give word to decrypt: ");
                wordToEncrypt = Console.ReadLine();

                decryptedWord = cs.Decrypt(wordToEncrypt);
                Console.WriteLine("Decrypted word: " + decryptedWord);
            }
            break;

            case 3:
                // Transposition B
            {
                Console.WriteLine("Give key [String, Letters only]: ");
                string key = Console.ReadLine();

                cs = new TranspositionCipherB(key);

                Console.WriteLine("Using Transposition B Cipher");

                Console.WriteLine("\nWord given: " + wordToEncrypt);

                encryptedWord = cs.Encrypt(wordToEncrypt);
                Console.WriteLine("Encrypted word: " + encryptedWord);


                Console.WriteLine("Give word to decrypt: ");
                wordToEncrypt = Console.ReadLine();
                Console.WriteLine("Give key [String, Letters only]: ");
                key = Console.ReadLine();

                cs = new TranspositionCipherB(key);

                decryptedWord = cs.Decrypt(wordToEncrypt);
                Console.WriteLine("Decrypted word: " + decryptedWord);
            }
            break;

            case 4:
                // Transposition C
            {
                Console.WriteLine("Give key [String, Letters only]: ");
                string key = Console.ReadLine();

                cs = new TranspositionCipherC(key);

                Console.WriteLine("Using Transposition C Cipher");

                Console.WriteLine("\nWord given: " + wordToEncrypt);

                encryptedWord = cs.Encrypt(wordToEncrypt);
                Console.WriteLine("Encrypted word: " + encryptedWord);


                Console.WriteLine("Give word to decrypt: ");
                wordToEncrypt = Console.ReadLine();
                Console.WriteLine("Give key [String, Letters only]: ");
                key = Console.ReadLine();

                cs = new TranspositionCipherC(key);

                decryptedWord = cs.Decrypt(wordToEncrypt);
                Console.WriteLine("Decrypted word: " + decryptedWord);
            }
            break;

            case 5:
                // Caesar
            {
                Console.WriteLine("Give key 1 [Integer]: ");
                int key0 = ReadInt();

                Console.WriteLine("Give key 2 [Integer]: ");
                int key1 = ReadInt();

                cs = new CaesarCipher(key0, key1);
                Console.WriteLine("Using Caesar Cipher");

                Console.WriteLine("\nWord given: " + wordToEncrypt);

                encryptedWord = cs.Encrypt(wordToEncrypt);
                Console.WriteLine("Encrypted word: " + encryptedWord);


                Console.WriteLine("Give word to decrypt: ");
                wordToEncrypt = Console.ReadLine();

                Console.WriteLine("Give key 1 [Integer]: ");
                key0 = ReadInt();

                Console.WriteLine("Give key 2 [Integer]: ");
                key1 = ReadInt();

                cs = new CaesarCipher(key0, key1);

                decryptedWord = cs.Decrypt(wordToEncrypt);
                Console.WriteLine("Decrypted word: " + decryptedWord);
            }
            break;

            case 6:
                // Vigenere
            {
                Console.WriteLine("Give key [String, Letters only]: ");
                string key = Console.ReadLine();

                cs = new VigenereCipher(key);
                Console.WriteLine("Using Vigenere Cipher");

                Console.WriteLine("\nWord given: " + wordToEncrypt);

                encryptedWord = cs.Encrypt(wordToEncrypt);
                Console.WriteLine("Encrypted word: " + encryptedWord);


                Console.WriteLine("Give word to decrypt: ");
                wordToEncrypt = Console.ReadLine();
                Console.WriteLine("Give key [String, Letters only]: ");
                key = Console.ReadLine();

                cs = new VigenereCipher(key);

                decryptedWord = cs.Decrypt(wordToEncrypt);
                Console.WriteLine("Decrypted word: " + decryptedWord);
            }
            break;

            case 7:
                Console.WriteLine("Bye!");
                Console.ReadKey();
                return;

            default:
                Console.WriteLine("Wrong input!");
                Console.ReadKey();
                return;
            }


            Console.ReadKey();
            return;
        }
Exemplo n.º 28
0
        string DecryptRailFence(string input, int key)
        {
            RailFenceCipher cipher = new RailFenceCipher();

            return(cipher.Decrypt(input, key));
        }
        public void DecodeMessage_EmptyString_ReturnEmptyString()
        {
            var result = RailFenceCipher.Decode(string.Empty, MinAllowedRailCount);

            Assert.AreEqual(string.Empty, result);
        }