#include #include #include #include #include void boolq(int); int ran1(int); int ran(int,int); int *ar,*s,*a; void main() { //clrscr(); int k,**G1,**G0,t,*t1,*t2,*psh,i,j,pn,*sec,lsec; char **flnm; FILE *fp; printf("\n Enter the length of secret message:"); scanf("%d",&lsec); sec=(int*)malloc((lsec+1) *sizeof(int)); printf("\n Enter the message in the binary form:"); for(i=1;i<=lsec;i++) { scanf("%d",&sec[i]); } printf("\n Enter the no. of participant:"); scanf("%d",&pn); printf("\n Enter the number of qualified set:"); scanf("%d",&k); t1=(int *)malloc((2*pn) *sizeof(int)); t2=(int *)malloc((pn) *sizeof(int)); //t2 will store no. of participants in each qualified set flnm=(char **)malloc((pn) *sizeof(char *)); for(i=0;i<=pn+1;i++) flnm[i]=(char *)malloc((pn) *sizeof(char)); for(i=1;i<=pn;i++) { printf("\n Enter the filename for the %d participant:",i); scanf("%s",&flnm[i][0]); } int tot=0;// tot is the sum of all participant in each qualified set for(i=1;i<=k;i++) { printf("\n Enter the no of participant int the qualified set %d:",i); scanf("%d",&t2[i]); tot+=t2[i]; } printf("\n Enter the participants in the qualified set %d:"); for(i=1;i<=tot;i++) { scanf("%d",&t1[i]); } int tmp=0; for(i=1;i<=k;i++) { tmp+=pow(2,t2[i]-1); //tmp stores the number of coloumns of G0 & G1 in our scheme } //printf("\n(%d)\n",tmp); G0=(int **)malloc((pn+2) *sizeof(int *)); for(i=0;i<=pn+2;i++) G0[i]=(int *)malloc((tmp+2) *sizeof(int)); G1=(int **)malloc((pn+2) *sizeof(int *)); for(i=0;i<=pn+2;i++) G1[i]=(int *)malloc((tmp+2) *sizeof(int)); printf("\n"); for(i=1;i<=pn;i++) { for(j=1;j<=tmp;j++) { G0[i][j]=0; G1[i][j]=0; } } /*for(i=1;i<=pn;i++) { for(j=1;j<=tmp;j++) { printf(" %d",G0[i][j]); } printf("\n"); } */ //calculating G0 & G1 int p=0,n=0,l,o=0,v; for(i=1;i<=k;i++) { l=t2[i]-1; boolq(l); o=0; v=0; for(j=1+n;j<=l+n;j++) { for(t=1+p;t<=pow(2,l)+p;t++) { G0[t1[j]][t]=ar[o]; G1[t1[j]][t]=ar[o]; o++; } } for(t=1+p;t<=pow(2,l)+p;t++) { G0[t1[l+1+n]][t]=s[v]; if(s[v]==1) G1[t1[l+1+n]][t]=0; else G1[t1[l+1+n]][t]=1; v++; } n=n+t2[i]; p=p+pow(2,l); } printf("\nInitial matrix G0 is:\n"); for(i=1;i<=pn;i++) { for(j=1;j<=tmp;j++) { printf(" %d",G0[i][j]); } printf("\n"); } printf("\n Initial matrix G1 is:\n"); for(i=1;i<=pn;i++) { for(j=1;j<=tmp;j++) { printf(" %d",G1[i][j]); } printf("\n"); } int fl,tm[25],ps=1; psh=(int *)malloc((pn*tmp*lsec+1) *sizeof(int)); for(i=1;i<=lsec;i++) { randomize(); if(sec[i]==1) { // randomize(); ran1(tmp); //printf("\n Permuted matrix G1(%d):\n",i); for(int k=1;k<=pn;k++) { for(int j=1;j<=tmp;j++) { tm[j]=G1[k][j]; } for(j=1;j<=tmp;j++) { fl=tm[a[j]]; printf("%d ",fl); psh[ps]=fl; ps++; }//end of j printf("\n"); }//end of k } else { // randomize(); ran1(tmp); //printf("\n Permuted matrix G0(%d):\n",i); for(int k=1;k<=pn;k++) { for(int j=1;j<=tmp;j++) { tm[j]=G0[k][j]; } for(j=1;j<=tmp;j++) { fl=tm[a[j]]; printf("%d ",fl); psh[ps]=fl; ps++; }//end of j printf("\n"); }//end of k } } for(i=1;i<=pn*tmp*lsec;i++) { printf(" %d",psh[i]); } v=1; for(i=1;i<=pn;i++) { fp=fopen(flnm[i],"w"); n=0; for(j=1;j<=lsec;j++) { for(o=v+n;ot && t