D:\DropBox\Dropbox\APIIT\Level 3\FYP\Coding\Finalzed\rRMS\rRMS\Stegnography\Stegnography.cs

Methods
first
using System;
using System.Drawing;
using NUnit.Framework;
using Microsoft.Pex.Framework;

namespace ImageServices
{
    /*
    STEGNOGRAPHY USING LSB SUBSTRITUTION
    *
    */
    [TestFixture]
    partial class Stegnography
    {
        //keeps the orginal ASCII message
        private String orginal_ASCII_Message;
        private String Binary_Message;

        private Color current_pixel_color = Color.Empty; //gets the current pixel color
        private Color stego_color = Color.Empty; //keeps the new color with embded data.

        private Color length_CurrentPixelsColor = Color.Empty;
        private Color length__StegoPixelColor = Color.Empty; 

        private Bitmap CoverImage;
        private Bitmap StegoImage;

        //class inits
        private TextEncoder TextEncode;

        /// <summary>
        /// Defult Constructor 
        /// </summary>
        /// 
        public Stegnography()
        {
        }

        /// <summary>
        /// This overload constructor will sets the message and coverImage and generate the binary stream
        /// </summary>
        /// <param name="Message">String Message which required to embded in the image</param>
        /// <param name="CoverImage">Image that carry the secriet data [Pass the Bitmap as a Bitmap Object]</param>
       
        public Stegnography(String Message, Bitmap CoverImage)
        {
            //sets the message
            this.orginal_ASCII_Message = Message;

            //gets th binary string
            this.TextEncode = new TextEncoder();
            this.TextEncode.setASCIIString(this.orginal_ASCII_Message); //sets the orginal ascii message
            this.Binary_Message = this.TextEncode.getBinaryString(); //gets the binary string as the ascii input

            this.CoverImage = CoverImage; //sets the inputed coverimage
            this.StegoImage = this.CoverImage; //sets the stego Image;
        }

        /// <summary>
        /// Generate the Stego-Image
        /// </summary>
        /// <returns>Returns Stego-Object</returns>
        /// 
        [Test]
        public Image getStegoImage()
        {
            int x = 0;
            int y = 0;

            int i = 0;

            int RGBcolorType = 0;

            char[] message_arr = this.Binary_Message.ToCharArray();
            char loc;
            int text_val;

            int length = this.getBinaryMessageLength();

            while (x <= this.CoverImage.Width)
            {
                if (i >= message_arr.Length)
                {
                    break;
                }

                if (x == this.CoverImage.Width)
                {
                    y++;
                    x = 0;
                }
                else
                { 
                }

                if (y == this.CoverImage.Height)
                {
                    break;
                }
                else
                {
                    RGBcolorType++;

                    if (RGBcolorType > 3) 
                    {
                        x++;
                        RGBcolorType = 1;
                    }

                    loc = message_arr[i];
                    i++;
                    text_val = int.Parse(loc.ToString());

                    if (x == this.CoverImage.Width)
                    {
                        y++;
                        x = 0;
                    }

                    try
                    {
                        this.current_pixel_color = this.CoverImage.GetPixel(x, y); //get the current pixel
                    }
                    catch
                    {
                    }
                    finally 
                    {
                        this.stego_color = this.getStegoColor(this.current_pixel_color, text_val, RGBcolorType); //gets the stego color
                        this.StegoImage.SetPixel(x, y, this.stego_color);
                    }

                    if (x == this.CoverImage.Width && y == this.CoverImage.Height)
                    {
                        break;
                    }
                }
            }

            return this.StegoImage;
        }

