1 //g++ cipher_webp.cpp -o cipher_webp -O3
3 //usage image.webp seed
4 //cipher_webp im1.webp 3213
15 typedef unsigned char uchar;
17 uchar modulo(int x,int N){ return (x % N + N) %N; }
19 void fxor(uchar *buf,int sz, int seed,int enc) {
22 for(int i=1;i<sz;i++) {
23 if(((uint)buf[i-1])==0xFF && ((uint)buf[i])==0xDA) {
24 cout<<"s "<<i+1<<endl;
27 if(((uint)buf[i-1])==0xFF && ((uint)buf[i])==0xD9) {
28 cout<<"e "<<i-2<<endl;
35 cout<<"start "<<start<<" end "<<end<<endl;
40 for(int i=0;i<(end-start)/100;i++) {
41 int p=lrand48()%(end-start)+start;
44 while(buf[p-1]==255 || buf[p]==255 ){
45 // cout<<"PROUT"<<endl;
46 p=lrand48()%(end-start)+start;
50 uchar v=lrand48()%255;
52 buf[p]=modulo((int)buf[p]+(int)v,255);
57 buf[p]=modulo((int)buf[p]-(int)v,255);
64 for(int i=start;i<end+1;i++) {
66 cout<<"ARGH"<<(int)buf[i]<<(int)buf[i+1]<<endl;
69 // cout<<"ARGH"<<(int)buf[i-1]<<(int)buf[i]<<endl;
76 int main(int argc, char **argv){
80 fp = fopen(argv[1], "r");
81 fseek(fp, 0L, SEEK_END);
83 fseek(fp, 0, SEEK_SET);
85 uchar *buf=(uchar*)malloc(sz);
86 uchar *buf2=(uchar*)malloc(sz);
87 fread(buf, sz, 1, fp);
91 int seed=atoi(argv[2]);
98 fp = fopen("lena2.webp", "w");
99 fwrite (buf , 1, sz, fp);
102 for(int i=0;i<sz;i++) {
109 fxor(buf2,sz,seed,0);
111 fp = fopen("lena3.webp", "w");
112 fwrite (buf2 , 1, sz, fp);