View Full Version : راهنمائی

شنبه 04 خرداد 1392, 02:58 صبح
سلام دوستان :
کسی از شما درباره نهان نگاری اطلاعات در تصویر فایلی داره ؟
من می خوام در این زمینه تحقیق کنم .........اطلاعاتم زیاد ندارم کمکم کنید .

مصطفی ساتکی
شنبه 04 خرداد 1392, 07:29 صبح
steganography را در سایت جستجو کنید.
این هم یه نمونه کد ساده :

#include <stdio.h>
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <stdlib.h>

#define EXTRACT_BIT(n,i) ((n&(1<<i))?1:0)

int main(int argc, char **argv)
IplImage *input; // input image
IplImage *hide; // image to hide
IplImage *output; // output image

uchar *data;
uchar *inputData;
uchar *hideData;

int messageChar;
int i=0, j=0, dataPos = 48;
int height, width, nchannels;
int hideHeight, hideWidth, hideNchannels;

if(argc < 3)
printf("Usage : %s <input image filepath> <image to hide>\n", argv[0]);

input = cvLoadImage(argv[1], CV_LOAD_IMAGE_COLOR);
hide = cvLoadImage(argv[2], CV_LOAD_IMAGE_COLOR);

//input image height and width
height = input->height;
width = input->width;
nchannels = input->nChannels;
*Use 24 bits (1 bit per pixel) to save hide image height and width in output image

hideHeight = hide->height;
hideWidth = hide->width;
hideNchannels = hide->nChannels;

if(height*width < (hideHeight*hideWidth*8+48))
printf("Please input source image of larger size\n");

if(nchannels != 3 || hideNchannels != 3)
printf("Sorry currently only support for RGB images\n");

printf("Hiding image of size %d X %d in image of size %d X %d\n", hideHeight, hideWidth, height, width);

//make an empty image with the same width and height as that of input image
output = cvCreateImage(cvSize(width,height), IPL_DEPTH_8U,3);

data = (uchar *)output->imageData;
inputData = (uchar *)input->imageData;
hideData = (uchar *)hide->imageData;

//save the height and width in output image 24 pixels for height and 24 pixels for width
//save height
for(i=0; i<24; i++)
data[i] = inputData[i] & 254;
data[i] = data[i] + EXTRACT_BIT(hideHeight, i);
//save width
for(i=0; i<24; i++)
data[i+24] = inputData[i+24] & 254;
data[i+24] = data[i+24] + EXTRACT_BIT(hideWidth, i);

//start saving the image from the 48th pixel
for(i=0; i<hideHeight*hideWidth*3; i++)
messageChar = hideData[i];
//printf("%d\n", messageChar);
for(j=0; j<8; j++)
data[dataPos] = inputData[dataPos] & 254;
data[dataPos] = data[dataPos] + EXTRACT_BIT(messageChar, j);
//hiding image completes

//copy the rest of the image to the output image
for(j=dataPos; j<height*width*3; j++)
data[j] = inputData[j];

//save the image in bmp or png format because they are lossless compression

cvNamedWindow("Original Image", CV_WINDOW_AUTOSIZE);
cvNamedWindow("Hidden Message Image", CV_WINDOW_AUTOSIZE);
cvShowImage("Original Image", input);
cvShowImage("Hidden Message Image", output);


cvDestroyWindow("Original Image");
cvDestroyWindow("Hidden Message Image");

return 0;