Ejemplo n.º 1
0
        public void TestReader()
        {
            CStreamWriter writer = new CStreamWriter();

            // put 6 bytes
            writer.Write(ShortData);
            CStreamReader reader = writer.CreateReader();

            // length==6, position==0
            Assert.AreEqual(0, reader.Position);
            Assert.AreEqual(ShortData.Length, reader.Length);

            // try to read more bytes than available
            byte[] buf = new byte[ShortData.Length * 1000];
            Assert.AreNotEqual(buf.Length, ShortData.Length);
            Assert.IsFalse(buf.SequenceEqual(ShortData));
            int read = reader.Read(buf);

            Assert.AreEqual(ShortData.Length, read);

            // assert the first few bytes are still correct
            byte[] buf2 = new byte[ShortData.Length];
            Array.Copy(buf, buf2, buf2.Length);
            Assert.IsTrue(buf2.SequenceEqual(ShortData));

            // not swapped
            Assert.IsFalse(reader.IsSwapped);
        }
Ejemplo n.º 2
0
 public void Dispose()
 {
     stop               = false;
     inputKey           = null;
     outputStreamWriter = null;
     inputStream        = null;
 }
Ejemplo n.º 3
0
        private static void SetEncodings(Encoding inputEncoding, Encoding outputEncoding)
        {
            stderr = new UnexceptionalStreamWriter(OpenStandardError(0), outputEncoding);
            ((StreamWriter)stderr).AutoFlush = true;
            stderr = TextWriter.Synchronized(stderr, true);

#if NET2_API && !NET_2_1
            if (!Environment.IsRunningOnWindows && ConsoleDriver.IsConsole)
            {
                StreamWriter w = new CStreamWriter(OpenStandardOutput(0), outputEncoding);
                w.AutoFlush = true;
                stdout      = TextWriter.Synchronized(w, true);
                stdin       = new CStreamReader(OpenStandardInput(0), inputEncoding);
            }
            else
            {
#endif
            stdout = new UnexceptionalStreamWriter(OpenStandardOutput(0), outputEncoding);
            ((StreamWriter)stdout).AutoFlush = true;
            stdout = TextWriter.Synchronized(stdout, true);
            stdin  = new UnexceptionalStreamReader(OpenStandardInput(0), inputEncoding);
            stdin  = TextReader.Synchronized(stdin);
#if NET2_API && !NET_2_1
        }
#endif

            GC.SuppressFinalize(stdout);
            GC.SuppressFinalize(stderr);
            GC.SuppressFinalize(stdin);
        }
Ejemplo n.º 4
0
        public void Dispose()
        {
            try
            {
                stop     = false;
                inputKey = null;
                inputIV  = null;

                if (outputStreamWriter != null)
                {
                    outputStreamWriter.Dispose();
                    outputStreamWriter = null;
                }

                if (p_crypto_stream != null)
                {
                    p_crypto_stream.Flush();
                    p_crypto_stream.Close();
                    p_crypto_stream = null;
                }
            }
            catch (Exception ex)
            {
                GuiLogMessage(ex.Message, NotificationLevel.Error);
            }
            this.stop = false;
        }
Ejemplo n.º 5
0
        public void Dispose()
        {
            try
            {
                stop         = false;
                inputKey     = null;
                inputIV      = null;
                inputStream  = null;
                outputStream = null;

                if (p_crypto_stream_dec != null)
                {
                    p_crypto_stream_dec.Flush();
                    p_crypto_stream_dec.Close();
                    p_crypto_stream_dec = null;
                }

                if (p_crypto_stream_enc != null)
                {
                    p_crypto_stream_enc.Flush();
                    p_crypto_stream_enc.Close();
                    p_crypto_stream_enc = null;
                }
            }
            catch (Exception exception)
            {
                GuiLogMessage(exception.Message, NotificationLevel.Error);
            }

            this.stop = false;
        }
