private void txtBoxConnectionString_TextChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtBoxConnectionString.Text))
            {
                btnSaveConnectionStringToFile.Enabled = true;
                _connectionString = CaesarEncoder.Encrypt(txtBoxConnectionString.Text, true);

                var connectionSuccessfully = new Repository(_connectionString).CheckConnection();
                if (connectionSuccessfully)
                {
                    lblConnectionStatus.Text      = "Подключение к БД успешно установлено";
                    lblConnectionStatus.ForeColor = Color.ForestGreen;

                    foreach (var tabPage in tabPane.TabPages)
                    {
                        ((TabPage)tabPage).Enabled = true;
                    }
                }
                else
                {
                    lblConnectionStatus.Text      = "Подключение к БД отсутствует";
                    lblConnectionStatus.ForeColor = Color.Red;

                    foreach (var tabPage in tabPane.TabPages)
                    {
                        if (((TabPage)tabPage).Text != "Настройки")
                        {
                            ((TabPage)tabPage).Enabled = false;
                        }
                    }
                }
            }
        }
Example #2
0
        public void Decodes(string input, string expected)
        {
            var encoder = new CaesarEncoder(-2);

            var encoded = encoder.Encode(input);

            Assert.Equal(expected, encoded);
        }
Example #3
0
        public void EncodesAndDecodesToSameString(string input, int shift)
        {
            var encoder = new CaesarEncoder(shift);

            var encoded = encoder.Encode(input);
            var decoded = encoder.Decode(encoded);

            Assert.Equal(input, decoded);
        }
        private void btnGenerateConnectionString_Click(object sender, EventArgs e)
        {
            var connectionString = GetConnectionString(string.Empty);

            if (connectionString != null)
            {
                txtBoxConnectionString.Text = CaesarEncoder.Encrypt(connectionString);
            }
        }
        private void btnLoadSettingsFromFile_Click(object sender, EventArgs e)
        {
            var explorer = new OpenFileDialog();

            if (explorer.ShowDialog() == DialogResult.OK)
            {
                var textFromFile = File.ReadAllText(explorer.FileName);

                txtBoxConnectionString.Text = textFromFile;

                _connectionString = CaesarEncoder.Encrypt(textFromFile, true);
            }
        }
Example #6
0
        public void DecodedStringIsTheSame([Random(100)] int key)
        {
            // Arrange
            var encoder = new CaesarEncoder();
            var random  = new Randomizer();
            var message = random.GetString();

            // Act
            var encoded = encoder.Encode(message, key);
            var decoded = encoder.Decode(encoded, key);

            // Assert
            Assert.AreEqual(message, decoded);
        }
Example #7
0
        public ActionResult KeySearch(HttpPostedFileBase file, string text)
        {
            text = GetNeededText(file, text);
            if (text == null)
            {
                return(RedirectToAction("Index"));
            }
            string fileName = file?.FileName ?? "Untitled.txt";

            ViewBag.Keys     = CaesarEncoder.GetBestKeys(text);
            ViewBag.FileName = fileName;

            return(View("KeySearch"));
        }
Example #8
0
        public void Should_Encode_And_Decode_String()
        {
            // Arrange
            var ce      = new CaesarEncoder(1234);
            var message = "encrypt_and_decrypt";

            // Act
            var encodedMessage = ce.Encode(message);
            var decodedMessage = ce.Decode(encodedMessage);

            // Assert
            Assert.True(string.Equals(decodedMessage, message),
                        $"Expected: {message}; Actual: {decodedMessage}");
        }
Example #9
0
        public void Should_Decode_String()
        {
            // Arrange
            var ce       = new CaesarEncoder(1234);
            var message  = "RjdFRjFFRkQ7QDk=";
            var expected = "test_string";

            // Act
            var decodedMessage = ce.Decode(message);

            // Assert
            Assert.True(string.Equals(decodedMessage, expected),
                        $"Expected: {expected}; Actual: {decodedMessage}");
        }
Example #10
0
        public ActionResult Decryption(HttpPostedFileBase file, string text, int decryptKey)
        {
            text = GetNeededText(file, text);
            if (text == null)
            {
                return(RedirectToAction("Index"));
            }
            string fileName = file?.FileName ?? "Untitled.txt";

            ViewBag.Text     = CaesarEncoder.Decryption(text, decryptKey);
            ViewBag.FileName = fileName;
            ViewBag.Key      = decryptKey;

            return(View("Decryption"));
        }
Example #11
0
        static void Main(string[] args)
        {
            string text, key;

            while (true)
            {
                Console.WriteLine("What to do?");
                Console.WriteLine("1. Encrypt");
                Console.WriteLine("2. Decrypt");
                Console.WriteLine("0. Exit");
                Task task = (Task)Convert.ToInt32(Console.ReadLine());
                if (task == Task.Exit)
                {
                    break;
                }
                Console.WriteLine("Which cipher?");
                Console.WriteLine("1. Vigenere");
                Console.WriteLine("2. Caesar");
                Cipher cipher = (Cipher)Convert.ToInt32(Console.ReadLine()) - 1;
                switch (task)
                {
                case Task.Encrypt:
                    text = GetText();
                    key  = GetKey();
                    switch (cipher)
                    {
                    case Cipher.Vigenere:
                        Encode.Encoder encVig = new VigenereEncoder(text, key);
                        EncodedMessage msgVig = encVig.Create();
                        Console.WriteLine("Encrypted message: {0}", msgVig.text);
                        break;

                    case Cipher.Caesar:
                        Encode.Encoder encCaesar = new CaesarEncoder(text, key);
                        EncodedMessage msgCaesar = encCaesar.Create();
                        Console.WriteLine("Encrypted message: {0}", msgCaesar.text);
                        break;
                    }
                    break;

                case Task.Decrypt:
                    text = GetText();
                    key  = GetKey();
                    switch (cipher)
                    {
                    case Cipher.Vigenere:
                        Decode.Decoder decVig = new VigenereDecoder(text, key);
                        DecodedMessage msgVig = decVig.Create();
                        Console.WriteLine("Decrypted message: {0}", msgVig.text);
                        break;

                    case Cipher.Caesar:
                        Decode.Decoder decCaesar = new CaesarDecoder(text, key);
                        DecodedMessage msgCaesar = decCaesar.Create();
                        Console.WriteLine("Decrypted message: {0}", msgCaesar.text);
                        break;
                    }
                    break;
                }
            }
            Console.ReadKey();
        }
 public void KeySearching(string input, int expectedResult)
 {
     CaesarEncoder.Key[] keys = CaesarEncoder.GetBestKeys(input);
     Assert.AreEqual(expectedResult, keys[0].Shift);
 }
        public void StringShifting(string input, int shift, string expectedResult)
        {
            string result = CaesarEncoder.Shift(input, shift);

            Assert.AreEqual(expectedResult, result);
        }