Don't like ads? PRO users don't see any ads ;-)
Guest

rot13

By: mulitia on May 12th, 2012  |  syntax: C  |  size: 0.62 KB  |  hits: 37  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /* rot13.c -- my attempt at making ROT13/Caeser Cipher */
  2.  
  3. #include <stdio.h>
  4. #include <ctype.h>
  5.  
  6. #define ROT 13
  7.  
  8. int main(void)
  9. {
  10.         int ch;
  11.         int rot;
  12.        
  13.         printf("Enter a line to cipher: \n");
  14.         while ((ch = getchar()) != '\n')
  15.         {
  16.                 if (ch >='A' && ch <= 'Z')
  17.                 {
  18.                         if ((rot = ch + ROT) <= 'Z')
  19.                                 putchar(rot);
  20.                         else
  21.                         {
  22.                                 rot = ch - ROT;
  23.                                 putchar(rot);
  24.                         }
  25.                 }
  26.                 else if (ch >='a' && ch <='z')
  27.                 {
  28.                         if((rot = ch + ROT) <='z')
  29.                                 putchar(toupper(rot));
  30.                         else
  31.                         {
  32.                                 rot = ch - ROT;
  33.                                 putchar(toupper(rot));
  34.                         }
  35.                 }
  36.                 else
  37.                         putchar(ch);
  38.         }
  39.        
  40.         putchar('\n');
  41.        
  42.         return 0;
  43. }