wonderingmind 0 Newbie Poster

I am having an issue with my decryption out.txt file. I have gotten the program to open the input file in note pad and encrypt. to an output text file but when I try to decryp to an out text file it doesn't do anything. I figure I am missing something simple but can't put my finger on it. Assistance (leading me in the right direction) would be appreciated. I apologize that all this code may be unnecessary but I included it to make sure there was enough to take a good look at it.

##include <iostream>
#include <fstream>
#include <string>

using namespace std;

    void mapE(string,char[]);
    void mapD(string,char[]);
    void mixitup(const string,const char[],int,string&);

int main()

    {string end[]={"encrypt","decrypt"},ekey, buffer,buffer2="";
    char file[80],enmap[128],demap[128],again;
    int  maplength;
    ofstream out;
    ifstream in;

int num;
do
{
    cout<<"Please enter 1 to perform encryption and 2 to perform decryption: ";
    cin>>num;

while(num<1||num>2)

      {cout<<"Invalid Entry!!\n";
       cout<<"Please enter 1 for encryption, 2 for decryption: ";
       cin>>num;
       }

    cout<<"Please enter the name of your file to "<<end[num-1]<<": ";
    cin>>file;

    in.open("C:\\users\\Ken S\\Documents\\input.txt");       

if(in.fail())           

   { cout<<"The input file entered did not open please check it\n";

   system("pause");
   return 1;
   }

    cout<<"Please enter the name of your output file: ";
    cin>>file;

    out.open("C:\\users\\Ken S\\Documents\\output.txt");

    cout<<"Please enter your encryption key (max 128 characters): ";
    cin>>ekey;
if(ekey.length()>128)
    {cout<<"The key entered is too long\n";
     cout<<"Enter your encryption key (max 128 characters): ";
     cin>>ekey;
     }
maplength=ekey.length();

if(num==1)

   mapE(ekey,enmap); 

else

   mapD(ekey,demap);

   getline(in,buffer);

while(in)
   { 
   if(num==1)

         mixitup(buffer,enmap,maplength,buffer2);

   else

         mixitup(buffer,demap,maplength,buffer2);
         out<<buffer2;

   getline(in,buffer);
   }  

    out.close();
    in.close();
    in.clear();
    out.clear();
    buffer2.erase(0);

    cout<<"would you like to perform another operation? (y/n)? ";
    cin>>again;
}
while(toupper(again)=='Y');

return 0;
}

void mixitup(const string buffer,const char map[],int len,string& buffer2)
{
int i=0;
char t,code;

for(i = 0;i < buffer.length();i++)
    { 
if(isalpha(buffer[i]))
{

if(islower(buffer[i]))
     code='a';

else

     code='A';
     t=buffer[i]-code;

     t=t+map[i%len];
     t=t%26;
     t=t+code;
     buffer2.push_back(t);
}

else

     buffer2.push_back(buffer[i]);
)

    buffer2.push_back('\n');
}

void mapE(string ekey,char map[])
{
int i;

for(i = 0;i < ekey.length();i ++)

     map[i]=ekey[i] - 'a';
}
void mapD(string ekey,char map[])
{
int i;

for(i = 0;i < ekey.length(); i++)

     map[i]=26 - (ekey[ i ] - 'a');
}