Saving rotated jokes unrotated

John Purbrick jpexg at mit-hermes.ARPA
Fri May 24 02:49:08 AEST 1985


> Voila! rotated joke saved in readable form.
> Maybe someone knows a better way. I'm listening...

Maybe not better, but here's a different method. Rot-13 is simply a procedure
of swapping every letter with the one 13 places forward (or back) in the
alphabet (ie a<-->n, b<-->o, c<-->p etc) so a simple program will do it. I
wrote one (with considerable ignorance, but I've never got around to updating
it) called rotify.c which takes the contents of a file and replaces it with 
the rotified version, up to 10000 chars. With this you can save a rot-13 joke 
or make up your own with a question and an answer which is readable by hitting
D. (Obviously, to do this you only rotify the answer.) 

John Purbrick					jpexg at mit-hermes.ARPA
{...decvax!genrad!  ...allegra!mit-vax!}  mit-eddie!mit-hermes!jpexg


#define MAXBYTES 10000
main(){
	int fnum, numbytes, clox;
	char inbuf[MAXBYTES], fname[20];

	printf("What file to rotify? ");
	scanf("%s", fname);			/* Get the file name */

	fnum = open(fname, 522, 0);		/* Open for reading */
	numbytes = read(fnum, inbuf, MAXBYTES);	/* Transfer to buffer */
	close(fnum);
	fnum = open(fname, 1025, 0);		/* Reopen for writing */

	for (clox = 0; clox < numbytes; clox++) 	/* Rotify!! */
	{	if ((inbuf[clox] > ('a'-1)) && (inbuf[clox] < 'n'))
			inbuf[clox] += 13;
		else if ((inbuf[clox] > 'm') && (inbuf[clox] < ('z'+1)))
			inbuf[clox] -= 13;
		else if ((inbuf[clox] > ('A'-1)) && (inbuf[clox] < 'N'))
			inbuf[clox] += 13;
		else if ((inbuf[clox] > 'M') && (inbuf[clox] < ('Z'+1)))
			inbuf[clox] -= 13;
		else continue;			/* Ignore nonalphabetics */
	}
	write(fnum, inbuf, numbytes);		/* Write the file again */
	close(fnum);				/* And close it */
}



More information about the Comp.unix mailing list