--- /dev/null
+//g++ cipher_jpg.cpp -o cipher_jpg -O3
+
+//cipher_jpg ~/Pictures/ecuador\ 2013/IMG_7548.JPG 38762
+//usage cipher_jpg image seed
+
+#include <iostream>
+#include <fstream>
+#include <iterator>
+#include <vector>
+
+
+using namespace std;
+
+typedef unsigned char uchar;
+
+uchar modulo(int x,int N){ return (x % N + N) %N; }
+
+void fxor(uchar *buf,int sz, int seed,int enc) {
+ int start,end;
+
+ for(int i=1;i<sz;i++) {
+ if(((uint)buf[i-1])==0xFF && ((uint)buf[i])==0xDA) {
+ cout<<"s "<<i+1<<endl;
+ start=i+16;//not nice
+ }
+ if(((uint)buf[i-1])==0xFF && ((uint)buf[i])==0xD9) {
+ cout<<"e "<<i-2<<endl;
+ end=i-2;
+ }
+ }
+
+
+
+
+ srand48(seed);
+
+
+ for(int i=0;i<(end-start)/10;i++) {
+ int p=lrand48()%(end-start)+start;
+ if(p<=start || p>=end)
+ cout<<"pb"<<endl;
+ while(buf[p-1]==255 || buf[p]==255 ){
+ p=lrand48()%(end-start)+start;
+ if(p<=start || p>=end)
+ cout<<"pb"<<endl;
+ }
+ uchar v=lrand48()%255;
+ if(enc) {
+ buf[p]=modulo((int)buf[p]+(int)v,255);
+ }
+ else {
+ buf[p]=modulo((int)buf[p]-(int)v,255);
+ }
+ }
+
+}
+
+
+int main(int argc, char **argv){
+ cout<<argv[1]<< endl;
+
+ FILE *fp;
+ fp = fopen(argv[1], "r");
+ fseek(fp, 0L, SEEK_END);
+ int sz = ftell(fp);
+ fseek(fp, 0, SEEK_SET);
+
+ uchar *buf=(uchar*)malloc(sz);
+ uchar *buf2=(uchar*)malloc(sz);
+ fread(buf, sz, 1, fp);
+ fclose(fp);
+
+
+ int seed=atoi(argv[2]);
+ cout<<sz<<endl;
+
+
+ fxor(buf,sz,seed,1);
+
+
+ fp = fopen("lena2.jpg", "w");
+ fwrite (buf , 1, sz, fp);
+ fclose(fp);
+
+ for(int i=0;i<sz;i++) {
+ buf2[i]=buf[i];
+ }
+
+
+
+
+ fxor(buf2,sz,seed,0);
+
+ fp = fopen("lena3.jpg", "w");
+ fwrite (buf2 , 1, sz, fp);
+ fclose(fp);
+
+
+
+
+
+
+ uchar res=modulo(-1,255);
+ cout<<(int)res<<endl;
+ cout<<-1%255<<endl;
+}
}
else if(h==32) {
-
+ /*
Y[0]=X[0]^X[1]^X[2]^X[3]^X[4]^X[7]^X[8]^X[10]^X[12]^X[15]^X[16]^X[17]^X[18]^X[20]^X[21]^X[24]^X[25]^X[28]^X[30];
Y[1]=X[0]^ X[1]^X[2]^X[3]^X[5]^X[6]^X[9]^X[11]^X[13]^X[14]^X[16]^X[17]^X[19]^X[20]^X[21]^ X[24]^X[25]^X[29]^X[31];
Y[2]=X[0]^X[1]^X[2]^X[3]^X[5]^X[6]^X[8]^X[10]^X[13]^X[14]^X[16]^X[18]^X[19]^X[22]^X[23]^X[26]^X[27]^X[28]^X[30];
Y[29]=X[2]^X[3]^X[6]^X[7]^X[14]^X[15]^X[17]^X[19]^X[20]^X[23]^X[24]^X[27]^X[29]^X[30]^X[31];
Y[30]=X[1]^X[2]^X[4]^X[5]^X[12]^X[13]^X[16]^X[18]^X[20]^X[23]^X[24]^X[27]^X[28]^X[29]^X[30];
Y[31]=X[2]^X[3]^X[4]^X[5]^X[12]^X[13]^X[17]^X[19]^X[21]^X[22]^X[25]^X[26]^X[28]^X[29]^X[31];
+*/
+
+
+ uchar X0=X[0];
+ uchar X1=X[1];
+ uchar X2=X[2];
+ uchar X3=X[3];
+ uchar X4=X[4];
+ uchar X5=X[5];
+ uchar X6=X[6];
+ uchar X7=X[7];
+ uchar X8=X[8];
+ uchar X9=X[9];
+ uchar X10=X[10];
+ uchar X11=X[11];
+ uchar X12=X[12];
+ uchar X13=X[13];
+ uchar X14=X[14];
+ uchar X15=X[15];
+ uchar X16=X[16];
+ uchar X17=X[17];
+ uchar X18=X[18];
+ uchar X19=X[19];
+ uchar X20=X[20];
+ uchar X21=X[21];
+ uchar X22=X[22];
+ uchar X23=X[23];
+ uchar X24=X[24];
+ uchar X25=X[25];
+ uchar X26=X[26];
+ uchar X27=X[27];
+ uchar X28=X[28];
+ uchar X29=X[29];
+ uchar X30=X[30];
+ uchar X31=X[31];
+
+ Y[0]=X0^X1^X2^X3^X4^X7^X8^X10^X12^X15^X16^X17^X18^X20^X21^X24^X25^X28^X30;
+ Y[1]=X0^ X1^X2^X3^X5^X6^X9^X11^X13^X14^X16^X17^X19^X20^X21^ X24^X25^X29^X31;
+ Y[2]=X0^X1^X2^X3^X5^X6^X8^X10^X13^X14^X16^X18^X19^X22^X23^X26^X27^X28^X30;
+ Y[3]=X0^X1^X2^X3^X4^X7^X9^X11^X12^X15^X17^X18^X19^X22^X23^X26^X27^X29^X31;
+ Y[4]=X0^X3^X5^X6^X7^X10^X11^ X12^X13^X14^ X15^X16^X19^X21^X23^ X25^X27^X30^X31;
+ Y[5]=X1^X2^X4^X6^X7^X10^X11^X12^X13^X14^X16 ^X17^X18^X20^X22^X24^X26^X30^X31;
+ Y[6]=X1^X2^X4^X5^X7^X8^X9^X12^X13^X14^X15^ X17^X18^X21^X23^X25^X27^X28^X29;
+ Y[7]=X0^X3^X4^X5^X6^X9 ^X9^X12^X13^X14^X15^X16^X19^X20^X22^X24^X26^X28^X29;
+ Y[8]=X0^X2^X6^X7^X8^X10^X11^X14^X15^X16^X18^X21^X22^X25^X26;
+ Y[9]=X1^ X3^X6^X7^X9^X10^X11^X14^X15^X17^X19^X20^X23^X24^X27;
+ Y[10]=X0^X2^X4^X5^X8^X9^X10^X12^X13^X16^X18^X20^X23^ X24^X27;
+ Y[11]=X1^X3^X4^X5^X8^X9^X11^X12^X13^X17^X19^X21^X22^X25^X26;
+ Y[12]=X0^X3^X4^X5^X6^X7^X10^X11^X13^X14^X15^X16^X19^X21^X23^X25^X27^X30^X31;
+ Y[13]=X1^X2^X4^X5^X6^X7^X10^X11^X12^X14^X15^X17^ X18^X20^X22^X24^X26^X30^X31;
+ Y[14]=X1^X2^X4^X5^X6^X7^X8^X9^X12^X13^X15^X17^X18^X21^X23^X25^X27^X28^X29;
+ Y[15]=X0^X3^X4^X5^X6^X7^X8^X9^X12^X13^X14^X16^X19^X20^X22^ X24^X26^X28^X29;
+ Y[16]=X0^X1^X2^X4^X8 ^X8^X10^X13 ^X15^X16^X17^X18^X19^X20^X21^X24^X25^X28^X30;
+ Y[17]=X0^X1^X3^X5^X6^X9^X11^X13^X14^X16^X17^X18^X19^X20^X21^X24^X25^X29^X31;
+ Y[18]=X0^X2^X3^X5^X6^X8^X10^X13^X14^X16^X17^X18^X19^X22^X23^X26^X27^X28^X30;
+ Y[19]=X1^X2^X3^X4^X7^X9^X11^X12^X15^X16^X17^X18^X19^X22^X23^X26^X28 ^X29^X31;
+ Y[20]=X0^X1^X5^X7^X10 ^X10^X13^X15^X16^X17^X20^X21^X23^X29^X30;
+ Y[21]=X0^X1^X4^X6^X8^X11^X12^X14^X16^X17^X20^X21^X22^X28^X31;
+ Y[22]=X2^X3^X5^X7^X8^X11^X13^X15^X18^X19^X21^X22^X23^X28^X31;
+ Y[23]=X2^X3^X4^X6^X9^X10^X12^X14^ X18^X19^X20^X22^X23^X29^X30;
+ Y[24]=X0^X1^X5^X7^X9^X10^X13^X15^X16^X17^X24^X25^X27^X29^X30;
+ Y[25]=X0^X1^X4^X6^X8^X11^X12^X14^X16^X17^X24^X25^X26^X28^X31;
+ Y[26]=X2^X3^X5^X7^X8^X11^X13^X15^X18^X19^X25^X26^X27^X28^ X31;
+ Y[27]=X2^X3^X4^X6^X9^X10^X12^X14^X18^X19^X24^X26^X27^X29^X30;
+ Y[28]=X0^X2^X6^X7^X14^X15^X16^X18^X21^X22^X25^X26^X28^X30^X31;
+ Y[29]=X2^X3^X6^X7^X14^X15^X17^X19^X20^X23^X24^X27^X29^X30^X31;
+ Y[30]=X1^X2^X4^X5^X12^X13^X16^X18^X20^X23^X24^X27^X28^X29^X30;
+ Y[31]=X2^X3^X4^X5^X12^X13^X17^X19^X21^X22^X25^X26^X28^X29^X31;
+
+
}
}