HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpMinor

Steganography - images within images

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
withinimagessteganography

Problem

Normally, you would change the LSB of the RGB channels in a pixel, they would represent the bits you are storing in the image. My method differs in that I represent my bits as either odd or even numbers stored inside the image channels ARGB. So an odd number represents a 1 and an even number represents a 0.

I also can't find anything online that mentions doing this the way I decided to. Am I the "first" to do it this way? What other ways are there for doing this?

```
using System;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace Steganography
{
public partial class Steganography : Form
{
OpenFileDialog ofd = new OpenFileDialog();
SaveFileDialog sfd = new SaveFileDialog();

const string Filter = "Image Files (.png) | .png";
const string StartDir = @"./Images";

string _binImg = "";

public Steganography()
{
InitializeComponent();

ofd.Filter = Filter;
ofd.InitialDirectory = StartDir;

sfd.Filter = Filter;
sfd.InitialDirectory = StartDir;
}

#region #### Open Images ####
private void btnOpenBaseImage_Click(object sender, EventArgs e)
{
if (ofd.ShowDialog() == DialogResult.OK)
{
pbBaseImage.Image = new Bitmap(ofd.FileName);
}
}

private void btnOpenHideImage_Click(object sender, EventArgs e)
{
if (ofd.ShowDialog() == DialogResult.OK)
{
pbHideImage.Image = new Bitmap(ofd.FileName);

_binImg = ByteArrayToBinary(File.ReadAllBytes(ofd.FileName));
}
}
#endregion

#region #### Hide Image ####
///
/// Hide an image inside of another image
///
///
///
private void btnHideImage_Click(object sender, EventArgs e)
{
// We only want to run th

Solution


  • I notice that your functions are a mix of user-interface stuff and the actual functionality. When you're writing code, it's best to separate user interface code and business logic code. That way, if you ever change the user interface (say, switch from Windows Forms to WPF) you don't have to perform brain surgery to get your business logic code out of there.



  • Why are you converting the bytes to a binary string and then operating on individual '0' and '1' chars? It would make much more sense to work with the bits directly using bitwise operations. The whole ByteArrayToBinary() and BinaryToByteArray() are unnecessary.



  • Why did you create your own class Pixel? You don't ever use it; you're using System.Drawing.Color like you're supposed to?



  • GetNybbleFromPixelChannels() is inefficient, as it appends character-by-character onto a string. You should be using a StringBuilder for tasks like that (which you do in ByteArrayToBinary())

Context

StackExchange Code Review Q#87187, answer score: 5

Revisions (0)

No revisions yet.