internal static string GetHiddenValue(StegoBitmap bitmap, Channel channel) { byte[] hidden = bitmap.GetChannel(channel); bool[] headerBits = hidden.Take(16).SelectMany(x => GetNLastBit(x, 1)).ToArray(); byte E = BoolArrayToByte(headerBits.Take(8).ToArray()); byte lengthSize = BoolArrayToByte(headerBits.Skip(8).Take(8).ToArray()); bool[] lengthBits = hidden.Skip(16).Take(lengthSize * 8).SelectMany(x => GetNLastBit(x, 1)).ToArray(); List <byte> lengthBytes = new List <byte>(); for (int i = 0; i < lengthBits.Length; i += 8) { lengthBytes.Add(BoolArrayToByte(lengthBits.Skip(i).Take(8).ToArray())); } int length = GetIntFromBytes(lengthBytes); bool[] bits = hidden.Skip(16 + lengthSize * 8).Take(length * 8).SelectMany(x => GetNLastBit(x, 1)).ToArray(); List <byte> bytes = new List <byte>(); for (int i = 0; i < bits.Length; i += 8) { bytes.Add(BoolArrayToByte(bits.Skip(i).Take(8).ToArray())); } return(ByteArrayToString(bytes.ToArray())); }
internal static Bitmap Hide(StegoBitmap bitmap, string text, Channel channel) { byte[] sourceChannel = bitmap.GetChannel(channel); byte flag = Convert.ToByte('E'); byte size = GetSizeOfLength(text.Length); byte[] length = GetLengthInBytes(text.Length, size); byte[] stegoText = StringToByteArray(text); byte[] stegoBytes = new byte[1 + 1 + length.Length + stegoText.Length]; stegoBytes[0] = flag; stegoBytes[1] = size; int counter = 0; for (int i = 0; i < length.Length; i++) { stegoBytes[i + 2] = length[counter++]; } counter = 0; for (int i = 0; i < stegoText.Length; i++) { stegoBytes[i + 2 + length.Length] = stegoText[counter++]; } bool[] stegoBits = stegoBytes.SelectMany(x => ByteToBoolArray(x)).ToArray(); for (int i = 0; i < stegoBits.Length; i++) { if ((sourceChannel[i] % 2 == 0) && stegoBits[i]) { sourceChannel[i]++; } else if ((sourceChannel[i] % 2 == 1) && !stegoBits[i]) { sourceChannel[i]--; } } return(new StegoBitmap(bitmap, sourceChannel, channel).GetImage()); }