예제 #1
0
        public string Decrypt()          // Дешифрування
        {
            string changedKey = "";      // результуюча змінна для нового ключа

            foreach (var ch in GetKey)
            {
                changedKey += GetAlphabet.GetLetterFromIndex((GetAlphabet.GetLenght() - GetAlphabet.GetIndexFromAlphabet(ch)) % GetAlphabet.GetLenght());          // обчислення симовлу нового ключа
            }
            var obj = new Vigener(GetInput, changedKey, GetAlphabet);

            return(obj.Encrypt());          // повернення розшифрованого тексту
        }
예제 #2
0
        private void materialRaisedButton1_Click(object sender, EventArgs e)
        {
            key = materialSingleLineTextField1.Text;
            if (key != null && textFromOriginalFile != null)
            {
                string executableLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                var    alph     = new Alphabet();
                var    ciphered = "";
                var    obj1     = new OneTimePad(textFromOriginalFile, key);
                var    obj2     = new Vigener(textFromOriginalFile, key, alph);
                var    obj3     = new AffineCipher(textFromOriginalFile, alph);

                var rsaKeys = new RSAKeys();

                var obj4 = new RSA(textFromOriginalFile, rsaKeys.GetRSAKeys[0]);

                //var rabinKeys = new RabinKeys();

                //var obj5 = new RabinCipher(textFromOriginalFile, rabinKeys.GetRabinKeys[0]);

                var elHamalKeys = new ElHamalKey();

                var obj6 = new ElHamalCipher(textFromOriginalFile, elHamalKeys.GetElHamalKeys[0]);


                if (materialRadioButton1.Checked == true)
                {
                    ciphered = obj1.Encrypt();
                    materialSingleLineTextField1.Enabled = true;
                    materialLabel1.Visible = false;
                }
                else if (materialRadioButton2.Checked == true)
                {
                    ciphered = obj2.Encrypt();
                    materialSingleLineTextField1.Enabled = true;
                    materialLabel1.Visible = false;
                }
                else if (materialRadioButton3.Checked == true)
                {
                    ciphered            = obj3.Encrypt();
                    materialLabel1.Text = "Ключ(" + obj3.GetKey.Key + ";" + obj3.GetKey.Value + ")";
                    materialSingleLineTextField1.Enabled = false;
                }
                else if (materialRadioButton4.Checked == true)
                {
                    ciphered = obj4.Encrypt();

                    File.WriteAllText(Path.Combine(executableLocation, "RSAkeys.txt"), string.Join("\n", rsaKeys.GetRSAKeys.Select(x => x)));

                    //var a = File.ReadAllText(Path.Combine(executableLocation, "RSAkeys.txt")).Trim(']', '[').Split('\n').Select(x => x.Trim(']', '[')).ToList();


                    materialLabel1.Text = "Ключ(" + obj4.GetKey.Key + ";" + obj4.GetKey.Value + ")";
                    materialSingleLineTextField1.Enabled = false;
                }
                else if (materialRadioButton5.Checked == true)
                {
                    ciphered = obj6.Encrypt();

                    File.WriteAllText(Path.Combine(executableLocation, "ElhamalKeys.txt"), string.Join("\n", elHamalKeys.GetElHamalKeys.Select(x => string.Join(";", x.ToArray()))));



                    materialLabel1.Text = "Ключ(" + obj6.GetKey[0] + ";" + obj6.GetKey[1] + ";" + obj6.GetKey[2] + ")";
                    materialSingleLineTextField1.Enabled = false;
                }


                textBox2.Text       = textFromOriginalFile;
                materialLabel2.Text = "Початковий текст";

                File.WriteAllText(Path.Combine(executableLocation, "CipheredText.txt"), ciphered);
                textBox1.Text       = File.ReadAllText(Path.Combine(executableLocation, "CipheredText.txt"));
                materialLabel3.Text = "Зашифрований текст";
            }
            else
            {
                MessageBox.Show("Введіть ключ та оберіть файл для шифрування даних");
            }
        }