// Arup Guha
// 10/5/2011
// Written in COP 3223H - Encrypts using the flip cipher.

#include <stdio.h>

int main() {

    // Get the input and output files, and open them.
    char filename[20], output[20];
    printf("What file do you want to read from?\n");
    scanf("%s", filename);
    printf("Where do you want the output?\n");
    scanf("%s", output);

    FILE* ifp = fopen(filename, "r");
    FILE* ofp = fopen(output, "w");

    char c;

    // Go through each character. When the read fails, the
    // loop is broken immediately.
    while ((c = fgetc(ifp)) != EOF) {

        // Only edit alphabetic letters.
        if (isalpha(c)) {

            // Work out both cases (lower/upper)
            if (islower(c)) {
                char cipher = (25 - (c - 'a')) + 'a';
                fprintf(ofp, "%c", cipher);
            }
            else {
                char cipher = (25 - (c - 'A')) + 'A';
                fprintf(ofp, "%c", cipher);
            }
        }
        else
            fprintf(ofp, "%c", c);
    }

    return 0;
}

