public static byte[] secretDataToByte(SecretData data) { if (data == null) { return(null); } //byte[] byteArray = null; //if (data.SecretText != "") //{ // Console.WriteLine(data.SecretText); // byteArray = Encoding.UTF8.GetBytes(data.SecretText); //} BinaryFormatter bf = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); bf.Serialize(ms, data); ms.Seek(0, 0); StreamReader rdr = new StreamReader(ms); string str = rdr.ReadToEnd(); byte[] byteArray = Encoding.ASCII.GetBytes(str); return(byteArray); }
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 Form1_Load(object sender, EventArgs e) { data = new SecretData(); //pictureBox3.Image = null; //stegoLength = 18; //byte[] outStream = System.Text.Encoding.ASCII.GetBytes(msg); //serverStream.Write(outStream, 0, outStream.Length); //serverStream.Close(); //serverStream.Flush(); }
public static SecretData byteToSecretData(byte[] array) { //Console.WriteLine(array.Length); //String msg = Encoding.UTF8.GetString(array); //SecretData data = new SecretData(); //data.SecretText = msg; //Console.WriteLine(msg); MemoryStream memStream = new MemoryStream(array); BinaryFormatter binForm = new BinaryFormatter(); //memStream.Write(array, 0, array.Length); memStream.Seek(0, 0); memStream.Position = 0; SecretData data = (SecretData)binForm.Deserialize(memStream); return(data); }
private void button1_Click(object sender, EventArgs e) { pictureBox1.Image = incomingData.stegoImage; stegoLength = incomingData.stegoLength; SecretData data = new SecretData(); if (data.SecretText != null) { data = Steganography.ExtractSecretData(incomingData.stegoImage, incomingData.stegoLength); textBox1.Text = data.SecretText; } else { pictureBox2.Image = incomingData.secretImage; } serverSocket.Stop(); }