Esempio n. 1
0
        static void Main(string[] args)
        {
            string texteClair   = null;
            string key          = null;
            string texteChiffre = null;

            Console.WriteLine("Quelle phrase voulez-vous encoder :");
            texteClair = Console.ReadLine();
            Console.WriteLine("Entrez votre clef :");
            key = Console.ReadLine();

            Vigenere vigenere = new Vigenere();

            texteChiffre = vigenere.Encrypt(texteClair, key);

            Console.WriteLine("\nTexte en claire : " + texteClair);
            Console.WriteLine("Cléf : " + key + "  ");
            Console.WriteLine("Texte chiffré : " + texteChiffre);

            texteClair = vigenere.Decrypt(texteChiffre, key);

            Console.WriteLine("\nTexte chiffré : " + texteChiffre);
            Console.WriteLine("Cléf : " + key + "  ");
            Console.WriteLine("Texte claire : " + texteClair);

            Console.Read();
        }
        public string ResetFileName()
        {
            string originalFilename = new Vigenere().full_key_decrypt(this.Name, this.SecureCode);

            this.Name = originalFilename.Substring(13);
            return(this.Name);
        }
Esempio n. 3
0
 public ActionResult DocxEncode(UploadedFile file)
 {
     lastKeyFile  = file.KeyFile;
     lastFileName = file.FileName;
     try
     {
         //"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
         using (MemoryStream ms = new MemoryStream())
         {
             byte[] arr = new byte[file.UploadedFileValue.ContentLength];
             file.UploadedFileValue.InputStream.Read(arr, 0, file.UploadedFileValue.ContentLength);
             ms.Write(arr, 0, arr.Length);
             string body = Parser.ParseDocx(ms);
             body = Vigenere.Encode(body, file.KeyFile);
             byte[] result = Parser.SaveDocx(body);
             string fName  = "Encoded.docx";
             if (file.FileName != null)
             {
                 fName = file.FileName + ".docx";
             }
             return(File(result, "application/docx", fName));
         }
     }
     catch (Exception e)
     {
         lastKeyFile = e.Message;
         return(Redirect("/Home"));
     }
 }
        public void IndexDecodeTextTest()
        {
            RedirectResult redir = controller.TextDecode(new Text("Привет мир!", "б", "test")) as RedirectResult;

            result = controller.Index() as ViewResult;
            Assert.AreEqual(Vigenere.Decode("Привет мир!", "б"), result.ViewBag.TextValue);
        }
Esempio n. 5
0
        public void Decrypt(string source, string key, string expected)
        {
            var    crypto = new Vigenere();
            string actual = crypto.Dencrypt(source, key);

            Assert.AreEqual(expected, actual);
        }
Esempio n. 6
0
        public void Encrypt_NullKeyProvided_ThrowException()
        {
            var source = "Hello";
            var cipher = new Vigenere();

            Assert.Throws(typeof(ArgumentNullException), delegate { cipher.Encrypt(source, null); });
        }
Esempio n. 7
0
        public void EncryptBasic()
        {
            Vigenere v             = new Vigenere("PALIMPSEST", new CipherNet.Common.Alphabet("KRYPTOS"));
            var      encryptedText = v.Encrypt("BETWEENSUBTLESHADINGANDTHEABSENCEOFLIGHTLIESTHENUANCEOFIQLUSION");

            Assert.AreEqual("EMUFPHZLRFAXYUSDJKZLDKRNSHGNFIVJYQTQUXQBQVYUVLLTREVJYQTMKYRDMFD", encryptedText);
        }
Esempio n. 8
0
        public void elegirAlgoritmo(string opcion)
        {
            string vigenere            = "Vigenere";
            string transposicion       = "Transposicion";
            string codificacionBinaria = "Binario";
            string palabraClave        = "Palabra Clave";

            if (opcion.Equals(vigenere))
            {
                anadirAlgoritmoALista(Vigenere.getVigenere());
            }
            else if (opcion.Equals(transposicion))
            {
                anadirAlgoritmoALista(Transposicion.getTransposicion());
            }
            else if (opcion.Equals(codificacionBinaria))
            {
                anadirAlgoritmoALista(CodificacionBinaria.getCodificacionBinaria());
            }
            else if (opcion.Equals(palabraClave))
            {
                anadirAlgoritmoALista(PalabraClave.getPalabraClave());
            }
            else
            {
                anadirTodoAlgoritmo();
            }
        }
