Steganography
Original Images
This is the image that will be used to hide the second image!https://www.hdwallpapers.net/abstract/colorful-diamond-wallpaper-674.htm
https://www.hdwallpapers.net/abstract/dark-wood-texture-wallpaper-383.htm
After the Hiding
This is what the image looks like with the hidden value:Algorithm
The algorithm used to hide an image inside another using 2 bits is quite similar to the 4 bits, but has some distinctive differences. Instead of using 2^4, or 16, as the number used for dividing, we will be using 2^2, or 4.The first two bits of the image to be hidden are selected using the shift function. Since it's a 2 bit hidden message, we take the two most significant bits of the image we are hiding, i.e., "Diamond.jpg", by dividing the pixel values by 64.
The first six bits of the image, "Dark Wood.jpg", are obtained using the chop2hide function.
Finally, the combined image is formed by adding the bits of the modified images together.
To get the hidden value back, we simply reverse what we have done to modify the image. This is implemented using the extract function.
Code
var start = new SimpleImage("Dark Wood.jpg");
var hide = new SimpleImage("Diamond.jpg");
function pixchange(pixval)
{
//Since it's only two bits, instead of 2^4, we use 2^2
var x = Math.floor(pixval/4) * 4;
return x;
}
//Function to alter the image to be hidden
function chop2hide(image)
{
for(var p of image.values())
{
p.setRed(pixchange(p.getRed()));
p.setGreen(pixchange(p.getGreen()));
p.setBlue(pixchange(p.getBlue()));
}
return image;
}
//Function to shift the bits of the main image
function shift(im)
{
var nim = new SimpleImage(im.getWidth(), im.getHeight());
for(var p of im.values())
{
var x = p.getX();
var y = p.getY();
var np = nim.getPixel(x,y);
np.setRed(Math.floor(p.getRed()/64));
np.setGreen(Math.floor(p.getGreen()/64));
np.setBlue(Math.floor(p.getBlue()/64));
}
return nim;
}
start_mod = chop2hide(start);
hide_mod = shift(hide);
print(starts); //Prints the first image modified
print(hides); // Prints the second image modified
//Function to add the two numbers
function add(a, b)
{
var ans = a + b;
return ans;
}
//Function to combine both images
function combine(st,hi)
{
var fin = new SimpleImage (st.getWidth(),st.getHeight());
for (var pixel_st of st.values())
{
var x = pixel_st.getX();
var y = pixel_st.getY();
var pixel_hi = hi.getPixel(x,y);
var pixel_fin = fin.getPixel(x,y);
pixel_fin.setRed(add(pixel_st.getRed(),pixel_hi.getRed()));
pixel_fin.setGreen(add(pixel_st.getGreen(),pixel_hi.getGreen()));
pixel_fin.setBlue(add(pixel_st.getBlue(),pixel_hi.getBlue()));
}
return fin;
}
combinedimage=combine(start_mod,hide_mod);
print(combinedimage); //Prints combined image
//Function to get the hidden value back
function pchange(pixval)
{
var x = (pixval-Math.floor(pixval/4)*4)*64;
return x;
}
//Function to extract the hidden image
function extract(image)
{
for(var pixel of image.values())
{
pixel.setRed(pchange(pixel.getRed()));
pixel.setGreen(pchange(pixel.getGreen()));
pixel.setBlue(pchange(pixel.getBlue()));
}
return image;
}
hiddenimage = extract(combinedimage);
print(hiddenimage); //Prints hidden image
Hidden Message in Given Picture
The following picture was given with a hidden message to extract:Algorithm
The algorithm used for the extraction is similar to the one used for extraction in the first part.Code
function pchange(pixval)
{
var x = (pixval-Math.floor(pixval/4)*4)*64;
return x;
}
function extract(image)
{
for(var pixel of image.values())
{
pixel.setRed(pchange(pixel.getRed()));
pixel.setGreen(pchange(pixel.getGreen()));
pixel.setBlue(pchange(pixel.getBlue()));
}
return image;
}
var combinedimage = new SimpleImage("hiltonHiding2bitMessage.png");
hiddenimage = extract(combinedimage);
print(hiddenimage);
No comments:
Post a Comment