* program to to decrypt caesar(tm) cypher
* (caesar is a trademark of the roman empire)
* cc decrypt.c -lm -o decrypt.c
* where n is an optional forced rotation.
* authors: Stan King, John Eldridge, based on algorithm suggested by
static char *SccsId
= "@(#)caesar.c 1.7 4/16/85";
/* letter frequencies (taken from some unix(tm) documentation) */
/* (unix is a trademark of Bell Laboratories) */
static double stdf
[ 26 ] =
7.97, 1.35, 3.61, 4.78, 12.37, 2.01, 1.46, 4.49,
6.39, 0.04, 0.42, 3.81, 2.69, 5.92, 6.96, 2.91,
0.08, 6.63, 8.77, 9.68, 2.62, 0.81, 1.88, 0.23,
double dot
, winnerdot
; /* .. */
sscanf( argv
[1], "%d", &forced
);
inbuf
= calloc( BUFSIZ
, 1 );
/* adjust frequency table to weight low probs REAL low */
stdf
[i
] = log(stdf
[i
]) + log(26.0/100.0);
/* Decode each line separately */
for (i
=0; i
<=25; obs
[i
++]=0)
/* get a sample of the text */
for( i
= 0; i
< BUFSIZ
; i
++ ) {
if( (c
= getchar()) == EOF
) {
/* now "dot" the freqs with the observed letter freqs */
/* and keep track of best fit */
for (try = 0; try<26; try+=13) {
dot
+= obs
[i
] * stdf
[ (i
+try) % 26 ];
/* initialize winning score */
/* print out sample buffer */
for( i
= 0; i
< bufsize
; i
++ )
putchar( rotate( inbuf
[i
], winner
) );
return 'A' + (c
- 'A' + perm
) % 26 ;
return 'a' + (c
-'a'+perm
) % 26 ;