#include /* printf, NULL */
#include /* srand, rand */
#include /* time */
#include /* file operations */
#include /* symbolic constants */
using namespace std;
int Gen(int length)
{
cout << "******************Attempting to write key to file*******************\n"<< endl; int randomData = open("/dev/random", O_RDONLY); // open file to get random values char myRandomData[length]; //determine the length of the key size_t randomDataLen = 0;// initialize counter while (randomDataLen < sizeof myRandomData) //read from file while key length is not larger than size of plain text { ssize_t result = read(randomData, myRandomData + randomDataLen, (sizeof …show more content…
Please check to ensure that the file exists and is in the directory of this message."; exit(0); } /*Attempting to open key*/ string key; ifstream keyfile ("keyfile"); // attempt to open the file if (keyfile.is_open()) //ensure file open was successful { while ( getline (keyfile,line) ) //for each line in the file { key+=line; // append the line to the variable to hold the message } keyfile.close();// close the file }
else //if file open operation was unsuccessful output an error message to the user and …show more content…
The key is stored in a file called keyfile" << endl; /*Open the file and determine the length of the plaintext to determine the length of the key */ string line; //variable to hold each line of the file as it is read string plaintext; //variable to hold the message to be encrypted int length; //variable to hold the length of the key ifstream myfile ("plaintext"); // attempt to open the file if (myfile.is_open()) //ensure file open was successful { while ( getline (myfile,line) ) //for each line in the file { plaintext+=line; // append the line to the variable to hold the message