We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, i'm a member of a 3 person group, we are in 12th Grade in France and we have the project to create a programme in processing which would encrypt an imported image and decrypt it on demand using the steganography process.
We made 3 programmes:
The first programme import an image and show it to the user and it encrypts it and make a mask. (the encrypted image + XOR + the mask = the imported image)
the second programme we made is about encrypting the image imported
and the third programme is about decrypting the encrypted image.
The problem we have is that, because of our poor english and java skills we can't put the 3 programmes in one...
Answers
The program which decrypt is this one
//image chiffrée = masque xor image secrète
PImage imgA,imgB, imgC; //A=masque, B=image chiffrée, C=image secrète int display; int nbPixels; int[] tabA, tabB, tabC; color bl, wh;
void setup() { size(600,600); imgA = loadImage("A.png"); imgB = loadImage("B.png");
nbPixels=imgA.height*imgA.width; tabA=new int[nbPixels]; tabB=new int[nbPixels]; tabC=new int[nbPixels];
bl=color(0); wh=color(255);
AnalyseImgA();
AnalyseImgB();
decryptage(); display=3; }
void draw() { if (display==3) { imageC(); image(imgC,0,0); } }
void AnalyseImgA() { imgA.loadPixels();
for (int y=0 ; y < imgA.height ; y=y+1) //loop hauteur (y) { for (int x=0 ; x < imgA.width ; x=x+1) //loop largeur (x) { color c = imgA.get(x,y); if (c==bl) tabA[x+(yimgA.width)]=0; else tabA[x+(yimgA.width)]=1; } } }
void AnalyseImgB() { imgB.loadPixels();
for (int y=0 ; y < imgB.height ; y=y+1) //loop hauteur (y) { for (int x=0 ; x < imgB.width ; x=x+1) //loop largeur (x) { color c = imgB.get(x,y); if (c==bl) tabB[x+(yimgB.width)]=0; else tabB[x+(yimgB.width)]=1; } } }
void decryptage() { for (int i=0 ; i < nbPixels ; i=i+1) { if (tabA[i]==tabB[i]) tabC[i]=0; else tabC[i]=1; } }
void imageC() { imgC=createImage(354, 450, RGB); imgC.loadPixels();
for(int i=0 ; i < nbPixels ; i=i+1) { if(tabC[i]==0) imgC.pixels[i]=wh; else imgC.pixels[i]=bl; }
imgC.updatePixels(); }
The one which encrypt is this one
Here are drive links to download the data images
https://drive.google.com/open?id=0B18AnLNEtpN7b29Od253Sm9fYjg
https://drive.google.com/open?id=0B18AnLNEtpN7a1NDTk5QWl9ZTWM
https://drive.google.com/open?id=0B18AnLNEtpN7TjRMakhqeWlDLWc
Both programs works separetely but we cannot figure out how to put them together
We did this but it doesn't work and it only has the decrypting code in it..
Steganography is about hiding information in plain sight so it is not really about encryption. In fact there is a steganography library for Processing but you won't be able to use that because it is a class exercise.
So to help discuss this I will define the two images
burden the image to hide
carrier the image to hide the burden in.
The carrier image with burden should look just like the original version. Hence hiding in plain sight.
I will call the process of putting the burden into the carrier image , encoding and the process of extracting the burden image from the carrier image, decoding
When an image is stored in RAM , each pixel is a 32-bit integer, comprising of four 8-bit channels i.e. ARGB. This diagram shows how the channels are arranged inside the integer
The four channels are
alpha (transparency)
red
green
blue
and each channel is just a single byte e.g.
MSB = most significant bit LSB = least significant bit
Steganography takes advantage of the fact that the 4 least significant bits (0-3) have virtually no visible effect on the actual colour displayed. It means that we can have any values we like in bits 0-3 without the effect being visible in the image.
Therefore we can use up to 4 bits per channel (bpc) to store the burden image
The same rule applies for the burden image so in theory the carrier and burden images can be exactly the same size but in reality they will be different so you would also need to store the width and height of the burden image in the carrier image as well as the pixel data.
To continue this I will define some more terms
cp[?]
is a pixel from the carrier image pixel arraybp[?]
is a pixel from the burden image pixel arraycw
&ch
= width and height of the carrier imagebw
&bh
= width and height of the burden imageSo how to encode the burden image into the carrier image
IMPORTANT: this only works if
cw * ch >= bw * bh - 2
the two bytes is to store bw and bhStep 1
Loop through the carrier image array zeroing the lower 4 bits with
cp[i] = cp[i] & 0xF0F0F0F0;
Step 2
Loop through the burden pixel array to remove lower 4 bits and shift the high bits right
bp[i] = (bp[i] & 0xF0F0F0F0) >>> 4;
Step 3
Merge the carrier and burden arrays
cp[i] = cp[i] | bp[i];
Step 4
Store the burden image size
cp[cw * ch -2] = bw;
cp[cw * ch -1] = bh;
Step 5
Store the image as a png file. IMPORTANT the image format MUST be lossless.
Decoding the burden is the reverse process.
There are lots of improvements that can be made to this algorithm but I doubt whether your tutor will mind.
I have just noticed you have posted a lot of code since I started this comment. C'est la vie
Hi quark and thank you !
I read your comment but i didn't understand everything, but it wasn't really our question haha ^^'
The fact is that we learnt javascool for only months and we have other majors in France (Mathematics, Physics/Chemistry, Biology and 4 others..) the fact is that we had only 3-4months to work on this project and we only had the time to make it work for b&w images.. the different programs themselves work but we don't know how to put them together as the 3rd program which didn't work..
Thank you for your post, it's very interesting to read it but we didn't ask for "how steganography works" but for "how to put those programs together to make them work" sorry for my english ^^'
My reply was based on your first comment above. It doesn't just explain how steganography works it also provides algorithms for encoding the steganograph which could be used to create a program.
Unfortunately you posted the code you wanted to merge 28 minutes after your first comment so I didn't notice it until I came to post the comment.
Hopefully someone else will find the information useful :)
Good luck with your assignment :)