        /// <summary>
        /// </summary>
        /// <param name="orginal_color">Pixel Orginal Color</param>
        /// <param name="location_data">10101</param>
        /// <returns></returns>
        [PexMethod()]
        private Color getStegoColor(Color orginal_color, int location_data, int Color_type)
        {
            top|nextColor StegoColor = Color.Empty;

            int red = 0;
            int green = 0;
            int blue = 0;

            red = orginal_color.R;
            green = orginal_color.G;
            blue = orginal_color.B;

            //RED
            if (Color_type == 1)
            {
                if (location_data == 1 && this.checkOdd(red) == true)
                { // if Input Binary is 1 and Pixel Current LSB value is 1 NOTHING TO DO
                    // StegoColor = Color.FromArgb(temp_col, green, blue);
                    StegoColor = Color.FromArgb(red, green, blue);
                }
                else if (location_data == 1 && this.checkOdd(red) == false)
                { // if Input Binary is 1 and Pixel Current LSB value is 0 (+1)
                    int temp_col = Math.Abs(red - 1);
                    //StegoColor = Color.FromArgb(temp_col, green, blue);
                    StegoColor = Color.FromArgb(temp_col, green, blue);
                }
                else if (location_data == 0 && this.checkOdd(red) == true) // if Input Binary is 0 and Pixel Current LSB value is 1 (-1)
                {
                    int temp_color = Math.Abs(red - 1);
                    //StegoColor = Color.FromArgb(temp_color, green, blue);
                    StegoColor = Color.FromArgb(temp_color, green, blue);
                }
                else if (location_data == 0 && this.checkOdd(red) == false)  // if Input Binary is 0 and Pixel Current LSB value is 0 NOTHING TO DO
                {
                    // StegoColor = Color.FromArgb(red, green, blue);
                    StegoColor = Color.FromArgb(red, green, blue);
                }
                else
                {
                    //ehhh .. some thing wrong ! 
                }
            }
            //GREEN
            else if (Color_type == 2)
            {
                if (location_data == 1 && this.checkOdd(green) == true)
                { // if Input Binary is 1 and Pixel Current LSB value is 1 NOTHING TO DO
                    // StegoColor = Color.FromArgb(temp_col, green, blue);
                    StegoColor = Color.FromArgb(red, green, blue);
                }
                else if (location_data == 1 && this.checkOdd(green) == false)
                { // if Input Binary is 1 and Pixel Current LSB value is 0 (+1)
                    int temp_col = Math.Abs(green - 1);
                    //StegoColor = Color.FromArgb(temp_col, green, blue);
                    StegoColor = Color.FromArgb(red, temp_col, blue);
                }
                else if (location_data == 0 && this.checkOdd(green) == true) // if Input Binary is 0 and Pixel Current LSB value is 1 (-1)
                {
                    int temp_color = Math.Abs(green - 1);
                    //StegoColor = Color.FromArgb(temp_color, green, blue);
                    StegoColor = Color.FromArgb(red, temp_color, blue);
                }
                else if (location_data == 0 && this.checkOdd(green) == false)  // if Input Binary is 0 and Pixel Current LSB value is 0 NOTHING TO DO
                {
                    // StegoColor = Color.FromArgb(red, green, blue);
                    StegoColor = Color.FromArgb(red, green, blue);
                }
                else
                {
                    //ehhh .. some thing wrong ! 
                }
            }
            //BLUE
            else if (Color_type == 3)
            {
                if (location_data == 1 && this.checkOdd(blue) == true)
                { // if Input Binary is 1 and Pixel Current LSB value is 1 NOTHING TO DO
                    int temp_col = Math.Abs(blue - 1);
                    // StegoColor = Color.FromArgb(temp_col, green, blue);
                    StegoColor = Color.FromArgb(red, green, blue);
                }
                else if (location_data == 1 && this.checkOdd(blue) == false)
                { // if Input Binary is 1 and Pixel Current LSB value is 0 (+1)
                    int temp_col = Math.Abs(blue - 1);
                    //StegoColor = Color.FromArgb(temp_col, green, blue);
                    StegoColor = Color.FromArgb(red, green, temp_col);
                }
                else if (location_data == 0 && this.checkOdd(blue) == true) // if Input Binary is 0 and Pixel Current LSB value is 1 (-1)
                {
                    int temp_color = Math.Abs(blue - 1);
                    //StegoColor = Color.FromArgb(temp_color, green, blue);
                    StegoColor = Color.FromArgb(red, green, temp_color);
                }
                else if (location_data == 0 && this.checkOdd(blue) == false)  // if Input Binary is 0 and Pixel Current LSB value is 0 NOTHING TO DO
                {
                    // StegoColor = Color.FromArgb(red, green, blue);
                    StegoColor = Color.FromArgb(red, green, blue);
                }
                else
                {
                    //ehhh .. some thing wrong ! 
                }
            }
            else
            {
            }

            return StegoColor;
        }

        /// <summary>
        /// return the length on the binary message
        /// </summary>
        /// <returns></returns>
        /// 
        [Test]
        private int getBinaryMessageLength()
        {
            return this.Binary_Message.Length;
        }

        /// <summary>
        /// Returns if the Color Pixel value is Odd or Even
        /// </summary>
        /// <param name="color">Input as Color pixel value</param>
        /// <returns>Returns True or False</returns>
        [PexMethod()]
        private bool checkOdd(int color)
        {
            prev|topif (color % 2 != 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        ///getBinaryString
        [Test]
        public String getBinaryString()
        {
            return this.Binary_Message;
        }

        public Bitmap getBMP()
        {
            return this.StegoImage;
        }
    }
}

Copyright (c) Microsoft Corporation. All rights reserved.
Copy full source to clipboard