Пример #1
0
        private void EncodeButton_Click(object sender, RoutedEventArgs e)
        {
            if (data == null)
            {
                MessageBox.Show("Загрузите изображение");
                return;
            }
            Int32.TryParse(SizeTextBox.Text, out var size);
            size = size > 0 ? size : 500;
            var message = data.Split(size).ToArray();
            var result  = new EncryptedBlock <byte> [message.Count()];

            Parallel.For(0, message.Count(), (i) =>
            {
                var encoded = ArithmeticCoder.Encode(message[i].ToArray());
                result[i]   = new EncryptedBlock <byte>(encoded.Message, encoded.Ranges, encoded.Length);
            });
            MessageBox.Show("Изображение закодировано");
            encryptedBlocks = result;
        }
Пример #2
0
        private void OpenEncodeButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter = "Encoded files(*.dat)|*.dat";
            if (openFileDialog1.ShowDialog() != true)
            {
                return;
            }

            BinaryFormatter formatter = new BinaryFormatter();

            //read file
            //using FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.OpenOrCreate);
            EncryptedBlock <byte>[] encrypteds = Parser.Decode(File.ReadAllBytes(openFileDialog1.FileName));//(EncryptedBlock<byte>[])formatter.Deserialize(fs);

            //decode
            IEnumerable <byte>[] result = new IEnumerable <byte> [encrypteds.Length];
            Parallel.For(0, encrypteds.Count(), (i) =>
            {
                var temp    = encrypteds[i];
                var encoded = ArithmeticCoder.Decode(temp.Message, temp.Ranges, temp.Length);
                result[i]   = encoded;
            });

            //merge
            using MemoryStream image = new MemoryStream();
            foreach (var i in result)
            {
                image.Write(i.ToArray(), 0, i.Count());
            }


            var img = ConvertByteArrayToBitmapImage(image.ToArray());

            EncodedPicture.Source = img;
        }