
rot13
By:
mulitia on
May 12th, 2012 | syntax:
C | size: 0.62 KB | hits: 37 | expires: Never
/* rot13.c -- my attempt at making ROT13/Caeser Cipher */
#include <stdio.h>
#include <ctype.h>
#define ROT 13
int main(void)
{
int ch;
int rot;
printf("Enter a line to cipher: \n");
while ((ch = getchar()) != '\n')
{
if (ch >='A' && ch <= 'Z')
{
if ((rot = ch + ROT) <= 'Z')
putchar(rot);
else
{
rot = ch - ROT;
putchar(rot);
}
}
else if (ch >='a' && ch <='z')
{
if((rot = ch + ROT) <='z')
putchar(toupper(rot));
else
{
rot = ch - ROT;
putchar(toupper(rot));
}
}
else
putchar(ch);
}
putchar('\n');
return 0;
}