[net.sources] Rot N program source

spaf@gatech.UUCP (01/02/84)

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

keith@rlgvax.UUCP (keith) (01/03/84)

If you don't want to bother with compiling source code:
	Bell NIX
		exec tr "[a-z][A-Z]" "[n-z][a-m][N-Z][A-M]"

	Berkeley NIX
		exec tr a-zA-Z n-za-mN-ZA-M