This is my C++ code to data encryption. The code runs, but does not work correctly! I don't know what is wrong The debugger shows this error:
An unhandled exception at 0x0FA6F6E0 (ucrtbased.dll) in ConsoleApplication6.exe:
0xC0000005: A read access violation at 0x00000000 has occurred
Here is my code:
#include<iostream>
#include<conio.h>
#include<fstream>
#include<string.h>
#include<stdlib.h>
#include<math.h>
using namespace std;
void main(int argc, char **kluch)
{
system("cls");
cout << "Key: N+3" << kluch[1];
ifstream in("C:\\Users\\s1mi\\source\\repos\\ConsoleApplication6\ConsoleApplication6\123\Input.txt");
ofstream out("C:\\Users\\s1mi\\source\\repos\\ConsoleApplication6\ConsoleApplication6\123\Output.txt");
if (!in)
{
cout << "\nThere is no filefor coding (Input.txt).";
cout << "\n\nPres any key for exit.";
_getch();
exit(1);
}
char temp, buf = NULL;
int n = strlen(kluch[1]);
int j, i = 0;
for (int k = 0; k < n; k++)
while (!in.eof())
{
in.read((char*)&buf, sizeof(buf));
if (buf == NULL)break;
j = fmod(i, n);
temp = buf ^ kluch[1][j];
out.put(temp);
i++;
buf = NULL;
}
in.close();
out.close();
cout << "\nThe text is in a file Output.txt";
_getch();
}