Ejemplo n.º 6
0
        /// <summary>Create output stream to display.</summary>
        /// <param name="bitmap">The bitmap to display.</param>
        private void CreateOutputStream(Bitmap bitmap)
        {
            // Avoid smoothing of WPF
            if (settings.PresentationStep > 2)
            {
                bitmap = ResizeBitmap(bitmap);
            }
            ImageFormat format = ImageFormat.Bmp;

            if (settings.OutputFileFormat == 1)
            {
                format = ImageFormat.Png;
            }
            else if (settings.OutputFileFormat == 2)
            {
                format = ImageFormat.Tiff;
            }

            // Avoid "generic error in GDI+"
            Bitmap saveableBitmap = CopyBitmap(bitmap, format);

            // Save bitmap
            MemoryStream outputStream = new MemoryStream();

            saveableBitmap.Save(outputStream, format);
            saveableBitmap.Dispose();
            bitmap.Dispose();

            OutputImage = new CStreamWriter(outputStream.GetBuffer());
        }
Ejemplo n.º 7
0
        public void TestSwapWithReader()
        {
            CStreamWriter writer = new CStreamWriter();
            CStreamReader reader = writer.CreateReader();

            // write, not swapped
            writer.Write(LongData);
            Assert.IsFalse(writer.IsSwapped);

            // read a few bytes, but there are still a few bytes left
            byte[] buf = new byte[ShortData.Length];
            reader.Read(buf);
            Assert.IsTrue(reader.Position > 0);
            Assert.IsTrue(reader.Length > reader.Position);

            // fill buffer, assert swap
            writer.Write(LongData);
            writer.Write(LongData);
            Assert.IsTrue(writer.IsSwapped);
            Assert.IsTrue(reader.IsSwapped);

            // try to read more than available, receive less
            buf = new byte[writer.Length * 2];
            int read = reader.Read(buf);

            Assert.IsTrue(read < buf.Length);

            // close writer, assert EOF
            writer.Close();
            int result = reader.ReadByte();

            Assert.AreEqual(-1, result);
        }
Ejemplo n.º 8
0
        private void sendOracleRequest()
        {
            if (!idle)
            {
                byte[] outputData = new byte[2 * blockSize];

                for (int byteCounter = 0; byteCounter < blockSize; byteCounter++)
                {
                    //corrupted preliminary/iv block
                    outputData[byteCounter] = corruptedBlock[byteCounter];

                    //cipher block
                    outputData[byteCounter + blockSize] = cipherBlock[byteCounter];
                }

                padStreamWriter = new CStreamWriter(outputData);

                requestsSent++;
                changePres(pres.outCounter, requestsSent.ToString());

                //GuiLogMessage("SendRequest", NotificationLevel.Info);

                idle = true;

                OnPropertyChanged("PaddingOracleOutput");
            }
        }
Ejemplo n.º 9
0
        public void TestSeek()
        {
            CStreamWriter writer = new CStreamWriter();

            writer.Write(LongData);
            writer.Close();

            CStreamReader reader = writer.CreateReader();

            byte[] buf = new byte[1024];

            { // seek 5 bytes before EOF, attempt to read much, get 5 bytes
                reader.Seek(LongData.Length - 5, SeekOrigin.Begin);
                int read = reader.Read(buf, 0, int.MaxValue);
                Assert.AreEqual(5, read);
            }

            { // read EOF
                int read = reader.Read(buf, 0, int.MaxValue);
                Assert.AreEqual(0, read);
            }

            { // seek beyond stream length, read EOF
                reader.Seek(LongData.Length * 3, SeekOrigin.Begin);
                int read = reader.Read(buf, 0, int.MaxValue);
                Assert.AreEqual(0, read);
            }

            { // seek back, read again
                reader.Seek(LongData.Length - 5, SeekOrigin.Begin);
                int read = reader.Read(buf, 0, int.MaxValue);
                Assert.AreEqual(5, read);
            }
        }
Ejemplo n.º 10
0
        /// <summary>Save an image to a file</summary>
        /// <param name="bitmap">The iamge to save</param>
        private void CreateOutputStream(Bitmap bitmap)
        {
            ImageFormat format = ImageFormat.Bmp;

            if (settings.OutputFileFormat == 1)
            {
                format = ImageFormat.Png;
            }
            else if (settings.OutputFileFormat == 2)
            {
                format = ImageFormat.Tiff;
            }

            //avoid "generic error in GDI+"
            Bitmap saveableBitmap = CopyBitmap(bitmap, format);

            //save bitmap
            MemoryStream outputStream = new MemoryStream();

            saveableBitmap.Save(outputStream, format);
            saveableBitmap.Dispose();
            bitmap.Dispose();

            OutputCarrier = new CStreamWriter(outputStream.GetBuffer());
        }
