1 //g++ cipher_h265.cpp -o cipher_h265 -O3
3 //example vid.h265 seed
4 //cipher_h265 vid1.h265 38762
15 typedef unsigned char uchar;
17 uchar modulo(int x,int N){ return (x % N + N) %N; }
20 void cipher_frame(uchar *buf, int start_sl, int end_sl, int enc) {
21 for(int i=0;i<(end_sl-start_sl)/2;i++) {
22 int p=lrand48()%(end_sl-start_sl)+start_sl;
23 if(p<start_sl || p>=end_sl)
25 while(buf[p-1]==255 || buf[p]==255 ){
26 p=lrand48()%(end_sl-start_sl)+start_sl;
27 if(p<start_sl || p>=end_sl)
30 uchar v=lrand48()%255;
32 buf[p]=modulo((int)buf[p]+(int)v,255);
35 buf[p]=modulo((int)buf[p]-(int)v,255);
43 void fxor(uchar *buf,int sz, int seed,int enc) {
51 for(int i=0;i<sz-6;i++) {
52 if(((uint)buf[i])==0x00 && ((uint)buf[i+1])==0x00 && ((uint)buf[i+2])==0x01) {
54 if (( ((uint)buf[i+3])==0x26 || ((uint)buf[i+3])==0x2a ) && ((uint)buf[i+4])==0x01 ) {
55 cout<<"IDR or I slice "<<i<<"\t";
58 for(int k=i+1;k<sz-4 && !stop;k++) {
59 if(((uint)buf[k])==0x00 && ((uint)buf[k+1])==0x00 && ((uint)buf[k+2])==0x00 && ((uint)buf[k+3])==0x01 ) {
60 cout<<"end "<<k<<endl;
67 cipher_frame(buf, start_sl, end_sl, enc);
79 if(((uint)buf[i])==0x00 && ((uint)buf[i+1])==0x00 && ((uint)buf[i+2])==0x00 && ((uint)buf[i+3])==0x01) {
81 if ( ( ((uint)buf[i+4])==0x02 || ((uint)buf[i+4])==0x10 || ((uint)buf[i+4])==0x12 ) && ((uint)buf[i+5])==0x01 ) {
82 cout<<"B or P slice "<<i<<"\t";
85 for(int k=i+1;k<sz-4 && !stop;k++) {
86 if(((uint)buf[k])==0x00 && ((uint)buf[k+1])==0x00 && ((uint)buf[k+2])==0x00 && ((uint)buf[k+3])==0x01 ) {
87 cout<<"end "<<k<<endl;
94 cipher_frame(buf, start_sl, end_sl, enc);
106 // cipher_frame(buf, 1000, sz, enc);
112 int main(int argc, char **argv){
113 cout<<argv[1]<< endl;
116 fp = fopen(argv[1], "r");
117 fseek(fp, 0L, SEEK_END);
119 fseek(fp, 0, SEEK_SET);
121 uchar *buf=(uchar*)malloc(sz);
122 uchar *buf2=(uchar*)malloc(sz);
123 fread(buf, sz, 1, fp);
127 int seed=atoi(argv[2]);
134 fp = fopen("lena2.h265", "w");
135 fwrite (buf , 1, sz, fp);
138 for(int i=0;i<sz;i++) {
145 fxor(buf2,sz,seed,0);
147 fp = fopen("lena3.h265", "w");
148 fwrite (buf2 , 1, sz, fp);