I'm trying to write a Vigenere Cipher that reads in (-e to encrypt, -d to decrypt), a key word (used during the encryption), a text file where the original message comes from, and another text file where the encrypted/decrypted message is outputed to, all from command line arguments. I'm having an issue with how to read everything from the command line in as a string and using chars for the actual encryption. I've found alot of other programs on just vigenere ciphers, but none where all of the arguments are read in from the command line. Here is my (unfinished) code.
#include<iostream>
#include<string>
#include<fstream>
#include<sstream>
using namespace std;
char encipher(char key, char plain);
char decipher(char key, char cipher);
int main(int argc, char* argv[]){
ifstream inFile(argv[3]);
ofstream outFile(argv[4]);
string key = argv[2];
for (int i = 0; i < argc; i++){
string arg = argv[i];
if (arg == "-e"){
inFile.open(arg.c_str());
string plain = ;
encipher(key, plain);
}
else if (arg == "-d"){
inFile.open(arg.c_str());
decipher(key, cipher);
}
}
char encipher(char key, char plain){
for (int i = 0; i < key.size(); i++){
if (key[i] >= 'A' && key[i] <= 'Z')
key += key[i];
else if (key[i] >= 'a' && key[i] <= 'z')
key += key[i] + 'A' - 'a';
return key;
}
}
char decipher(char key, char cipher){
for (int i = 0; i < key.size(); i++){
if (key[i] >= 'A' && key[i] <= 'Z')
key -= key[i];
else if (key[i] >= 'a' && key[i] <= 'z')
key -= key[i] + 'A' - 'a';
}
}