Decrypting Unknown Hash Encryption

965 Views Asked by At

I'm moving to MYSQL from files and I want to use md5 instead of Encryption

public Encrypt(string[])
{
 for(new x=0; x < strlen(string); x++)
   {
    string[x] += (3^x) * (x % 15);
    if(string[x] > (0xff))
    {
     string[x] -= 256;
    }
   }
 return 1;
}

But I need to decrypt it. I don't know how to make a decrypting function. Can anybody help me?

2

There are 2 best solutions below

5
On

It looks like the "encryption" adds to each character a number derived from its position. The encryption can be undone by subtracting by the same number.

public Decrypt(string[])
{
 for(new x=0; x < strlen(string); x++)
   {
    string[x] -= (3^x) * (x % 15);
    if(string[x] < (0x00))
    {
     string[x] += 256;
    }
   }
 return 1;
}
0
On

My understanding of PAWN is that it uses null-terminated strings. If that is the case, then this encryption is not a reversable process in general.

Consider a string where the thirteenth character (string[12]) is 'L'. The offset that will be added to that is (3^12) * (12 % 15), i.e. 180. In ASCII, the character 'L' has a value of 76, which when added to 180 is 256. After wrapping to fit in the 0-255 character range that becomes a zero, potentially terminating your encrypted string somewhere in the middle.

If you are storing the length of the original string separately or it's always a fixed length, then maybe this isn't a problem. But if you are relying on a null terminator to determine the length of the string, it isn't going to work.