Hi there,

The code below is part of a project that runs on a linux based c++ compiler. I'm afraid I know little of the unix environment but I know where the problem in the code is. After checking up on the internet I realised that windows does not support the "unistd.h" header file. As a result the open, read and write commands in the code are not recognised. Does anyone know how to change the code so that it works under windows (by the way, I'm using Microsoft Visual C++ to compile). Thanks a lot.

#include "numtheory.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <iostream>
#include <string>

void encrypt(const string& file, number exponent, number modulus);

int main()
{
cout << "Enter name of file to encrypt: " << flush;
string file; cin >> file;

cout << "Enter Enciphering Key: e = " << flush;
number e; cin >> e;

cout << "Enter Modulus: N = " << flush;
number N; cin >> N;

encrypt(file, e, N);

return 0;
}

void encrypt(const string& file, number exponent, number modulus)
{
cout << "Encrypting: exponent is " << exponent << ", N is " << modulus << endl;

const int BUF_SIZE = 8192;

unsigned char input_buffer[BUF_SIZE];
unsigned int output_buffer[BUF_SIZE];

int input_file = open(file.c_str(), O_RDONLY);
int output_file = open((file + ".encrypted").c_str(), O_WRONLY | O_CREAT);

while(1)
{
// Step 1: Read BUF_SIZE bytes of file into input buffer.

int bytesRead = read(input_file, input_buffer, BUF_SIZE);
if (bytesRead == 0)
{
// done with file.
break;
}


// Step 2: Encrypt this block of data and store in output buffer.

for(int i = 0;i < bytesRead;++i)
{
output_buffer[i] = powermod( input_buffer[i], exponent, modulus );
}

write(output_file, output_buffer, sizeof(unsigned int) * bytesRead);
}

cout << "Done encrypting." << endl;

close(input_file);
close(output_file);
}