// scramble.cpp #include #include #include #include "Vigenere.h" using namespace std; int main( int argc, char* argv[] ) { // check number of arguments if ( argc < 3 ) { cerr << "Missing argument." << endl; cerr << "usage: scramble key filename" << endl; return 1; } // open streams ifstream lReader; ofstream lOutput; lReader.open( argv[2] ); if ( lReader.fail() ) { cerr << "Cannot open file \'" << argv[2] << "\'." << endl; return 1; } string lOutName( argv[2] ); lOutName += ".secure.txt"; lOutput.open( lOutName.c_str() ); if ( lOutput.fail() ) { cerr << "Cannot open output file \'" << lOutName.c_str() << "\'." << endl; return 1; } cout << "Scrambling \'" << argv[2] << "\' "; cout.flush(); // encode file Cipher lScambler; // convert key to uppercase lScambler.normalizeKey( argv[1] ); int lKeyIndex = 0; string lLine; cout << "using key: \"" << argv[1] << "\" "; cout.flush(); while ( getline( lReader, lLine ) ) { lOutput << lScambler.Encode( argv[1], lKeyIndex, lLine ) << endl; cout << "."; cout.flush(); } cout << endl; //----- done ----------------------------------------------------// lReader.close(); lOutput.close(); return 0; }