Steganography

by Andrew Sunday, 13 June 2010 07:45

I was reading about steganography this week and decided to have a play about. Here is the code I wrote:

 my code

Maybe with these three methods you can get it out, method 1:

// Decrypts a bitmap into a text file
private static void DecryptFile()
{
    // Get the bitmap
    FileInfo image = GetFileInfo("Enter path to encrypted bitmap:", true);
    Bitmap bmp;

    try
    {
        bmp = (Bitmap)Bitmap.FromFile(image.FullName);
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
        Console.WriteLine("Aborting");
        return;
    }

    int x = 0;
    int y = 0;

    StringBuilder stringBuilder = new StringBuilder();

    // Get the 3 characters from each pixel
    while (y < bmp.Height)
    {
        Color color = bmp.GetPixel(x, y);

        stringBuilder.Append(ColorToString(color));

        x++;

        if (x >= bmp.Width)
        {
            x = 0;
            y++;
        }
    }

    // Save decrypted text to file
    FileInfo saveFile = GetFileInfo("Enter path to save output:", false);

    try
    {
        using (StreamWriter stream = saveFile.AppendText())
        {
            stream.Write(stringBuilder.ToString());
        }
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
        Console.WriteLine("Aborting");
        return;
    }

    Console.WriteLine("Saved to " + saveFile.FullName);
}

 

Nice and simple, method 2:

// Convert a color to 3 char string
private static string ColorToString(Color color)
{
    return ASCIIEncoding.ASCII.GetString(new byte[] { color.R, color.G, color.B });
}

 

I’m not sure if the recursive calls are the best way to do this but it works well, method 3:

// Gets a FileInfo object by path input from the user
private static FileInfo GetFileInfo(string message, bool mustExist)
{
    Console.WriteLine(message);

    string filepath = Console.ReadLine();

    if (string.IsNullOrEmpty(filepath))
    {
        return GetFileInfo(message, mustExist);
    }

    FileInfo fileInfo;

    try
    {
        fileInfo = new FileInfo(filepath);
    }
    catch (Exception e)
    {
        // invalid file
        Console.WriteLine(e.Message);
        return GetFileInfo(message, mustExist);
    }

    if (!mustExist || fileInfo.Exists)
    {
        return fileInfo;
    }

    Console.WriteLine("File does not exist");

    return GetFileInfo(message, mustExist);
}

 

It’s not quite obscure enough yet but I will be doing some more reading into this and try to do more. For anyone interested the wikipedia page is a good place to start and has some interesting examples.

Tags: , , ,

.NET

My BlogEngine.NET Theme

by Andrew Wednesday, 12 May 2010 23:44

I’ve decided to put this on hold for now. I’ve got a few things that need to be done to deadlines just now and updating the theme is lower priority. It is partly done and can be seen here if you are interested.

In the mean time I will be spending my free time doing other things so expect some posts soon.

Tags:

BlogEngine.NET