Hey all, this is my first post here so if Im breaking any rules please let me know. Ive been programming since I was about 10 or 11, I started out with liberty basic and I remember the first program I wrote was

Code:
Input A
Input B
A+B=C
Print C
After that it was a little dabbleing in AI and then I fell in love with encryption. I wrote a Simple Substitution program, it was great! It had two passwords one the user entered and the other that was saved as a text file that if it wasnt found would delete the message and the program (which turned to to be a real pain during testing). I even had it set up so you could select one of three keys, I felt like not even the enigma could bet me out. Heck I even had the decoder automatically open up a .txt file and decode it. You didnt even have to tell the program what cipher you used! Then disaster struck, I found a way to break my master piece with pencil, paper and a highlighter if I could find it. So then me and my grand father ( A programmer of the punch card days) we decided to tackel the almigthy C++. We knew that simple substitution wasnt going to be enough, so off to google it was. Then I found this sight and there it was XOR and now I have version 1.0 done and I keep coming up with new ideas. Sorry I digress



My problem is since Im currently using a DOS program and not a windows app, users cant copy and paste the material that they would like to encrpyt. So Im trying to get it so the user can open up wordpad and copy and paste into there and save it as a ritch-text format (.rtf) file. Then when you run the encryption program it opens the file up and you enter the key. I have a decoder that does the same thing but I cant get it to work with the encoder.




Here is the working encoder and decoder

Encoder:

Code:
/*XOR encryption program v1.0*/
#include <fstream.h>
#include <iostream.h>
#include <stdlib.h>


int main (void)
{

int message_length, cipher_length, j, k;  
char message[500];    
char cipher[100];           
std::cout <<"Key in your message, up to 500 characters.";
std::cout << "\n";
std::cin.getline(message,500); 
std::cout <<"Key in your cipher, up to 100 characters.";
std::cout << "\n";
std::cin.getline(cipher,100);     
message_length = strlen (message); 
cipher_length = strlen (cipher);   


j=1;
k=1;
while((j<=message_length)){
                       message[j-1]=message[j-1]^cipher[k-1]; 
                       if((k==cipher_length)){
                                            k=0;
                                            }
                       j=j+1;
                       k=k+1;
                       }
ofstream a_file ( "example.rtf" );
a_file<< message;
std::cout << message;                             
std::cout << "\n";


std::cout << "\n";
  system("PAUSE");
     return 0;


}
Decoder:
Code:
/*XOR Decryption program v1.0*/
#include <fstream.h>
#include <iostream.h>
#include <stdlib.h>


int main (void)
{

int message_length, cipher_length, j, k;  
char message[500];    
char cipher[100];           
ifstream b_file ( "example.rtf" );
b_file>> message;
std::cout <<"Key in your cipher, up to 100 characters.";
std::cout << "\n";
std::cin.getline(cipher,100);     
message_length = strlen (message); 
cipher_length = strlen (cipher);   

j=1;
k=1;
while((j<=message_length)){
                       message[j-1]=message[j-1]^cipher[k-1]; 
                       if((k==cipher_length)){
                                            k=0;
                                            }
                       j=j+1;
                       k=k+1;
                       }
std::cout << message;                              
std::cout << "\n";


std::cout << "\n";
  system("PAUSE");
     return 0;


}


Here is the one thats not working
Code:
/* XOR encryption program v1.1b*/
#include <fstream.h>
#include <iostream.h>
#include <stdlib.h>


int main (void)
{

int message_length, cipher_length, j, k; 
char message[500];    
char cipher[100];      
ifstream b_file ( "message.rtf" );
b_file>> message;
std::cout <<"Key in your cipher, up to 100 characters.";
std::cout << "\n";
std::cin.getline(cipher,100);    
message_length = strlen (message); 
cipher_length = strlen (cipher);   

std::cout << "message is - " << message;      
std::cout << "\n";
std::cout << "cipher is - " << cipher;         
std::cout << "\n";
std::cout << "length of message is " << message_length; 
std::cout << "\n";
std::cout << "length of cipher is " << cipher_length; 
std::cout << "\n";
std::cout << "the first character of message is " << message[0]; 
std::cout << "\n";
std::cout << "the last character of message is " << message[message_length-1];
std::cout << "\n";
std::cout << "the first character of cipher is " << cipher[0]; 
std::cout << "\n";
std::cout << "the last character of cipher is " << cipher[cipher_length-1]; 
std::cout << "\n";

j=1;
k=1;
while((j<=message_length)){
                       message[j-1]=message[j-1]^cipher[k-1]; 
                       if((k==cipher_length)){
                                            k=0;
                                            }
                       j=j+1;
                       k=k+1;
                       }
ofstream a_file ( "example.rtf" );
a_file<< message;
std::cout << message;                               
std::cout << "\n";


std::cout << "\n";
  system("PAUSE");
     return 0;


}
All the stuff in the middle acts as sort of like a error checking system. I really dont have any idea what im doing, Im not learning this A,B,C. Im just figuring out what I need as I go. So please dont smite me and make me feel little under your superior knowlege of C++. So any suggestions as to whats wrong?