Esempio n. 9
0
        static bool HomeworkSection1()
        {
            // Start finding key with only known cipher text attack
            bool successfull = DecryptWithKnownCipherText();

            // If known cipher text attack has not been successfull, try known plain text and cipher text attack.
            if (!successfull)
            {
                successfull = DecryptWithKnownPlainAndCipherText();
            }

            if (successfull)
            {
                // Decode the cipher text with the found keyword to check whether the found keyword is correct or not.
                Vigenere vigenere    = new Vigenere();
                string   decodedText = vigenere.Decode(cipherText, keywordText);

                if (decodedText == plainText)
                {
                    Console.WriteLine("Cipher text decrypted successfully!");
                }
            }

            return(successfull);
        }
Esempio n. 10
0
        public void DecodeWrongLetters()
        {
            string text   = "Пrи8еТ";
            string key    = "б";
            string result = Vigenere.Decode(text, key);

            Assert.AreEqual("Оrз8дС", result);
        }
Esempio n. 11
0
        public void EncodeWrongLetters()
        {
            string text   = "Пrи8еТ";
            string key    = "б";
            string result = Vigenere.Encode(text, key);

            Assert.AreEqual("Рrй8ёУ", result);
        }
Esempio n. 12
0
        public void DecodeUpperLetters()
        {
            string text   = "ПривеТ";
            string key    = "б";
            string result = Vigenere.Decode(text, key);

            Assert.AreEqual("ОпзбдС", result);
        }
Esempio n. 13
0
        public void EncodeUpperLetters()
        {
            string text   = "ПривеТ";
            string key    = "б";
            string result = Vigenere.Encode(text, key);

            Assert.AreEqual("РсйгёУ", result);
        }
Esempio n. 14
0
        public void EncodeLowerLetters()
        {
            string text   = "привет";
            string key    = "б";
            string result = Vigenere.Encode(text, key);

            Assert.AreEqual("рсйгёу", result);
        }
Esempio n. 15
0
 public IActionResult vg_decrypt(Vigenere vg)
 {
     vg.decrypted = "";
     vg.encrypted = Request.Form["encrypted"];
     vg.key       = Request.Form["key"];
     vg.processText();
     return(View("vigenere", vg));
 }
Esempio n. 16
0
        public void Encrypt_IncorrectInput_ThrowException()
        {
            var source = "Hello!";
            var key    = "key";
            var cipher = new Vigenere();

            Assert.Throws(typeof(ArgumentException), delegate { cipher.Encrypt(source, key); });
        }
Esempio n. 17
0
 void anadirTodoAlgoritmo()
 {
     algoritmos.Clear();
     algoritmos.Add(Vigenere.getVigenere());
     algoritmos.Add(Transposicion.getTransposicion());
     algoritmos.Add(CodificacionBinaria.getCodificacionBinaria());
     algoritmos.Add(PalabraClave.getPalabraClave());
 }
Esempio n. 18
0
        public void KeyCheckUpper()
        {
            string text   = "аааааа";
            string key    = "Абв";
            string result = Vigenere.Encode(text, key);

            Assert.AreEqual("абвабв", result);
        }
Esempio n. 19
0
        public void DecodeLowerLetters()
        {
            string text   = "привет";
            string key    = "б";
            string result = Vigenere.Decode(text, key);

            Assert.AreEqual("опзбдс", result);
        }
Esempio n. 20
0
        public void DecodeEmpty()
        {
            string text   = "";
            string key    = "б";
            string result = Vigenere.Decode(text, key);

            Assert.AreEqual("", result);
        }
