I've made a program a while back that I just discovered was broken. Which is rather strange since it functions correctly on very certain file sizes.I've spend upwards of several days trying to figure out the issue however I am running out of ideas. So I am here to ask can someone spot the error with this code.
#ifndef _code_h_
#define _code_h_
#include <iostream>
#include <string>
#include <thread>
#include <Windows.h>
#include <stdio.h>
#include <vector>
#include <stdlib.h>
#include <fstream>
#include <array>
#include "lib/aes.h"
#include "lib/modes.h"
#include "lib/filters.h"
using namespace std;
using namespace CryptoPP;
class stringAesCypher
{
public:
void encode (string data,string Skey,string &out)
{
byte key[16];
byte iv[16];
string bin;
string theKey(Skey);
int i(0);
theKey.append("t;rke;tlrke65409654ytr");
while(i != 16)
{
key[i] = theKey[i];
iv[i] = theKey[i];
i++;
}
CryptoPP::ECB_Mode< CryptoPP::AES >::Encryption
Encryptor( key, sizeof(key));
CryptoPP::StringSource( data, true,
new CryptoPP::StreamTransformationFilter( Encryptor,
new CryptoPP::StringSink( out )
) ); }
void decode (string CT,string Skey,string &out)
{
byte key[16];
byte iv[16];
string bin;
string theKey(Skey);
int i(0);
theKey.append("t;rke;tlrke65409654ytr");
while(i != 16)
{
key[i] = theKey[i];
iv[i] = theKey[i];
i++;
}
CryptoPP::ECB_Mode< CryptoPP::AES >::Decryption
Decryptor( key, sizeof(key) );
CryptoPP::StringSource( CT, true,
new CryptoPP::StreamTransformationFilter( Decryptor,
new CryptoPP::StringSink( out )
) ); }
};
class Core
{
private:
string ram[8];
string ramTemp[8];
string theMode;
string theKey;
public:
void wipeRam()
{
for(int i = 0; i != 8; i++)
{
ram[i].resize(0);
ramTemp[i].resize(0);
}
}
void cores(int rRam)
{
stringAesCypher Code;
if(theMode == "E")
{
Code.encode(ram[rRam],theKey,ramTemp[rRam]);
ram[rRam] = ramTemp[rRam];
}
if(theMode == "D")
{
Code.decode(ram[rRam],theKey,ramTemp[rRam]);
ram[rRam] = ramTemp[rRam];
}
}
void startCores()
{
thread t1(&Core::cores,this,0);
thread t2(&Core::cores,this,1);
thread t3(&Core::cores,this,2);
thread t4(&Core::cores,this,3);
thread t5(&Core::cores,this,4);
thread t6(&Core::cores,this,5);
thread t7(&Core::cores,this,6);
thread t8(&Core::cores,this,7);
t1.join();
t2.join();
t3.join();
t4.join();
t5.join();
t6.join();
t7.join();
t8.join();
}
void splitIT(string &buffer)
{
int round(0);
int theTotal(0);
if(theMode == "E")
{
theTotal = 12500000;
}
if(theMode == "D")
{
theTotal = 12500016;
}
for(int i = 0; i != 8; i++)
{
if(round > buffer.length())
{
break;
}
else
{
ram[i] = buffer.substr(round,theTotal);
round = round + theTotal;
}
}
}
void readWriteSystem(string inFileName,string outFileName,string mode,string key)
{
int roundsOnSubBuffer(0);
int theTotalRamData(0);
int ramSlot(0);
int ramPlace(0);
theKey = key;
theMode = mode;
size_t buffer_size; if(mode == "E")
{
buffer_size = 100000000; }
if(mode == "D")
{
buffer_size = 100000128; }
string buffer(buffer_size,'\0'); ifstream fileStreamIn(inFileName,ios::binary);
ofstream fileStreamOut(outFileName,ios::binary);
while(fileStreamIn)
{
buffer.resize(buffer_size);
fileStreamIn.read(&buffer.front(), buffer_size);
size_t count = fileStreamIn.gcount();
buffer.resize(count);
splitIT(buffer);
startCores();
buffer = "";
for(int i = 0; i != 8; i++)
{
theTotalRamData = theTotalRamData + ram[i]
.length();
}
for(int i = 0; i != 8; i++)
{
buffer.append(ram[i]);
}
fileStreamOut.write(buffer.c_str(),buffer.length());
wipeRam();
if (!count)
break;
}
fileStreamIn.close();
fileStreamOut.close();
}
};
#endif