/************************************************************************* * Encoding an ASCII text using a random encoding table * * ---------------------------------------------------------------------- * * The text to encode is in file codage.dat. * * The random encoding table is in file code.lst. * * The output encoded text is in file codage.lst. * * * * The text can be decoded by decodage.exe that must have access to * * code.lst and codage.lst files. * * ---------------------------------------------------------------------- * * SAMPLE RUN: * * File codage.dat contains: * * * * Program ASCII; * * Uses WincrtMy; * * * * VAR * * i: word; * * * * BEGIN * * for i:=160 to 255 do * * write(i:4,' ',chr(i)); * * Readkey; * * DoneWinCrt * * END. * * * * The output file code.lst contains: * * * * !h"k#c$2%#&^'v(1):*$+",e-H.L/50}102o3|4j5t6D7R8?9J:G;.Z?O@3AUBiCg * * DbEmFSG(HWIxJfK)L+MNN&OAPBQ]R7S;T>UlVYWVXTY,Zw[!\C]-^n_/`Fayb8c{d9edfz * * g~hQi\jqk[l'm@n4oPprqsr*s #include #include #include #include #include #define MINCAR 33 // ASCII characters from 33 to 126 only #define MAXCAR 126 #define MAXSTR 81 // lines of length 80 char A[MAXCAR+1],Z[MAXCAR+1]; int alea,fait,i,j; char ligne[MAXSTR]; char codee[MAXSTR]; void main(void) { FILE *fp1,*fp2, *fp3; srand((unsigned)time(NULL)); //initialize random generator if((fp1=fopen("codage.dat","r"))==NULL) { printf("\n Impossible to open input text file: codage.dat"); exit(1); } if((fp2=fopen("codage.lst","w"))==NULL) { printf("\n Impossible to open output encoded file: codage.lst"); exit(1); } if((fp3=fopen("code.lst","w"))==NULL) { printf("\n Impossible to open the random table file: code.lst"); exit(1); } for (i=MINCAR; i MAXCAR-MINCAR); Z[MINCAR]=MINCAR+alea; for (i=MINCAR+1; i MAXCAR-MINCAR); Z[i]=MINCAR+alea; fait=1; for (j=MINCAR; j