#include #include #include #include #define CR 0x0d //carriage return #define ESC 0x1b //Escape key #define TAB 0x09 #define LF 0x0a //Line feed #define BACKSPACE 0x08 #define NULL 0 //Empty character #define TRUE 1 #define FALSE 0 #define LENGTH 128 //size of the string void rot13(char *string); void input(char *string, int length); void main() { char phrase[LENGTH]; char scrambled[LENGTH]; puts("Type a phrase to be scrambled:"); input(phrase,LENGTH); /* copy the phrase before scrambling */ strcpy(scrambled,phrase); rot13(scrambled); //rot13 the phrase printf("The scrambled phrase is:\n"); puts(scrambled); } void rot13(char *string) { int count = 0; char c = '!'; //initialize c while(c) { c = string[count]; if(isalpha(c)) { if(toupper(c)>='A' && toupper(c)<='M') c+=13; else c-=13; } string[count] = c; count++; } } void input(char *string, int length) { int done = FALSE; int index = 0; char ch; string[0] = NULL; // init the buffer do { ch = getch(); /* Check to see if the buffer is full */ if (index == length) { switch(ch) { case CR: break; default: ch = NULL; break; } } /* process the keyboard input */ switch(ch) { case CR: //Enter key putchar(ch); putchar(LF); string[index] = NULL; done = TRUE; break; case BACKSPACE: if(index==0) { break; } else { putchar(ch); putchar(' '); putchar(ch); index--; break; } case NULL: break; default: //display & sto putchar(ch); string[index] = ch; index++; break; } } while(!done); }