2

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';

    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Have you tried to pass each argument between " character? Like: vigenere.exe -e "that's my string" ? – hypnos Dec 05 '16 at 16:58
  • im not having a problem actually passing the arguments, im having an issue with converting them into chars in the actual code (which is what it needs to be using ASCII to do the encryption) , while they're passed in as strings if that makes sense – chiorboyatbest Dec 05 '16 at 17:20

1 Answers1

0

Try using strcmp rather than straight away comparing two strings. In

if (arg == "-e")

and

else if (arg == "-d")
Sanjay-sopho
  • 429
  • 3
  • 15