home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 484b.lha / ARN_v0.68 / Arn068.lzh / rot.c < prev    next >
C/C++ Source or Header  |  1990-10-05  |  2KB  |  97 lines

  1. /***************************************************************************
  2.  * rot.c  written 1990 by R.Bless                                          *
  3.  * rot - a variable rot program for amiga computers                        *
  4.  * usage: rot [number]                                                     *
  5.  * Description:                                                            *
  6.  * rot reads from stdin and puts the en-/decrypted text to stdout.         *
  7.  * rot rotates each letter from ('A'..'Z' and  'a'..'z') with number.      *
  8.  * Default number is 13. If you've a text with rot 8 encrypted, you must   *
  9.  * decrypt it with rot 18 (8+18=26, you see?).                             *
  10.  *                                                                         *
  11.  * This program is FREEWARE. You're allowed to eat it!                     *
  12.  * Version 0.02 - 12.9.1990                                                *
  13.  * A Byteable Software Product                                             *
  14.  ***************************************************************************/
  15.  
  16. #include <stdio.h>
  17. #undef BUFSIZ
  18. #define BUFSIZ 4096
  19. #define STRINGSIZE 1024L
  20.  
  21. #ifdef AMIGA
  22. char *AllocMem();
  23. #endif
  24. #ifdef UNIX
  25. void *malloc();
  26. void free();
  27. #endif
  28. char *fgets();
  29. long atol();
  30.  
  31. char *rot(s,n)
  32. register char *s;
  33. int n;
  34. {
  35.   char *t=s;
  36.  
  37.   while(*s!='\0')
  38.   {
  39.     if (*s>='A' && *s<='Z')
  40.        *s='\x41'+(*s-'\x41'+n)%26;
  41.     else
  42.     if (*s>='a' && *s<='z')
  43.        *s='\x61'+(*s-'\x61'+n)%26;
  44.     s++;
  45.   }
  46.   return t;
  47. }
  48.  
  49.  
  50. int
  51. main(argc,argv)
  52. int argc;
  53. char *argv[];
  54. {
  55.   char *tmp;
  56.   int number=13;
  57.  
  58.   if (argc>2)
  59.   {
  60.     fprintf(stderr,"usage: rot [number]\n");
  61.     return 1;
  62.   }
  63.   else
  64.   {
  65.     if (argc==2)
  66.       number= (int) atol(argv[1]);
  67.     else
  68.       number=13;
  69. #ifdef AMIGA
  70.     if (!(tmp= AllocMem(STRINGSIZE, NULL)))
  71. #endif
  72. #ifdef UNIX
  73.     if (!(tmp= malloc(STRINGSIZE)))
  74. #endif
  75.     {
  76.       fprintf(stderr,"rot: no memory available!\n");
  77.       return 2;
  78.     }
  79.     else
  80.     {
  81.       while (gets(tmp, STRINGSIZE))
  82.       {
  83.         fputs(rot(tmp,number),stdout);fputc('\n',stdout);
  84.       }
  85.       fflush(stdout);
  86.     }
  87. #ifdef AMIGA
  88.     if (tmp) FreeMem(tmp, STRINGSIZE);
  89. #endif
  90. #ifdef UNIX
  91.     if (tmp) free(tmp);
  92. #endif
  93.  
  94.   }
  95.   return 0;
  96. }
  97.