diff options
author | Paul Janzen <pjanzen@cvs.openbsd.org> | 1998-08-19 07:53:55 +0000 |
---|---|---|
committer | Paul Janzen <pjanzen@cvs.openbsd.org> | 1998-08-19 07:53:55 +0000 |
commit | f39ea58f043a480bf6c5f77025131d419762bd0d (patch) | |
tree | caa658e1a792c6fd2c5030a8f2df58f191141fe6 /games/caesar | |
parent | f058c203ecb54996b64df65517d94b4bace16eac (diff) |
minor tidying, and a fix to rot13's command line behaviour
Diffstat (limited to 'games/caesar')
-rw-r--r-- | games/caesar/caesar.6 | 6 | ||||
-rw-r--r-- | games/caesar/caesar.c | 36 |
2 files changed, 22 insertions, 20 deletions
diff --git a/games/caesar/caesar.6 b/games/caesar/caesar.6 index b7fcf720b8b..bf7b64b11ab 100644 --- a/games/caesar/caesar.6 +++ b/games/caesar/caesar.6 @@ -1,4 +1,4 @@ -.\" $OpenBSD: caesar.6,v 1.2 1998/03/12 09:09:16 pjanzen Exp $ +.\" $OpenBSD: caesar.6,v 1.3 1998/08/19 07:53:53 pjanzen Exp $ .\" .\" Copyright (c) 1989, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -40,11 +40,11 @@ .Nm caesar .Nd decrypt caesar cyphers .Sh SYNOPSIS -.Nm caesar +.Nm .Op Ar rotation .Sh DESCRIPTION The -.Nm caesar +.Nm utility attempts to decrypt caesar cyphers using English letter frequency statistics. .Nm Caesar diff --git a/games/caesar/caesar.c b/games/caesar/caesar.c index 0008ccac3f2..9cd63673cb9 100644 --- a/games/caesar/caesar.c +++ b/games/caesar/caesar.c @@ -1,4 +1,4 @@ -/* $OpenBSD: caesar.c,v 1.6 1998/03/12 09:06:43 pjanzen Exp $ */ +/* $OpenBSD: caesar.c,v 1.7 1998/08/19 07:53:54 pjanzen Exp $ */ /* * Copyright (c) 1989, 1993 @@ -51,18 +51,18 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)caesar.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$OpenBSD: caesar.c,v 1.6 1998/03/12 09:06:43 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: caesar.c,v 1.7 1998/08/19 07:53:54 pjanzen Exp $"; #endif #endif /* not lint */ -#include <stdlib.h> -#include <string.h> -#include <math.h> -#include <stdio.h> #include <ctype.h> -#include <unistd.h> #include <err.h> #include <errno.h> +#include <math.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> #define LINELENGTH 2048 #define ROTATE(ch, perm) \ @@ -80,7 +80,7 @@ double stdf[26] = { }; void printit __P((int)); -void usage __P(()); +void usage __P((void)); int @@ -88,7 +88,7 @@ main(argc, argv) int argc; char **argv; { - register int ch, dot, i, nread, winnerdot = 0; + register int ch, dot, i, nread, winnerdot; register char *inbuf, *p, **av; int obs[26], try, winner; @@ -96,13 +96,6 @@ main(argc, argv) setegid(getgid()); setgid(getgid()); - if (argc > 1) { - if ((i = atoi(argv[1]))) - printit(i); - else - usage(); - } - /* check to see if we were called as rot13 */ av = argv; p = strrchr(*av, '/'); @@ -111,6 +104,13 @@ main(argc, argv) if (strcmp(p,"rot13") == 0) printit(13); + if (argc > 1) { + if ((i = atoi(argv[1]))) + printit(i); + else + usage(); + } + if (!(inbuf = malloc(LINELENGTH))) errx(1, "out of memory."); @@ -134,6 +134,7 @@ main(argc, argv) * now "dot" the freqs with the observed letter freqs * and keep track of best fit */ + winnerdot = 0; for (try = winner = 0; try < 26; ++try) { /* += 13) { */ dot = 0; for (i = 0; i < 26; i++) @@ -155,7 +156,8 @@ main(argc, argv) } void -printit(int rot) +printit(rot) + int rot; { register int ch; |