Wierd, wierd compile errors.
Posted: Sat Apr 19, 2003 5:35 pm
I'm writing an encryption/de-encryption program pair, and have hit a brick wall. The first program (encrypt) writes the encrypted output to 'flatfile' and the random key to 'key'. The second program reads the information in from key, reads in from flatfile, and is supposed to use key to decrypt flatfile and put the output back out into flatfile.
First program runs fine (except for cout'ing the final output), second doesn't.
Help?
Encrypt
decrypt
First program runs fine (except for cout'ing the final output), second doesn't.
Help?
Encrypt
Code: Select all
#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
using namespace std;
int x = 0;
int rseed;
char message[1025];
char encrypt[1025];
int crypt();
int storeseed();
int main()
{
ofstream wfile("flatfile");
if(!wfile)
{
cerr << "File did not open correctly." << endl;
return(1);
}
else
{
cout << "Input message: ";
cin.getline(message, 1025, '\n');
crypt();
wfile << encrypt;
}
wfile.close();
ifstream rfile("flatfile");
if(!rfile)
{
cerr << "File did not open correctly." << endl;
return(1);
}
else
{
while(rfile.eof() != 1)
{
rfile >> message;
cout << message << " ";
}
}
rfile.close();
return(0);
}
int crypt()
{
srand(time(NULL));
rseed = rand();
storeseed();
while(x < 1026)
{
encrypt[x] = (message[x]*rseed);
x++;
}
return(0);
}
int storeseed()
{
ofstream xfile("key");
if(!xfile)
{
cerr << "File did not open correctly." << endl;
return(1);
}
else
{
xfile << rseed;
}
xfile.close();
return(0);
}decrypt
Code: Select all
#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
using namespace std;
int x = 0;
int rseed;
char message[1025];
char decrypt[1025];
int crypt();
int main()
{
ifstream rfile("key");
if(!rfile)
{
cerr << "File did not open correctly." << endl;
return(1);
}
else
{
rfile >> rseed;
cout << rseed;
}
rfile.close();
ifstream xfile("flatfile");
if(!xfile)
{
cerr << "File did not open correctly." << endl;
return(1);
}
else
{
while(xfile.eof() != 1)
{
xfile >> decrypt;
cout << decrypt;
}
}
xfile.close();
crypt();
ofstream wfile("flatfile");
if(!wfile)
{
cerr << "File did not open correctly." << endl;
return(1);
}
else
{
wfile << message;
}
wfile.close();
cout << message;
return(0);
}
int crypt()
{
while(x < 1026)
{
message[x] = (decrypt[x]/rseed);
x++;
}
return(0);
}