So I have this code in C++ and I have a crypted picture and the content but I only know the way it is crypted trough this code, I need to reverse it in order to get the content in bytes of the picture but i don't know how, please help me.
This is in main, the buffers are of bytes.
bytesin = number of bytes of image
nrBytesOut= number of bytes in crypted image
bufferIN = the content of the image
bufferOut= the content of the crypted image
for (int contor = 0; contor < 256; contor++)
{
DWORD retvalue = 0;
for (int i = 0; i < bytesIn; i++) {
if (bufferIn[i] == contor) {
retvalue++;
}
}
if (retvalue == 0) { continue; }
CreateBufferOut(nrBytesOut, contor);
CreateBufferOut(nrBytesOut, retValue);
var18 = 0xffffffff;
Please use code tags when you post. Type [code] your code [/code] to generate something like the below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
for (int contor = 0; contor < 256; contor++)
{
DWORD retvalue = 0;
for (int i = 0; i < bytesIn; i++) {
if (bufferIn[i] == contor) {
retvalue++;
}
}
if (retvalue == 0) { continue; }
CreateBufferOut(nrBytesOut, contor);
CreateBufferOut(nrBytesOut, retValue);
// etc.
}
Without the code tags, I completely misunderstood what your code was doing. I actually had typed up a response that was meaningless. Code tags would have made it easier to read and understand your code so that comments are meaningful.
Where did you get this code? It looks like it has errors in it. For example, this
1 2
bufferOut[nrBytesOut] = value;
nrBytesOut += 4; //value is 4 bytes long
suggests that the programmer expects all 4 bytes of value to be copied into bufferOut, but that won't happen. Only the last byte will be stored.
Some other things about the code don't make much sense either. E.g., the way var18 is handled is strange. And nrBytesOut is almost certainly being handled incorrectly. It looks as if the programmer expects it to constantly be incremented so that new bytes will always be appended to bufferOut, but since it's passed in by value it will not retain it's updated value between calls.
Here's your code in code tags (with a couple of added comments indicated by ////).
I was able to fix up the encryption program so it works as intended (I think). I was also able to make a decrypter for it. But you seem to have lost interest in this exercise.
Here's the encryption program. I left the globals and C-style arrays, so obviously that could be done better.