home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
430.lha
/
Arn_v0.67
/
rot.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-11-09
|
2KB
|
97 lines
/***************************************************************************
* rot.c written 1990 by R.Bless *
* rot - a variable rot program for amiga computers *
* usage: rot [number] *
* Description: *
* rot reads from stdin and puts the en-/decrypted text to stdout. *
* rot rotates each letter from ('A'..'Z' and 'a'..'z') with number. *
* Default number is 13. If you've a text with rot 8 encrypted, you must *
* decrypt it with rot 18 (8+18=26, you see?). *
* *
* This program is FREEWARE. You're allowed to eat it! *
* Version 0.02 - 12.9.1990 *
* A Byteable Software Product *
***************************************************************************/
#include <stdio.h>
#undef BUFSIZ
#define BUFSIZ 4096
#define STRINGSIZE 1024L
#ifdef AMIGA
char *AllocMem();
#endif
#ifdef UNIX
void *malloc();
void free();
#endif
char *fgets();
long atol();
char *rot(s,n)
register char *s;
int n;
{
char *t=s;
while(*s!='\0')
{
if (*s>='A' && *s<='Z')
*s='\x41'+(*s-'\x41'+n)%26;
else
if (*s>='a' && *s<='z')
*s='\x61'+(*s-'\x61'+n)%26;
s++;
}
return t;
}
int
main(argc,argv)
int argc;
char *argv[];
{
char *tmp;
int number=13;
if (argc>2)
{
fprintf(stderr,"usage: rot [number]\n");
return 1;
}
else
{
if (argc==2)
number= (int) atol(argv[1]);
else
number=13;
#ifdef AMIGA
if (!(tmp= AllocMem(STRINGSIZE, NULL)))
#endif
#ifdef UNIX
if (!(tmp= malloc(STRINGSIZE)))
#endif
{
fprintf(stderr,"rot: no memory available!\n");
return 2;
}
else
{
while (gets(tmp, STRINGSIZE))
{
fputs(rot(tmp,number),stdout);fputc('\n',stdout);
}
fflush(stdout);
}
#ifdef AMIGA
if (tmp) FreeMem(tmp, STRINGSIZE);
#endif
#ifdef UNIX
if (tmp) free(tmp);
#endif
}
return 0;
}