I agree with SushiBox, this is way beyond me
I did have some success though; I worked out how to take the bytes of an int and calculate the int manually. The below code demonstrates this and the key line is:
// Calculate integer from bytes
int Return = ( (b[1]*Power(256,1) ) + (b[2] * Power(256,2) ) + (b[3] * Power(256,3) ) + b[0]);
Full code:
#include <iostream>
using namespace std;
// Finds the power of a number
int Power(int Number, int Power)
{
int Return = 1;
for(int n = 0;n<Power;n++)
{
Return = Return*Number;
}
return(Return);
}
// Performs core calculations
int ComputeInteger(unsigned char b[sizeof(int)])
{
// Calculate integer from bytes
int Return = ( (b[1]*Power(256,1) ) + (b[2] * Power(256,2) ) + (b[3] * Power(256,3) ) + b[0]);
// Show working
cout << "nBYTES: ";
for(int x = 0;x<sizeof(int);x++)
{
cout << " b" << x << ": ";
cout << (int)b[x];
cout << ", ";
}
cout << "nnCALCULATIONS: n";
for(int x = 0;x<sizeof(int);x++)
{
cout << " b[" << x << "]*Power(256," << x <<"): " << b[x]*Power(256,x);
cout << "n";
}
return Return;
}
void main()
{
// Get the integer to work with
cout << "Enter an integer to work with:";
int Integer;
cin >> Integer;
// Get bytes from integer
unsigned char Buffer[sizeof(int)];
*(int*)&Buffer = Integer;
// Perform calculations
int Computed = ComputeInteger(Buffer);
// Output results
cout << "nnComputed integer: " << Computed;
cout << "nCorrect integer: " << Integer;
cout << "nnDifference: " << Computed-Integer;
int Blank;
cin >> Blank;
}
Expanding on the above by adding in more bytes, the maximum size of the number could be increased.