#include #include #include #include void main() { FILE *input_file, *output_file, *catalyst_file; char input_name[66], output_name[66], catalyst_name[66]; char key[66],word[66],key2[66]; int c,d,length,keylength,loophelp,step,mode; /*length-of file*/ int ch, row, col, offrow, offcol, limitrow, datasize, spacecount; int count; ch = 0; row = 0; col=0; offrow=0; offcol=0; limitrow=0; /* init#1 here */ datasize=0; spacecount=0; count=0; testts:row=cursrow();limitrow = row;/*printf("\nStarted at row %d",row);*/ col=0; /* clrscrn();printf("\nts aaa 1 bbb 0 ccc \n\n\n");*/ while(row >= 0){ offrow = row; offcol = col; poscurs(offrow,offcol);ch = readch(); if((ch == 84)||(ch == 116)){ offcol =offcol + 1;if (offcol > 79){ offcol = 0; offrow = row +1; } poscurs(offrow , offcol);ch = readch(); if((ch == 79)||(ch == 111)){ offcol = offcol + 1;if (offcol > 79){ offcol = 0; offrow = row +1; } poscurs(offrow,offcol);ch = readch(); if((ch == 80)||(ch == 112)){ offcol =offcol + 1;if (offcol > 79){ offcol = 0; offrow = row +1; } poscurs(offrow , offcol);ch = readch(); if((ch == 83)||(ch == 115)){ offcol = offcol + 1;if (offcol > 79){ offcol = 0; offrow = row +1; } poscurs(offrow , offcol);ch = readch(); if(ch == 32){ goto cmdfound;} if(ch == 46){ goto baddata;} /* period after ts */ } } } } /* poscurs(row+2,col);writech(43); */ col=col+1;if(col >79) {col = 0; row = row -1;} } poscurs(24,0);exit(0); /*file renamed */ cmdfound:/*-----printf("\n\n\n\n Ts: was at row%d",row); printf(" last char %c",ch); printf(" row %d, col %d", row, col); printf(" offrow %d, offcol %d", offrow, offcol);----*/ getdata: row=offrow; col=offcol+1; poscurs(row,col);ch=readch(); if (ch == 32) { printf("IN code#1");goto baddata; } /*two spaces in a row*/ datasize=0; inputname: poscurs(row,col);ch=readch();input_name[datasize]= ch; datasize=datasize+1; if (datasize > 64) { printf("IN code #2"); goto baddata; } col=col+1; if (col>79) {col=0;row=row+1; } if (row>limitrow) { printf("IN code #3");goto baddata; } poscurs(row,col);ch=readch();if (ch != 32) {goto inputname;/*no space yet*/ } col=col+1; if (col>79) {col=0;row=row+1; } if (row>limitrow) { printf("IN code #4");goto baddata; } poscurs(row,col);ch=readch();if (ch==32){printf(" row %d, col %d",row,col); printf("IN #5");goto baddata; } /*two spaces*/ /*--------------------------------------------------------*/ datasize=0; eord: poscurs(row,col);ch=readch();mode = ch; datasize=datasize+1;if (datasize > 1){printf("ED code#2");goto baddata; } col=col+1; if (col>79) {col=0;row=row+1; } if (row>limitrow) { printf("ED code#3");goto baddata; } poscurs(row,col);ch=readch();if (ch != 32) {goto eord;/*no space yet*/ } col=col+1; if (col>79) {col=0;row=row+1; } if (row>limitrow) { printf("ED code#4");goto baddata; } poscurs(row,col);ch=readch();if (ch==32){printf(" row %d, col %d",row,col); printf("ED code#5");goto baddata; } /*two spaces*/ if((mode != 49)&&(mode !=50)){mode=0;goto baddata;} /*--------------------------------------------------------*/ datasize=0; outputfile: poscurs(row,col);ch=readch();output_name[datasize] = ch; datasize=datasize+1;if (datasize > 64){printf("OUT code#2");goto baddata; } col=col+1; if (col>79) {col=0;row=row+1; } if (row>limitrow) { printf("OUT code#3");goto baddata; } poscurs(row,col);ch=readch();if (ch != 32) {goto outputfile;/*no space yet*/ } col=col+1; if (col>79) {col=0;row=row+1; } if (row>limitrow) { printf("OUT code#4");goto baddata; } poscurs(row,col);ch=readch();if (ch==32){printf(" row %d, col %d",row,col); printf("OUT code#5");goto baddata; } /*two spaces*/ /*--------------------------------------------------------*/ datasize=0; catalyst: poscurs(row,col);ch=readch();catalyst_name[datasize] = ch; datasize=datasize+1;if (datasize > 64){printf("CAT code#2");goto baddata; } col=col+1; if (col>79) {col=0;row=row+1; } if (row>limitrow) { printf("CAT code#3");goto baddata; } poscurs(row,col);ch=readch();if (ch != 32) {goto catalyst;/*no space yet*/ } col=col+1; if (col>79) {col=0;row=row+1; } if (row>limitrow) { printf("CAT code#4");goto baddata; } poscurs(row,col);ch=readch();if (ch==32){printf(" row %d, col %d",row,col); printf("OUT code#5");goto baddata; } /*two spaces*/ /*--------------------------------------------------------*/ datasize=0; keysee: poscurs(row,col);ch=readch();key[datasize] = ch; datasize=datasize+1;if (datasize > 64){printf("KEY code#2");goto baddata; } col=col+1; if (col>79) {col=0;row=row+1; } if (row>limitrow) { printf("KEY code#3");goto baddata; } poscurs(row,col);ch=readch();if (ch != 32) {goto keysee;/*no space yet*/ } /*---- col=col+1; if (col>79) {col=0;row=row+1; } if (row>limitrow) { printf("KEY code#4");goto baddata; } poscurs(row,col);ch=readch();if (ch==32){printf(" row %d, col %d",row,col); printf("KEY code#5");goto baddata; } *two spaces* --------*/ /*--------------------------------------------------------*/ poscurs (24,0); /*get rid of this later!*/ /*printf("\n\n\n datasize %d",datasize); */ /*printf(" baddata row%d, col%d, ch%d",row,col,ch);printf("\n");*/ /*------- for debuging printf("\n\nInput file="); printf("%s",input_name); printf("\nEncrypt-1,Decode-2:="); printf("%c",mode); printf("\nOutput file= "); printf("%s",output_name); printf("\nCatalyst file="); printf("%s",catalyst_name); printf("\nKey="); printf("%s",key); printf("\n"); ----------*/ goto dataready; exit(0); /*later exit to regular ts */ baddata: /* start at begining for beginers*/ printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); printf("TOPSECRET! by SIVA R.KRISHNA (C)'95-97 V2.0"); printf("\nShareware registration,$5 to PSC BOX 3013 "); printf("DYESS AFB,TX.79607"); printf("\n\nSecurity hints:"); printf("\nEncrypt compressed files to minimize repeating data.Since the receiver must"); printf("\nhave the Catalyst/s,you may want to start with something popular.Consider"); printf("\nencrypting more than once.If sensitive data was written to a disk,format"); printf("\nthe disk and overwrite the whole disk before disposal.Ensure personnel have"); printf("\nproper security clearance.Have building and personnel checked for"); printf("\nsurveillance equipment."); printf("\n\nDisclaimer:This program is sold AS IS,no one or "); printf("vendor shall be liable for special,incidental,consequential"); printf(",direct,indirect or other similar damages from the use "); printf("or missuse of this program.Other liabilities for damages"); printf(" shall in no event exceed the purchase price."); printf(" \n"); printf(" \n"); printf(" \n"); anotherfile: /*----------init#2 here-----------*/ c=0;d=0;length=0;keylength=0;loophelp=0;mode=0; printf("\nName of input file : "); scanf("%s",&input_name); againmode:printf("\n1=Encrypt 2=Decode\n"); scanf("%s",&mode);/* printf("\nMode=%d",mode);*/ if((mode!=49)&&(mode!=50)) {goto againmode;} printf("\nName of output file : "); scanf("%s",&output_name); printf("\nName of Catalyst file, 0=NONE : "); scanf("%s",catalyst_name); againkey: printf("\nEnter KEY"); printf("\n01234567891123456789212345678931234567894123456789"); printf("51234567896123\n"); scanf("%s",&key); if(strlen(key)>64){printf("\n key=%s\n length=%d",key,strlen(key)); goto againkey;} /* generate firstime k2 only */ keylength=strlen(key); printf("\nThelength of key \n%s is %d\n",key,keylength); dataready: keylength=strlen(key); /*again for fast-dataready:see 3 lines up*/ loophelp=0; while(loophelp < keylength+1) {key2[loophelp]=key[loophelp+1] ; loophelp=loophelp+1; } loophelp=loophelp+1;key2[loophelp]=key[loophelp]; /* printf("\n0-%c,1-%c,2-%c,3-%c",key[0],key[1],key[2],key[3]); */ /* printf("\n0-%d,1-%d,2-%d,3-%d",key[0],key[1],key[2],key[3]); */ /* printf("\n The word is %s",word); */ input_file = fopen(input_name,"rb"); if (input_file == NULL) { puts("***can't open input file***"); exit(0); } output_file = fopen( output_name, "wb"); if (output_file == NULL) { puts("***can't open output file***"); exit(0); } if (catalyst_name[0] !=48) { catalyst_file = fopen( catalyst_name, "rb"); if (catalyst_file == NULL) { puts("***can't open Catalyst file***"); exit(0); } } c=0;d=0;length=0;loophelp=0; while((c = getc(input_file)) != EOF){length=length+1;/*start i/o file*/ /* printf("-cbefore%d,%c-",c,c);*/ if(mode == 49){word[loophelp]=c; /*d for troubleshooting*/ } c=(key[loophelp]^c); c=(c^loophelp)^keylength; /*hide key from simple code*/ c=(key2[loophelp]^c); if (catalyst_name[0] !=48) { d=getc(catalyst_file); /* printf(" %d",d); */ if (d== EOF) { fclose(catalyst_file); catalyst_file = fopen (catalyst_name, "rb"); d=getc(catalyst_file); /*printf("%c",d);*/ } c=c^d; } /* if(length == 1) { c=d;printf("*c=%d,%c*",c,c); } */ /* if(c == 26) { c=d; printf("*c=%d,%c*",c,c); } */ /* if(c == 92) { c=d; printf("*c=%d,%c*",c,c); } */ skipcode: if(mode == 50){word[loophelp]=c; } putc(c,output_file); loophelp=loophelp+1; if(loophelp == keylength) { loophelp=0;strcpy(key2,word); /*init loophelp*/ } } /*stop while;i/o file*/ fclose(output_file); fclose(input_file); fclose(catalyst_file); /* printf("\nFile length was=%d",length); */ /* printf(" c=%d %c %s ",c,c,c);*/ if(datasize>0){exit(0);} /* quit fast for the pros */ againmode2:printf("\n1=Another File 2=QUIT\n"); scanf("%s",&mode); /* printf("\nMode=%d",mode); */ if((mode!=49)&&(mode!=50)) {goto againmode2;} if (mode == 49){goto anotherfile; } }