'a' to 'z' aren't guaranteed to be contiguous. Which means that your encryption basically won't work if the user is using a different encoding scheme (rare, I'll grant you, but not impossible).
Here's a simple encryption program I whipped up just for the fun of it. Use isalpha() instead of isprint() for less radical encryption.
Code:
#include <stdio.h>
#include <limits.h>
#include <ctype.h>
int is_encryptable(int c);
void crypt_line(const char *line, const char *map, int map_entries);
int main() {
char map[UCHAR_MAX];
int x, y, map_entries = 0;
char line[BUFSIZ];
for(x = 0; x < UCHAR_MAX; x ++) {
if(is_encryptable(x)) {
map[map_entries ++] = x;
}
}
for(;;) {
printf("crypt> ");
if(!fgets(line, sizeof line, stdin)) break;
printf(" ==> ");
crypt_line(line, map, map_entries);
}
putchar('\n');
return 0;
}
int is_encryptable(int c) {
return isprint(c) && c != '\n';
}
void crypt_line(const char *line, const char *map, int map_entries) {
int x, y;
for(x = 0; line[x]; x ++) {
if(is_encryptable(line[x])) {
/* linear search, ugh */
for(y = 0; map[y]; y ++) {
if(line[x] == map[y]) {
putchar(map[map_entries - y - 1]);
}
}
}
else {
putchar(line[x]);
}
}
}
It simply collects all printable characters into one map. Every time a character is encrypted, it "reverses" the position in the map table and uses that instead. (By reverse I mean length - x - 1.)
Code:
$ ./encrypt
crypt> Greetings.
==> W,99*507+p
crypt> W,99*507+p
==> Greetings.
crypt>
$
Presumably you're aware that this sort of encryption isn't really that secure.
Anyway, for more interesting encyption, you can use the bitwise NOT operator (~). But that's even easier to guess and the result frequently isn't printable.