Hello, I'm writing a simple shift cipher which reads from plain.txt, encrypts, and writes to cipher.txt. It works, but only for small plain text lines of a couple of words or so. If the plain text lines are long, then the program does not respond (freezes). Any help would be appreciated. Thanks.
#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char *argv[]){
string line = "";
int lineLength = 0;
int shiftValue = 0;
int asciiValue[lineLength];
char cipherLine[lineLength];
ifstream plainText ("plain.txt");
ofstream cipherText ("cipher.txt");
cout << "Please enter a shift value: ";
cin >> shiftValue;
while (!plainText.eof()){
getline (plainText, line);
lineLength = line.length() - 1;
for (int i=0; i<=lineLength; i++){
asciiValue[i] = (int)line[i];
asciiValue[i] += shiftValue;
cipherLine[i] = (char)asciiValue[i];
cipherText << cipherLine[i];
}
cipherText << endl << endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}