static void Main(string[] args) { // Отладка. Замер времени выполнения Stopwatch sw = new Stopwatch(); // Входные данные Information.msg = "Helloooooworld----------F**K"; Information.key = "Nachalo"; Information.imgPath = @"C:\Users\Евгений\Pictures\check-in-minion-BMP.bmp"; Information.colorChanel = "B"; Information.container.xSize = 128; Information.container.ySize = 128; // Обработка входных данных // Явное преобразование регистра цветовой компоненты Information.colorChanel = Information.colorChanel.ToUpper(); // Преобразование секретного сообщения в массив бит BitArray msgBit = new BitArray(Encoding.UTF8.GetBytes(Information.msg)); // Получение изобрадения по выбранному цветовому каналу Bitmap img = new Bitmap(Information.imgPath, true); // Вывод информации о входных данных Console.WriteLine("Шифруемое сообщение: {0}", Information.msg); Console.WriteLine("Количество бит в сообщении: {0}", msgBit.Length); Console.WriteLine("Размер изображения: {0}х{1}", img.Width, img.Height); Console.WriteLine("Количество пикселей в изображении: {0}", img.Width * img.Height); Console.WriteLine("Размер контейнера: {0}x{1}", Information.container.xSize, Information.container.ySize); Console.WriteLine("Количество пикселей в контейнере: {0}", Information.container.xSize * Information.container.ySize); //// Замер времени выполнения //Console.WriteLine(); //Console.WriteLine("Получение цветового канала..."); //sw.Start(); //int[][] imgChanel = Utils.getColorChanel(img, Information.colorChanel); //sw.Stop(); //Console.WriteLine("Затрачено времени: {0}", sw.Elapsed); //sw.Reset(); PreparedData data = new PreparedData("code"); LeastSignificantBit lsb = new LeastSignificantBit(); string decrypt_message; lsb.Encrypt(ref data, 0); decrypt_message = lsb.Decrypt(ref data, Information.key, 0); //Block blockMethod = new Block(); //blockMethod.Coder(ref data, 10, 10); //blockMethod.Decoder(ref data, 10, 10, "Nachalo"); Console.WriteLine("Message is \"{0}\"", decrypt_message); // Чего потеря в весе почти в 2 раза? // #1 Отсутствие метаданных изображения Console.WriteLine(); Console.WriteLine("Запись обработанного цветового канала..."); sw.Start(); // Utils.setColorChanel(img, data.imgChanel, Information.colorChanel).Save(@"C:\Users\Евгений\Pictures\check-in-minion2.bmp"); sw.Stop(); Console.WriteLine("Затрачено времени: {0}", sw.Elapsed); Console.WriteLine(); Console.WriteLine("Выполнено"); Console.ReadLine(); }
private void button_Code_Click(object sender, EventArgs e) { int row; int col; try { row = Convert.ToInt32(textBox_Block_Diff_M.Text); col = Convert.ToInt32(textBox_Block_Diff_N.Text); } catch(Exception){ MessageBox.Show("В полях размера блока введены недопустимые символы"); return; } string colorComponent = "R"; if(radioButton_Red.Checked) colorComponent = "R"; else if(radioButton_Green.Checked) colorComponent = "G"; else if(radioButton_Blue.Checked) colorComponent = "B"; Regex pattern = new Regex(@"^\s*\d+\s*$"); if (pattern.IsMatch(textBox_Offset.Text) && pattern.IsMatch(textBox_M.Text) && pattern.IsMatch(textBox_N.Text) && Image_Default.Image != null) { string xSize; string ySize; if (radioButton_Block_Method.Checked) { xSize = textBox_M.Text; ySize = textBox_N.Text; } else { xSize = textBox_Block_Diff_M.Text; ySize = textBox_Block_Diff_N.Text; } Utils.initialize(imgPath, richTextBoxKey.Text, colorComponent, (textBox_Offset.Text.Length == 0 ? 0 : Convert.ToInt32(textBox_Offset.Text)), (xSize.Length == 0 ? 0 : Convert.ToInt32(xSize)), (ySize.Length == 0 ? 0 : Convert.ToInt32(ySize)), message_box.Text); preparedData = new PreparedData("code"); if (Utils.checkFields("code")) { MessageBox.Show("Одно или более полей - пустые"); return; } // Выполним шифрование информации в изображение //try //{ if (radioButtonLSB_Static.Checked) { Methods.LeastSignificantBit lsb = new Methods.LeastSignificantBit(); lsb.Encrypt(ref preparedData, Information.offset); } else if (radioButton_Block_Method.Checked) { Methods.Block.Block block = new Methods.Block.Block(); block.Coder(ref preparedData, Information.container.xSize, Information.container.ySize); } else if (radioButton_Block_Different_Shape.Checked) { Methods.Block_Different_Shape.Block_Different_Shape block = new Methods.Block_Different_Shape.Block_Different_Shape(); General.Point[] selectedPoints = null; General.Point[] notSelectedPoints = null; General.Utils.getShapePoints(row, col, boxes, out selectedPoints, out notSelectedPoints); block.Coder(ref preparedData, selectedPoints, notSelectedPoints, Information.container.xSize, Information.container.ySize); } //} //catch (Exception msg) //{ // MessageBox.Show("Произошли проблемы при шифровании.\n " + msg.Message); // return; //} MessageBox.Show("Шифрование прошло успешно"); } else { MessageBox.Show("Отсутствует изображение или поля имеют недопустимые символы"); return; } button_Save.Enabled = true; }