示例#1
0
 public ActionResult DocxDecode(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.Decode(body, file.KeyFile);
             byte[] result = Parser.SaveDocx(body);
             string fName  = "Decoded.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);
        }
示例#3
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);
        }
示例#4
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);
        }
示例#5
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);
        }
示例#6
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);
        }
示例#7
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);
        }
示例#8
0
        public void DecodeEmpty()
        {
            string text   = "";
            string key    = "б";
            string result = Vigenere.Decode(text, key);

            Assert.AreEqual("", result);
        }
示例#9
0
        public void DecodeWrongLetters()
        {
            string text   = "Пrи8еТ";
            string key    = "б";
            string result = Vigenere.Decode(text, key);

            Assert.AreEqual("Оrз8дС", result);
        }
示例#10
0
        public void DecodeUpperLetters()
        {
            string text   = "ПривеТ";
            string key    = "б";
            string result = Vigenere.Decode(text, key);

            Assert.AreEqual("ОпзбдС", result);
        }
示例#11
0
        public void DecodeLowerLetters()
        {
            string text   = "привет";
            string key    = "б";
            string result = Vigenere.Decode(text, key);

            Assert.AreEqual("опзбдс", result);
        }
示例#12
0
        public void DecodeNull()
        {
            string text = null;
            string key  = "б";

            try
            {
                string result = Vigenere.Decode(text, key);
            }
            catch (Exception e)
            {
                Assert.AreEqual("Текст не может быть пустым!", e.Message);
            }
        }
示例#13
0
 public ActionResult TextDecode(Text text)
 {
     try
     {
         lastTextValue = Vigenere.Decode(text.TextValue, text.KeyText);
         lastKeyText   = text.KeyText;
     }
     catch (Exception e)
     {
         lastKeyText   = e.Message;
         lastTextValue = text.TextValue;
     }
     lastTextName = text.TextName;
     return(Redirect("/Home"));
 }