/********************************************************************* * This demo program encodes a text file by the letter * * transposing method * * ------------------------------------------------------------------ * * SAMPLE RUN: * * File test.cpp contains: * * * * #include * * #include * * * * void main() { * * * * double ni, nr; //indices of refraction (dimensionless) * * double incident,refracted; //angles from perpendicular (deg) * * double DegToRad; //required for trig functions * * * * const double pi = 3.1415926537; * * * * DegToRad = pi/180.0; * * * * printf("\n Give indices for incident and refracting medium: "); * * scanf("%lf %lf", &ni, &nr); * * * * printf("\n What is the angle of incidence? "); * * scanf("%lf", &incident); * * * * // Convert refracted angle to degrees before displaying its value * * * * refracted = asin(ni/nr*sin(incident*DegToRad)); * * * * printf("\n Refracted angle = %f\n\n", refracted/DegToRad); * * * * } * * * * TRANSPOSITION CIPHER * * Give name of input text file: test.cpp * * Give name of output text file: test.txt * * Give flag (e) to encode (d) decode: e * * Give transposition distance: 12 * * * * File test.txt now contains: * * * * dlonh# * * >i.ci#tne. #include #define SIZE 4096 void code(char *input, char *output, int dist) { char done, temp; int t; char s[SIZE]; FILE *fp1, *fp2; if ((fp1=fopen(input,"r"))==0) { printf("\n cannot open input file %s\n", input); return; } if ((fp2=fopen(output,"w"))==0) { printf("\n cannot open output file %s\n", output); return; } done=0; do { for (t=0; t