Ejemplo n.º 11
0
        public void TestSeekSwap()
        {
            CStreamWriter writer = new CStreamWriter();

            writer.Write(LongData);

            CStreamReader reader = writer.CreateReader();

            byte[] buf = new byte[1024];

            // seek 5 bytes before EOF
            reader.Seek(LongData.Length - 5, SeekOrigin.Begin);

            // write more, ensure swap
            writer.Write(LongData);
            writer.Write(LongData);
            Assert.IsTrue(writer.IsSwapped);

            { // seek somewhere to the middle, read
                reader.Seek(LongData.Length * 2, SeekOrigin.Begin);
                int read = reader.Read(buf);
                Assert.AreEqual(buf.Length, read);
            }

            { // seek beyond length, assert still open, get EOF
                reader.Seek(LongData.Length * 3, SeekOrigin.Current);
                Assert.IsFalse(writer.IsClosed);
                int read = reader.Read(buf);
                Assert.AreEqual(0, read);
            }
        }
Ejemplo n.º 12
0
        public void TestExistingFileReader()
        {
            string     tempFile   = DirectoryHelper.GetNewTempFilePath();
            FileStream tempWriter = new FileStream(tempFile, FileMode.CreateNew);

            tempWriter.Write(ShortData, 0, ShortData.Length);
            tempWriter.Write(LongData, 0, LongData.Length);
            tempWriter.Close();

            CStreamWriter cstream = new CStreamWriter(tempFile);
            CStreamReader reader  = cstream.CreateReader();

            byte[] buf = new byte[ShortData.Length];
            reader.ReadFully(buf);
            Assert.IsTrue(buf.SequenceEqual(ShortData));

            buf = new byte[LongData.Length];
            reader.ReadFully(buf);
            Assert.IsTrue(buf.SequenceEqual(LongData));

            // force gc
            reader  = null;
            cstream = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();

            File.Delete(tempFile);
        }
Ejemplo n.º 13
0
 public void Dispose()
 {
     try
     {
         stop               = false;
         counter            = 0;
         lengthOfInputByte  = 0;
         lengthOfOutputByte = 0;
         inputByteKey       = null;
         iV         = null;
         outputByte = null;
         crc32      = null;
         key        = null;
         if (internalInputByteList != null)
         {
             internalInputByteList.Clear();
         }
         internalInputByteList = null;
         inputStream           = null;
         //if (outputByteList != null) { outputByteList.Clear(); }
         //outputByteList = null;
         outputStreamWriter = null;
         if (internalInputByteList != null)
         {
             internalInputByteList.Clear();
         }
         //internalInputByteList = null;
     }
     catch (Exception exc)
     {
         GuiLogMessage(exc.Message.ToString(), NotificationLevel.Error);
     }
     this.stop = false;
 }