Esempio n. 21
0
        public void DencryptEnumerable(string[] sources, string key, string[] expected)
        {
            var crypto = new Vigenere();

            string[] actual = crypto.Dencrypt(sources, key).ToArray();

            Assert.AreEqual(expected, actual);
        }
Esempio n. 22
0
        public void Decode_OnlyLatinAlphabet() // Проверка зашифровки файла содержащего только латинский алфавит
        {
            string input          = File.ReadAllText(@"../../testFiles/Decoding/Test3.txt", Encoding.UTF8);
            string expectedResult = File.ReadAllText(@"../../testFiles/Encoding/Test3.txt", Encoding.Default);

            input = Vigenere.Decode(input, "скорпион");
            Assert.AreEqual(input, expectedResult);
        }
Esempio n. 23
0
        private void VigenereDecode(object sender, RoutedEventArgs e)
        {
            Vigenere vigenere = new Vigenere();
            string   value    = VigenereDecodeInput.Text;
            string   key      = VigenereDecodeKeyInput.Text;

            VigenereDecodeOutput.Text = vigenere.Decrypt(value, key);
        }
Esempio n. 24
0
        public void Decode_OnlyNumbers() // Проверка зашифровки файла содержащего только цифры
        {
            string input          = File.ReadAllText(@"../../testFiles/Decoding/Test4.txt", Encoding.UTF8);
            string expectedResult = File.ReadAllText(@"../../testFiles/Encoding/Test4.txt", Encoding.Default);

            input = Vigenere.Decode(input, "скорпион");
            Assert.AreEqual(input, expectedResult);
        }
Esempio n. 25
0
        public void Decode_CyrilicLettersAndNumbers() // Проверка зашифровки файла содержащего цифры, буквы и пробельные символы
        {
            string input          = File.ReadAllText(@"../../testFiles/Decoding/Test2.txt", Encoding.UTF8);
            string expectedResult = File.ReadAllText(@"../../testFiles/Encoding/Test2.txt", Encoding.Default);

            input = Vigenere.Decode(input, "скорпион");
            Assert.AreEqual(input, expectedResult);
        }
Esempio n. 26
0
        public void Decode_OnlyCyrillicLetters() // Проверка шифрования файла содержащего только буквы и пробельные символы
        {
            string input          = File.ReadAllText(@"../../testFiles/Decoding/Test1.txt", Encoding.UTF8);
            string expectedResult = File.ReadAllText(@"../../testFiles/Encoding/Test1.txt", Encoding.Default);

            input = Vigenere.Decode(input, "скорпион");
            Assert.AreEqual(input, expectedResult);
        }
Esempio n. 27
0
        public void Encrypt_EmptyInput_EmptyOutput()
        {
            var source    = "";
            var key       = "key";
            var cipher    = new Vigenere();
            var encrypted = cipher.Encrypt(source, key);

            Assert.IsEmpty(encrypted);
        }
Esempio n. 28
0
        public void TestEncrypt()
        {
            IEnumerable <string> source = Program.Preprocess("ALPHA");
            string key      = "OMEGA";
            string expected = "OXTNA";
            string actual   = Vigenere.Encrypt(source, key).FirstOrDefault();

            Assert.AreEqual(expected, actual);
        }
Esempio n. 29
0
 private void chiffrerBtn_Click(object sender, EventArgs e)
 {
     if (textBox1.TextLength != 0 || textBox2.TextLength != 0)
     {
         Vigenere vigenere = new Vigenere();
         textBox3.Text       = vigenere.Encrypt((textBox1.Text), textBox2.Text);
         chiffrerBtn.Enabled = false;
     }
 }
Esempio n. 30
0
        public void TestDecrypt()
        {
            IEnumerable <string> encrypt = Program.Preprocess("ALPHA");
            string key      = "NU";
            string expected = "OXTCO";
            string actual   = Vigenere.Decrypt(encrypt, key).FirstOrDefault();

            Assert.AreNotEqual(expected, actual);
        }