1 //g++ cipher_jpg.cpp -o cipher_jpg -O3
3 //cipher_jpg ~/Pictures/ecuador\ 2013/IMG_7548.JPG 38762
4 //usage cipher_jpg image seed
14 typedef unsigned char uchar;
16 uchar modulo(int x,int N){ return (x % N + N) %N; }
18 void fxor(uchar *buf,int sz, int seed,int enc) {
21 for(int i=1;i<sz;i++) {
22 if(((uint)buf[i-1])==0xFF && ((uint)buf[i])==0xDA) {
23 cout<<"s "<<i+1<<endl;
26 if(((uint)buf[i-1])==0xFF && ((uint)buf[i])==0xD9) {
27 cout<<"e "<<i-2<<endl;
38 for(int i=0;i<(end-start)/10;i++) {
39 int p=lrand48()%(end-start)+start;
40 if(p<=start || p>=end)
42 while(buf[p-1]==255 || buf[p]==255 ){
43 p=lrand48()%(end-start)+start;
44 if(p<=start || p>=end)
47 uchar v=lrand48()%255;
49 buf[p]=modulo((int)buf[p]+(int)v,255);
52 buf[p]=modulo((int)buf[p]-(int)v,255);
59 int main(int argc, char **argv){
63 fp = fopen(argv[1], "r");
64 fseek(fp, 0L, SEEK_END);
66 fseek(fp, 0, SEEK_SET);
68 uchar *buf=(uchar*)malloc(sz);
69 uchar *buf2=(uchar*)malloc(sz);
70 fread(buf, sz, 1, fp);
74 int seed=atoi(argv[2]);
81 fp = fopen("lena2.jpg", "w");
82 fwrite (buf , 1, sz, fp);
85 for(int i=0;i<sz;i++) {
94 fp = fopen("lena3.jpg", "w");
95 fwrite (buf2 , 1, sz, fp);
103 uchar res=modulo(-1,255);
104 cout<<(int)res<<endl;