1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
int main(int argc, char* argv[])
{
ifstream fin;
fin.open("testfile.txt", fstream::in); //Opens the text file - fstream::binary as well??
if(!fin.is_open()) //If the file opening fails, ERROR message prints
{
printf("ERROR: The file open failed.\n");
system("PAUSE");
exit(1);
}
else
{
printf("File opened successfully!\n");
}
char message[BLOCKSIZE];
char key[16];
int length;
char * buffer;
// get length of file:
fin.seekg (0, fstream::end);
length = fin.tellg();
fin.seekg (0, fstream::beg);
cout << "Length of file: " << length << "\n";
// allocate memory:
buffer = new char [length];
// read data as a block:
fin.read (buffer,length); //replace length with 188 in some sort of loop??
fin.close();
strcpy(message, buffer.c_str());
delete[] buffer;
srand ( time(NULL) );
// generate a random key
for (int i=0;i<16;i++) {
key[i]=rand() % 256;
}
int msglen=BLOCKSIZE;
printf("original message: %s\n",message);
TestEncryptor(key,16*8,(BYTE*)message,msglen);
printf("encrypted message: %s\n",message);
TestDecryptor(key,16*8,(BYTE*)message,msglen);
printf("decrypted message: %s\n",message);
gets(message);
return 0;
fin.close();
}
|