예제 #1
0
 private static void getPlainText(InfoAboutFile info, string fileToEncode, bool procType) // if file size more than 256 bytes, then need read file few times and return part of file
 {
     char[] array;
     if (procType)
     {
         using (StreamReader fstream = new StreamReader(fileToEncode, Encoding.Default))
         {
             Console.WriteLine("read File to encode");
             Console.WriteLine(fstream.BaseStream.Length);
             sizeOfSourceMess = fstream.BaseStream.Length;
             array            = new char[fstream.BaseStream.Length];
             fstream.Read(array, 0, array.Length);
             info.plainText = new string(array);
         }
     }
     else
     {
         using (StreamReader fstream = new StreamReader(fileToEncode, Encoding.UTF8))
         {
             Console.WriteLine("read File to decode");
             Console.WriteLine(fstream.BaseStream.Length);
             array = new char[fstream.BaseStream.Length];
             fstream.Read(array, 0, array.Length);
             info.plainText = new string(array);
         }
     }
 }
예제 #2
0
        private void Decode(object sender, RoutedEventArgs e)
        {
            if (!filenameEnc.fileIsEmpty() && !cypherKey.Text.fileIsEmpty())
            {
                string        key          = cypherKey.Text;
                string        fileToDecode = @"D:\RealEncAndCom\noteEncode.txt";
                string        decodedPath  = @"D:\RealEncAndCom\noteDecode" + fileExtension;
                InfoAboutFile encodedFile  = new InfoAboutFile();

                File.Delete(decodedPath);
                getPlainText(encodedFile, fileToDecode, false);
                string decodedText = rc4plus(encodedFile.plainText, key);
                decodedText = decodedText.Substring(0, (int)sizeOfSourceMess);
                processText(decodedPath, decodedText, false);
                decLabel1.Content = "Файл был расшифрован!";
            }
            else
            {
                decLabel1.Content = "Файл не был расшифрован!";
            }
        }
예제 #3
0
        private void Encode(object sender, RoutedEventArgs e)
        {
            if (!filenameEnc.fileIsEmpty() && !cypherKey.Text.fileIsEmpty())
            {
                string        key          = cypherKey.Text;
                string        fileToEncode = filenameEnc;
                string        encodePath   = @"D:\RealEncAndCom\noteEncode.txt";
                InfoAboutFile file         = new InfoAboutFile();

                File.Delete(encodePath);
                getPlainText(file, fileToEncode, true);
                string encodedText = rc4plus(file.plainText, key);
                processText(encodePath, encodedText, true);

                encLabel1.Content = "Файл был зашифрован!";
            }
            else
            {
                encLabel1.Content = "Файл не был зашифрован";
            }
        }