//=========================================================================== // Caesar Cipher with step of 13. (ROT-13 encoding). //=========================================================================== // // Informatics 2C Computer Systems // Coursework 1 // // Paul Jackson // 10 Oct 2012 // Template for MIPS code //--------------------------------------------------------------------------- // C definitions for SPIM system calls //--------------------------------------------------------------------------- #include int read_char() { return getchar(); } int read_int() { int i; scanf("%i", &i); return i; } void read_string(char* s, int size) { fgets(s, size, stdin); } void print_char(int c) { putchar(c); } void print_int(int i) { printf("%i", i); } void print_string(char* s) { printf("%s", s); } //--------------------------------------------------------------------------- // Global variables //--------------------------------------------------------------------------- #define BUF_SIZE 40 char buf[BUF_SIZE]; //--------------------------------------------------------------------------- // MAIN function //--------------------------------------------------------------------------- int main (void) { print_string(" input: "); // Read input string into buf. // String stored in buf is always NUL ('\0') terminated. read_string(buf, BUF_SIZE); char* buf_p = buf; while (1) { int c = *buf_p; if (c == '\0') break; if ('a' <= c && c <= 'z') { c = c + 13; if (c > 'z') c = c - 26; } *buf_p = c; buf_p++; } print_string("\noutput: "); print_string(buf); print_string("\n"); return 0; } //--------------------------------------------------------------------------- // End of file //---------------------------------------------------------------------------