First off I appreciate any help that you all may provide. Also I made this post for two reasons. One of which being to give anyone out there wanting a XOR encryption function the chance to use this one, and also I have a question between the 2 code snippets at the bottom of the post.
The working function ( I removed the key I used for privacy, but it is easy to add your own, if you cant your hopeless)
//crypt.h
Code:
#include <string>
struct CRYPT_
{
char byte;
std::string key;
};
bool Crypt(const std::string&);
//crypt.cpp
Code:
#include "crypt.h"
#include <fstream>
using namespace std;
CRYPT_ data;
bool Crypt(const std::string& file)
{
char savebyte;
int value = 0;
data.key = "type new key here";
ifstream load (file.c_str(), ios::binary);
if (!load)
{
return false;
}
ofstream save ("encrypted.xtc", ios::binary);
while (load.get(data.byte))
{
savebyte = data.byte ^ data.key[value];
save << savebyte;
if ( value < 92 )
{
++value;
}
else {
value = 0;
}
}
save.close();
load.close();
remove(file.c_str());
rename("encrypted.xtc", file.c_str());
return true;
}
That is for anyone that may have been looking for something like this.
Now my question is why will this work
Code:
while (load.get(data.byte))
{
savebyte = data.byte ^ data.key[value];
save << savebyte;
if ( value < 92 )
{
++value;
}
else {
value = 0;
}
}
but on the other hand this looks pretty much the same, but I get a lot of errors trying this...
Code:
while (load.get(data.byte))
{
save << data.byte ^ data.key[value];
if ( value < 92 )
{
++value;
}
else {
value = 0;
}
}
Thank you very much for taking your time to assist me. Good day.