#include <stdio.h>

#define K 3
#define N ('z'-'a'+1)

char cipher(char c);
char decipher(char c);

char to_lower(char c){
    if (c>='A' && c<='Z') c=c-'A'+'a';
    return c;
}

int main(int argc, char **argv){
	int i, r, decrypt=0;
    char c;
    FILE *fin;
    FILE *fout;
    if (argc<3) return -1;
    fin=fopen(argv[1], "r");
    fout=fopen(argv[2], "w");
    if (!fin || !fout) return -1;
    if (argc>3 && strcmp(argv[3],"decipher")==0) decrypt=1; 

    fscanf(fin, "%c", &c);
    while(!feof(fin)){
        c=to_lower(c);
        if (c>='a' && c<='z') 
            if (decrypt) c=decipher(c);
            else c=cipher(c);
        fprintf(fout, "%c", c);
        fscanf(fin, "%c", &c);
    }
    close(fin);
    close(fout);
    return 0;
}

char cipher(char c){
	return (c-'a'+K)%N+'a';
}

char decipher(char c){
	return (c-'a'-K+26)%N+'a';
}
