Rot N program source
spaf at gatech.UUCP
spaf at gatech.UUCP
Mon Jan 2 11:53:33 AEST 1984
Since I keep seeing requests from people for the source to a program
to "rot 13" something, let me repost one such program which found its
way onto the net a few months ago. I'll post this with an expiration
date far into the future for, ahem, future reference.
/*
* do a rot
*
* rot [shift factor] [files]
* shift factor defaults to 13
* files " " stdin
*/
#include <stdio.h>
#include <ctype.h>
#define ROT 13
main(argc, argv)
int argc;
char *argv[];
{
int rot;
if ((argc < 2) || ((rot = atoi(argv[1])) == 0))
rot = ROT;
else {
argc--;
++argv;
}
while (*++argv) {
if (freopen(*argv, "r", stdin) == NULL)
perror(*argv);
else
rotate(rot);
}
if (argc == 1)
rotate(rot);
exit(0);
}
rotate(rot)
int rot;
{
register char c;
while ((c = getchar()) != EOF) {
if (isupper(c))
c = 'A' + (c - 'A' + rot) % 26;
else if (islower(c))
c = 'a' + (c - 'a' + rot) % 26;
putchar(c);
}
}
--
Off the Wall of Gene Spafford
School of ICS, Georgia Tech, Atlanta GA 30332
CSNet: Spaf @ GATech ARPA: Spaf.GATech @ CSNet-Relay
uucp: ...!{akgua,allegra,rlgvax,sb1,unmvax,ulysses,ut-sally}!gatech!spaf
More information about the Comp.sources.unix
mailing list