private void button2_Click(object sender, EventArgs e) { button1.Enabled = true; button2.Enabled = false; button3.Enabled = true; incomingData = null; serverSocket.Start(); Console.WriteLine("Server Started"); clientSocket = serverSocket.AcceptTcpClient(); Console.WriteLine("Accept connection from client"); BinaryFormatter bformatter = new BinaryFormatter(); NetworkStream networkStream = clientSocket.GetStream(); incomingData = (PacketData)bformatter.Deserialize(networkStream); Console.WriteLine(incomingData.stegoLength); SecretData tempSecretDt = new SecretData(); tempSecretDt.SecretImage = incomingData.secretImage; tempSecretDt.SecretText = incomingData.secretText; byte[] secretByte = Converter.secretDataToByte(tempSecretDt); Console.WriteLine(secretByte.Length); ElementRGB carrier = Converter.imageToElementRGB(incomingData.realImage); temp = Steganography.CreateStegoImage(carrier, secretByte, (Bitmap)incomingData.realImage); }
public static SecretData ExtractSecretData(Image StegoImage, int stegoLength) { //Operasi extraksi secret data di sini List <int> embededData = new List <int>(); int s1, s2, s3; ElementRGB rgbData = Converter.imageToElementRGB(StegoImage); for (int i = 0; i < stegoLength; i++) { s1 = rgbData.Red.ElementAt(i) % 3; s2 = rgbData.Green.ElementAt(i) % 3; s3 = rgbData.Blue.ElementAt(i) % 3; embededData.Add(s1); embededData.Add(s2); embededData.Add(s3); } //while ((embededData.Count % 8) != 0) embededData.RemoveAt(embededData.Count - 1); int[] base3Data = new int[embededData.Count]; for (int i = 0; i < embededData.Count; i++) { base3Data[i] = embededData.ElementAt(i); } int[] base2Data = Converter.base3ToBase2(base3Data); BitArray binaryData = Converter.NumericToBinary(base2Data); byte[] byteData = Converter.ToByteArray(binaryData); SecretData secretData = Converter.byteToSecretData(byteData); return(secretData); }
private void btnCreateStegoImage_Click(object sender, EventArgs e) { //data = new SecretData(); data.SecretImage = new Bitmap(pictureBox2.Image); byte[] secretByte = Converter.secretDataToByte(data); ElementRGB carrier = Converter.imageToElementRGB(pictureBox1.Image); Console.WriteLine(secretByte.Length); pictureBox3.Image = Steganography.CreateStegoImage(carrier, secretByte, (Bitmap)pictureBox1.Image); stegoLength = carrier.StegoLength; pictureBox3.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox3.Refresh(); btnSendImage.Enabled = true; MessageBox.Show("Stego Image Created"); }
public static Image elementRGBToImage(ElementRGB data) { Bitmap img = new Bitmap(data.width, data.height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); int i = 0; for (int x = 0; x < data.width; x++) { for (int y = 0; y < data.height; y++) { Color imageColor = Color.FromArgb(data.Red.ElementAt(i), data.Green.ElementAt(i), data.Blue.ElementAt(i)); img.SetPixel(x, y, imageColor); i++; } } return(img); }
public static ElementRGB imageToElementRGB(Image img) { ElementRGB raw = new ElementRGB(); Bitmap inputImage = new Bitmap(img); Color pixelColor = new Color(); raw.width = inputImage.Width; raw.height = inputImage.Height; raw.Red = new List <int>(); raw.Green = new List <int>(); raw.Blue = new List <int>(); for (int x = 0; x < inputImage.Width; x++) { for (int y = 0; y < inputImage.Height; y++) { pixelColor = inputImage.GetPixel(x, y); if (int.Parse(pixelColor.R.ToString()) != 0) { if (int.Parse(pixelColor.R.ToString()) == 255) { raw.Red.Add(int.Parse(pixelColor.R.ToString()) - 2); } else { raw.Red.Add(int.Parse(pixelColor.R.ToString())); } } else { raw.Red.Add(2); } if (int.Parse(pixelColor.G.ToString()) != 0) { if (int.Parse(pixelColor.G.ToString()) == 255) { raw.Green.Add(int.Parse(pixelColor.G.ToString()) - 2); } else { raw.Green.Add(int.Parse(pixelColor.G.ToString())); } } else { raw.Green.Add(2); } if (int.Parse(pixelColor.B.ToString()) != 0) { if (int.Parse(pixelColor.B.ToString()) == 255) { raw.Blue.Add(int.Parse(pixelColor.B.ToString()) - 2); } else { raw.Blue.Add(int.Parse(pixelColor.B.ToString())); } } else { raw.Blue.Add(2); } } } return(raw); }
public static Image CreateStegoImage(ElementRGB rawData, byte[] secretData, Bitmap carrierImage) { Bitmap StegoImage = carrierImage; BitArray secretBits = Converter.ToBitArray(secretData); int[] numericBits = Converter.BinaryToNumeric(secretBits); int[] base3Data = Converter.base2ToBase3(numericBits); //Operasi Steganography di sini temp = new int[base3Data.Length + 1]; int[] embededData = new int[base3Data.Length + 1]; for (int i = 0; i < base3Data.Length; i++) { embededData[i] = base3Data[i]; temp[i] = base3Data[i]; } embededData[base3Data.Length] = 0; int index = 0; int ptr = 0; int f1, f2, f3; for (int x = 0; x < rawData.width; x++) { for (int y = 0; y < rawData.height; y++) { if (ptr + 2 <= base3Data.Length) { //Manipulasi Pixel////////// //MessageBox.Show(rawData.Red.ElementAt(index) + " " + rawData.Green.ElementAt(index) + " " + rawData.Blue.ElementAt(index)); f1 = rawData.Red.ElementAt(index) % 3; f2 = rawData.Green.ElementAt(index) % 3; f3 = rawData.Blue.ElementAt(index) % 3; /////////////////////////////////////////////////////////////////////////////// if (f1 == embededData.ElementAt(ptr)) { rawData.Red[index] = rawData.Red.ElementAt(index); } else { rawData.Red[index] = rawData.Red.ElementAt(index) + embededData.ElementAt(ptr) - f1; } ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// if (f2 == embededData.ElementAt(ptr + 1)) { rawData.Green[index] = rawData.Green.ElementAt(index); } else { rawData.Green[index] = rawData.Green.ElementAt(index) + embededData.ElementAt(ptr + 1) - f2; } ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// if (f3 == embededData.ElementAt(ptr + 2)) { rawData.Blue[index] = rawData.Blue.ElementAt(index); } else { rawData.Blue[index] = rawData.Blue.ElementAt(index) + embededData.ElementAt(ptr + 2) - f3; } ///////////////////////////////////////////////////////////////////////////////// //MessageBox.Show(f1+" "+embededData.ElementAt(ptr)+" "+f2+" "+embededData.ElementAt(ptr+1)+" "+f3+" "+embededData.ElementAt(ptr+2)+"\n"+rawData.Red.ElementAt(index)+" "+rawData.Green.ElementAt(index)+" "+rawData.Blue.ElementAt(index)); ptr += 3; //////////////////////////// Color imageColor; //if (rawData.Blue.ElementAt(index) != -1 && rawData.Red.ElementAt(index)!= -1 && rawData.Green.ElementAt(index)!=-1) { imageColor = Color.FromArgb(rawData.Red.ElementAt(index), rawData.Green.ElementAt(index), rawData.Blue.ElementAt(index)); StegoImage.SetPixel(x, y, imageColor); } index++; } } } rawData.StegoLength = index; return(StegoImage); }