Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

/******************** *Payton Murray *vigenere cipher *CSC 442 *****************

ID: 3685849 • Letter: #

Question

/********************
*Payton Murray
*vigenere cipher
*CSC 442
********************/

#include <iostream>
#include <string>

using namespace std;

// String declarations
string eord, key, word;

// the encrpyting function it accepts two arguments
// the word that the user gave and the key specified by command line args
void Encrypt(string enc, string key)
{
   string result;
   int k=0;
// the main loop that actually encrpyts each letter of the word
   for (int i=0; i<enc.length(); i++)
   {
       result[i]=(((enc[i]-97)+(key[k]-97))%26)+97;
       k++;
       if(k== key.length())
           k=0;
   }
   for( int i=0; i<enc.length(); i++)
       cout << result[i];
   cout<<endl;
  
}

// the Decrypting function it accepts two arguments
// the the cryptic message and the key ised to encrypt it.
void Decrypt(string result, string key)
{
  
   //some code goes here?


}
int main( int argc, char* argv[])
{    
   while(true) // loop that allows the program to contiue running until ^C is hit
{
   eord = argv[1];
   key = argv[2];
  
   // prints out a prompt and recieves the word or words entered by the user
   cout << "> ";
   getline(cin, word);

   // the if else statement that checks for encoding or decoding
   if (eord =="-e")      
       Encrypt(word, key);
                                                                                                                  
   else if( eord == "-d")
   {
       cout << "HEY " << endl;
   }
}
   return 0;
}

This is my code so far i cant figure out the decoding part. i am running the program in linux a such ./cipher -e key this is for encoding it works however it doetn do spaces for example if i put in hello world it will translate the " " as R. any way i need it to match the following exxamples:

jgourd@latech:~$ ./vigenere -e key
hello <-- I typed this
rijvs <-- my code generated this
HELLO <-- I typed this
RIJVS <-- my code generated this
^C <-- I pressed Ctrl+C
jgourd@latech:~$ ./vigenere -e KEY
hello
rijvs
HELLO
RIJVS
^C
jgourd@latech:~$ ./vigenere -d key
rijvs
hello
RIJVS
HELLO
^C
jgourd@latech:~$ ./vigenere -d KEY
rijvs
hello
RIJVS
HELLO
^C
jgourd@latech:~$ ./vigenere -e "This is my key"
hello world
altdw oapvh
This is my message that I am sending you!
Moqk qk yw wiqlhow bzmr S ek llvvqfs wyy!
Get ready for Cyber Storm dudes! We're going to video game your butts on May 5!
Zlb jmspw psp Vfjwz Kfmbq bnkmk! Ew'dc qsggn bg dapcy kyfl ggcj nsdxq hu Usg 5!
^C
jgourd@latech:~$ ./vigenere -d "This is my wrong key"
Zlb jmspw psp Vfjwz Kfmbq bnkmk! Ew'dc qsggn bg dapcy kyfl ggcj nsdxq hu Usg 5!
Get ready tbb Izzsb Ryeji jbmqt! Qj'xs munzf jy lorgh wlzb cijc favfe jy Det 5!
^C
jgourd@latech:~$ ./vigenere -d "This is my key"
Zlb jmspw psp Vfjwz Kfmbq bnkmk! Ew'dc qsggn bg dapcy kyfl ggcj nsdxq hu Usg 5!
Get ready for Cyber Storm dudes! We're going to video game your butts on May 5!
^C

my code is in c++ any help would be great thank you!

Explanation / Answer

Hi below i have written the sample code for vigenere cipher encryption/decryption for your reference, #include #include using namespace std; class Vigenere { public: string key; Vigenere(string key) { for(int i = 0; i = 'A' && key[i] key += key[i]; else if(key[i] >= 'a' && key[i] key += key[i] + 'A' - 'a'; } } string encrypt(string text) { string out; for(int i = 0, j = 0; i = 'a' && c 'Z') continue; out += (c + key[j] - 2*'A') % 26 + 'A'; j = (j + 1) % key.length(); } return out; } string decrypt(string text) { string out; for(int i = 0, j = 0; i = 'a' && c 'Z') continue; out += (c - key[j] + 26) % 26 + 'A'; j = (j + 1) % key.length(); } return out; } }; int main() { Vigenere cipher("VIGENERECIPHER"); string original = "Hi! Hope so you having a beautiful day"; string encrypted = cipher.encrypt(original); string decrypted = cipher.decrypt(encrypted); cout