/* Simple steg example by lovepump, (c) 2005 */ #include #include #include #include #include #include "steg.h" int main(int argc, char **argv) { FILE *in, *out; unsigned char *img, hash[20], *ct; unsigned long n, flen; int i, j, bitspixel, colmap; HDR *header; if(argc < 4) { printf("Usage: %s infile outfile text\n", argv[0]); printf("Where text is the phrase to SHA1 hash and steg\n"); return -1; } in = fopen(argv[1], "r"); out = fopen(argv[2], "w+"); fseek(in, 0, SEEK_END); flen = ftell(in); rewind(in); img = (char *)malloc(flen); header = (HDR*)img; fread(img, flen, 1, in); colmap = ((header->flags)>>7); bitspixel = ((header->flags & 7)+1); printf("GIF:\nWidth = %d, Height = %d\n", header->width, header->height); printf("Bits per pixel: %d, Colour map = %d\n", bitspixel, colmap); printf("Colour table size: %f bits, %f bytes.\n", pow(2,bitspixel), pow(2,bitspixel)/8); if(pow(2,bitspixel)/8 < 32) exit(-1); n = strlen(argv[3]); SHA1(argv[3], n, hash); ct = img + sizeof(header) + 7; for(i = 0; i < 20; i++) { for(j = 0; j < 8; j++) { *ct = (*ct & 254); if(hash[i] & 1) (*ct)++; hash[i]>>=1; ct++; } } fwrite(img, flen, 1, out); fclose(in); fclose(out); return 1; }