Ejemplo n.º 14
0
        public void Execute()
        {
            if (InputStreamOne == null || InputStreamTwo == null)
            {
                return;
            }

            using (CStreamReader reader1 = InputStreamOne.CreateReader(), reader2 = InputStreamTwo.CreateReader())
            {
                outputStreamWriter = new CStreamWriter();
                EventsHelper.PropertyChanged(PropertyChanged, this, "OutputStream");

                int    bytesRead;
                byte[] buffer = new byte[1024];

                // Input One
                while ((bytesRead = reader1.Read(buffer)) > 0)
                {
                    outputStreamWriter.Write(buffer, 0, bytesRead);
                }
                // Input Two
                while ((bytesRead = reader2.Read(buffer)) > 0)
                {
                    outputStreamWriter.Write(buffer, 0, bytesRead);
                }

                outputStreamWriter.Close();
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Called every time this plugin is run in the workflow execution.
        /// </summary>
        public virtual void Execute()
        {
            ProgressChanged(0, 1);

            GuiLogMessage(Properties.Resources.LogExecutionStarted, NotificationLevel.Info);
            GuiLogMessage(string.Format(Properties.Resources.LogSettings, settings), NotificationLevel.Info);
            GuiLogMessage(string.Format(Properties.Resources.LogInput, InputKey.Length * 8, InputIV.Length * 8, InitialCounter), NotificationLevel.Info);

            Validate();
            if (IsValid)
            {
                OnPropertyChanged(ChaChaPresentationViewModel.RESET_VISUALIZATION);
                ClearIntermediateResults();
                outputWriter          = new CStreamWriter();
                keystreamOutputWriter = new CStreamWriter();
                // If InitialCounter is not set by user, it defaults to zero.
                // Since maximum initial counter by any version is 64-bit, we cast it to UInt64.
                ulong initialCounter = (ulong)InitialCounter;
                Xcrypt(InputKey, InputIV, initialCounter, settings, InputStream, outputWriter, keystreamOutputWriter);
                OnPropertyChanged("OutputStream");
                OnPropertyChanged("KeystreamOutputStream");
            }

            ExecutionFinished = true;

            ProgressChanged(1, 1);
        }
Ejemplo n.º 16
0
        static void SetupStreams(Encoding inputEncoding, Encoding outputEncoding)
        {
#if !NET_2_1
            if (!Environment.IsRunningOnWindows && ConsoleDriver.IsConsole)
            {
                StreamWriter w = new CStreamWriter(OpenStandardOutput(0), outputEncoding);
                w.AutoFlush = true;
                stdout      = TextWriter.Synchronized(w, true);

                w           = new CStreamWriter(OpenStandardOutput(0), outputEncoding);
                w.AutoFlush = true;
                stderr      = TextWriter.Synchronized(w, true);

                stdin = new CStreamReader(OpenStandardInput(0), inputEncoding);
            }
            else
            {
#endif
#if FULL_AOT_RUNTIME
            Type nslogwriter = Type.GetType("MonoTouch.Foundation.NSLogWriter, monotouch, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");
            stdout = (TextWriter)Activator.CreateInstance(nslogwriter);
#else
            stdout = new UnexceptionalStreamWriter(OpenStandardOutput(0), outputEncoding);
            ((StreamWriter)stdout).AutoFlush = true;
#endif
            stdout = TextWriter.Synchronized(stdout, true);

#if FULL_AOT_RUNTIME
            stderr = (TextWriter)Activator.CreateInstance(nslogwriter);
#else
            stderr = new UnexceptionalStreamWriter(OpenStandardError(0), outputEncoding);
            ((StreamWriter)stderr).AutoFlush = true;
#endif
            stderr = TextWriter.Synchronized(stderr, true);

            stdin = new UnexceptionalStreamReader(OpenStandardInput(0), inputEncoding);
            stdin = TextReader.Synchronized(stdin);
#if !NET_2_1
        }
#endif

#if NET_4_5
            console_stderr = stderr;
            console_stdout = stdout;
            console_stdin  = stdin;
#endif

#if MONODROID
            if (LogcatTextWriter.IsRunningOnAndroid())
            {
                stdout = TextWriter.Synchronized(new LogcatTextWriter("mono-stdout", stdout));
                stderr = TextWriter.Synchronized(new LogcatTextWriter("mono-stderr", stderr));
            }
#endif  // MONODROID

            GC.SuppressFinalize(stdout);
            GC.SuppressFinalize(stderr);
            GC.SuppressFinalize(stdin);
        }
Ejemplo n.º 17
0
 public void Dispose()
 {
     if (outputStreamWriter != null)
     {
         outputStreamWriter.Dispose();
         outputStreamWriter = null;
     }
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Close open file. Will be called when deleting an element instance from workspace.
 /// </summary>
 public void Dispose()
 {
     if (cstreamWriter != null)
     {
         cstreamWriter.Dispose();
         cstreamWriter = null;
     }
     fileInputPresentation.CloseFileToGetFileStreamForExecution();
     fileInputPresentation.dispose();
 }
Ejemplo n.º 19
0
        static void SetupStreams(Encoding inputEncoding, Encoding outputEncoding)
        {
#if !NET_2_1
            if (!Environment.IsRunningOnWindows && ConsoleDriver.IsConsole)
            {
                StreamWriter w = new CStreamWriter(OpenStandardOutput(0), outputEncoding);
                w.AutoFlush = true;
                stdout      = TextWriter.Synchronized(w, true);

                w           = new CStreamWriter(OpenStandardOutput(0), outputEncoding);
                w.AutoFlush = true;
                stderr      = TextWriter.Synchronized(w, true);

                stdin = new CStreamReader(OpenStandardInput(0), inputEncoding);
            }
            else
            {
#endif
// FULL_AOT_RUNTIME is used (instead of MONOTOUCH) since we only want this code when running on
// iOS (simulator or devices) and *not* when running tools (e.g. btouch #12179) that needs to use
// the mscorlib.dll shipped with Xamarin.iOS
#if MONOTOUCH && FULL_AOT_RUNTIME
            stdout = new NSLogWriter();
#else
            stdout = new UnexceptionalStreamWriter(OpenStandardOutput(0), outputEncoding);
            ((StreamWriter)stdout).AutoFlush = true;
#endif
            stdout = TextWriter.Synchronized(stdout, true);

#if MONOTOUCH && FULL_AOT_RUNTIME
            stderr = new NSLogWriter();
#else
            stderr = new UnexceptionalStreamWriter(OpenStandardError(0), outputEncoding);
            ((StreamWriter)stderr).AutoFlush = true;
#endif
            stderr = TextWriter.Synchronized(stderr, true);

            stdin = new UnexceptionalStreamReader(OpenStandardInput(0), inputEncoding);
            stdin = TextReader.Synchronized(stdin);
#if !NET_2_1
        }
#endif

#if MONODROID
            if (LogcatTextWriter.IsRunningOnAndroid())
            {
                stdout = TextWriter.Synchronized(new LogcatTextWriter("mono-stdout", stdout));
                stderr = TextWriter.Synchronized(new LogcatTextWriter("mono-stderr", stderr));
            }
#endif  // MONODROID

            GC.SuppressFinalize(stdout);
            GC.SuppressFinalize(stderr);
            GC.SuppressFinalize(stdin);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// HOWTO: Enter the algorithm you'd like to implement in this method.
        /// </summary>
        public void Execute()
        {
            // no progress, yet
            ProgressChanged(0, 1);

            if (InputCarrier == null)
            {
                GuiLogMessage("Please specify an input file.", NotificationLevel.Error);
                return;
            }

            using (CStreamReader midiReader = InputCarrier.CreateReader())
            {
                MemoryStream    secretStream;
                MemoryStream    outputStream = new MemoryStream();
                MidiFileHandler midiHandler  = new MidiFileHandler();

                switch (settings.Action)
                {
                case 0:         // Encryption
                    using (CStreamReader messageReader = InputData.CreateReader())
                    {
                        secretStream = new MemoryStream(messageReader.ReadFully());
                        midiHandler.HideOrExtract(midiReader, secretStream, new MemoryStream(), outputStream, (byte)(settings.MaxMessageBytesPerCarrierUnit * 2), false);
                    }
                    OutputCarrier = new CStreamWriter(outputStream.ToArray());
                    OnPropertyChanged("OutputCarrier");
                    break;

                case 1:         // Decryption
                    secretStream = new MemoryStream();
                    midiHandler.HideOrExtract(midiReader, secretStream, new MemoryStream(), outputStream, 1, true);
                    //OutputData = new CStreamWriter(secretStream.GetBuffer());

                    secretStream.Position = 0;
                    using (StreamReader secretReader = new StreamReader(secretStream))
                    {
                        OutputText = secretReader.ReadToEnd();
                        OnPropertyChanged("OutputText");
                    }
                    break;
                }
            }

            // HOWTO: After you have changed an output property, make sure you announce the name of the changed property to the CT2 core.
            //OnPropertyChanged("Difference");

            // HOWTO: You can pass error, warning, info or debug messages to the CT2 main window.
            //if (settings.Subtrahend < 0)
            //    GuiLogMessage("Subtrahend is negative", NotificationLevel.Debug);

            // HOWTO: Make sure the progress bar is at maximum when your Execute() finished successfully.
            ProgressChanged(1, 1);
        }
Ejemplo n.º 21
0
        static void SetupStreams(Encoding inputEncoding, Encoding outputEncoding)
        {
#if !NET_2_1
            if (!Environment.IsRunningOnWindows && ConsoleDriver.IsConsole)
            {
                StreamWriter w = new CStreamWriter(OpenStandardOutput(0), outputEncoding, true);
                w.AutoFlush = true;
                stdout      = TextWriter.Synchronized(w);

                w           = new CStreamWriter(OpenStandardOutput(0), outputEncoding, true);
                w.AutoFlush = true;
                stderr      = TextWriter.Synchronized(w);

                stdin = new CStreamReader(OpenStandardInput(0), inputEncoding);
            }
            else
            {
#endif
#if MONOTOUCH
            stdout = new NSLogWriter();
#else
            stdout = new UnexceptionalStreamWriter(OpenStandardOutput(0), outputEncoding);
            ((StreamWriter)stdout).AutoFlush = true;
#endif
            stdout = TextWriter.Synchronized(stdout);

#if MONOTOUCH
            stderr = new NSLogWriter();
#else
            stderr = new UnexceptionalStreamWriter(OpenStandardError(0), outputEncoding);
            ((StreamWriter)stderr).AutoFlush = true;
#endif
            stderr = TextWriter.Synchronized(stderr);

            stdin = new UnexceptionalStreamReader(OpenStandardInput(0), inputEncoding);
            stdin = TextReader.Synchronized(stdin);
#if !NET_2_1
        }
#endif

#if MONODROID
            if (LogcatTextWriter.IsRunningOnAndroid())
            {
                stdout = TextWriter.Synchronized(new LogcatTextWriter("mono-stdout", stdout));
                stderr = TextWriter.Synchronized(new LogcatTextWriter("mono-stderr", stderr));
            }
#endif  // MONODROID

            GC.SuppressFinalize(stdout);
            GC.SuppressFinalize(stderr);
            GC.SuppressFinalize(stdin);
        }
Ejemplo n.º 22
0
        public void TestDestructorWithReader()
        {
            CStreamWriter writer = new CStreamWriter();

            // write, not swapped
            writer.Write(LongData);

            // read something and assert there's more
            CStreamReader reader = writer.CreateReader();

            byte[] buf = new byte[ShortData.Length];
            reader.Read(buf);
            Assert.IsTrue(reader.Position > 0);
            Assert.IsTrue(reader.Length > reader.Position);
            Assert.IsFalse(reader.IsSwapped);

            // write more, assert swap
            writer.Write(LongData);
            writer.Write(LongData);
            Assert.IsTrue(reader.IsSwapped);

            string filePath = writer.FilePath;

            // destroy ref to writer
            writer.Close();
            writer = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
            Assert.IsNull(writer);

            // assert reading still works
            Assert.IsTrue(File.Exists(filePath));
            Assert.IsNotNull(reader);
            int sum = 0;

            while (sum < LongData.Length * 2)
            {
                int read = reader.Read(buf);
                Assert.IsTrue(read > 0);
                sum += read;
            }

            // destroy reader
            reader = null;

            GC.Collect();
            GC.WaitForPendingFinalizers();

            // deleted tempfile
            Assert.IsFalse(File.Exists(filePath));
        }
Ejemplo n.º 23
0
        public void TestWriter()
        {
            CStreamWriter writer = new CStreamWriter();

            // put 6 bytes
            writer.Write(ShortData);

            // length == position == 6
            Assert.AreEqual(ShortData.Length, writer.Length);
            Assert.AreEqual(ShortData.Length, writer.Position);

            // not swapped
            Assert.IsFalse(writer.IsSwapped);
        }
Ejemplo n.º 24
0
        //Some functions for creating the image output / doing manipulations
        private void CreateOutputStream(Bitmap bitmap)
        {
            ImageFormat format = ImageFormat.Bmp;

            Bitmap saveableBitmap = CopyBitmap(bitmap, format);

            MemoryStream outputStream = new MemoryStream();

            saveableBitmap.Save(outputStream, format);
            saveableBitmap.Dispose();
            bitmap.Dispose();

            OutputPicture = new CStreamWriter(outputStream.GetBuffer());
        }
Ejemplo n.º 25
0
        public void StegoLSBTestMethod()
        {
            var pluginInstance = TestHelpers.GetPluginInstance("StegoLeastSignificantBit");
            var scenario       = new PluginTestScenario(pluginInstance, new[] { "InputData", "InputCarrier", "InputPassword", ".Action", ".CustomizeRegions", ".OutputFileFormat" }, new[] { "OutputData", "OutputCarrier" });

            CStreamWriter carrierImage = new CStreamWriter("..\\..\\Templates\\Steganography\\cryptool2.jpg", true);

            foreach (TestVector vector in testvectors)
            {
                object[] output1 = scenario.GetOutputs(new object[] { vector.message.ToStream(), carrierImage, vector.password.ToStream(), 0, false, 1 });
                object[] output2 = scenario.GetOutputs(new object[] { null, (ICryptoolStream)output1[1], vector.password.ToStream(), 1, false, 1 });
                // check if hiding and extracting the secret message leaves it unchanged
                Assert.AreEqual(vector.message, ((ICryptoolStream)output2[0]).ToByteArray().ToString2(), "Unexpected value in test #" + vector.n + ".");
            }
        }
Ejemplo n.º 26
0
        public void TestExhaustiveRead()
        {
            CStreamWriter writer = new CStreamWriter();

            writer.Write(LongData);
            writer.Write(LongData);
            writer.Write(LongData);
            writer.Close();

            CStreamReader reader = writer.CreateReader();

            byte[] bigbuf = reader.ReadFully();

            Assert.AreEqual(LongData.Length * 3, bigbuf.Length);
        }
Ejemplo n.º 27
0
 public void Dispose()
 {
     try
     {
         inputInt      = 0;
         packetCounter = 0;
         stop          = false;
         outputStream  = null;
         rnd           = null;
     }
     catch (Exception exc)
     {
         GuiLogMessage(exc.Message, NotificationLevel.Error);
     }
     this.stop = false;
 }
Ejemplo n.º 28
0
        public void Execute()
        {
            if (amountOfNumbers <= 0)
            {
                GuiLogMessage("Negative amount of numbers cant be generated", NotificationLevel.Warning);
                ProgressChanged(1, 1);
                return;
            }

            if (hasSeed)
            {
                setSeed(seed);
            }

            ProgressChanged(0, 1);

            CStreamWriter writer = new CStreamWriter();

            data = writer;
            uint current;

            byte[] nextData;
            outputNumbers = new BigInteger[amountOfNumbers];

            for (int i = 0; i < amountOfNumbers; i++)
            {
                // nothing to say here, it is simple writing the necessary amount of uints onto the stream
                current          = getNextUInt();
                outputNumbers[i] = current;
                nextData         = BitConverter.GetBytes(current);
                if (littleEndian)
                {
                    Array.Reverse(nextData);
                }
                writer.Write(nextData);
                ProgressChanged(i, amountOfNumbers);
            }
            writer.Close();

            OnPropertyChanged("OutputData");
            OnPropertyChanged("OutputNumbers");
            GuiLogMessage("Generation finished", NotificationLevel.Debug);

            ProgressChanged(1, 1);
        }
Ejemplo n.º 29
0
        private void processInput(string value)
        {
            ShowProgress(50, 100);

            //ShowStatusBarMessage("Converting input ...", NotificationLevel.Debug);

            switch (settings.PresentationFormatSetting)
            {
            case StringDecoderSettings.PresentationFormat.Base64:
                outputBytes = Convert.FromBase64String(value);
                break;

            case StringDecoderSettings.PresentationFormat.Octal:
                outputBytes = ToByteArray(value, ".{1,3}", "[^0-7]", 8);
                break;

            case StringDecoderSettings.PresentationFormat.Decimal:
                outputBytes = ToByteArray(value, ".{1,3}", "[^0-9]", 10);
                break;

            case StringDecoderSettings.PresentationFormat.Binary:

                outputBytes = ToByteArray(value, ".{1,8}", "[^01]", 2);
                break;

            case StringDecoderSettings.PresentationFormat.Hex:
                outputBytes = ToByteArray(value, ".{1,2}", "[^a-fA-F0-9]", 16);
                break;

            case StringDecoderSettings.PresentationFormat.Text:
            default:
                outputBytes = GetBytesForEncoding(value, settings.Encoding);
                break;
            }

            outputStream = new CStreamWriter(outputBytes);

            //ShowStatusBarMessage("Input converted.", NotificationLevel.Debug);

            ShowProgress(100, 100);

            OnPropertyChanged("OutputBytes");
            OnPropertyChanged("OutputStream");
        }
Ejemplo n.º 30
0
        public void Execute()
        {
            if (string.IsNullOrWhiteSpace(settings.OpenFilename))
            {
                GuiLogMessage("No input file selected, can't proceed", NotificationLevel.Error);
                return;
            }

            try
            {
                cstreamWriter = new CStreamWriter(settings.OpenFilename, true);
                NotifyPropertyChange();
                fileInputPresentation.makeUnaccesAble(false);
            }
            catch (FileNotFoundException ex)
            {
                GuiLogMessage(string.Format("File not found: '{0}'", settings.OpenFilename), NotificationLevel.Error);
            }
        }