ZenHAX

Free Game Research Forum | Official QuickBMS support | twitter @zenhax | SSL HTTPS://zenhax.com
It is currently Mon Oct 26, 2020 3:50 am

All times are UTC




Post new topic  Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Coding help :D
PostPosted: Tue Jul 07, 2020 3:04 pm 

Joined: Sat Aug 09, 2014 2:34 pm
Posts: 1100
Hey guys. I have a specific project for which it is necessary to encrypt some files back after decryption. The algorithm is simple (XOR) and I was hoping that it would work both ways (decrypt and encrypt data) but the function works as it turned out only in one direction - decrypt only. I need expert help and teach the function to correctly encrypt data back :)


Code:
uint8_t kBox1[20] = {
   0xEB, 0x57, 0x50, 0x86, 0x32, 0x0D, 0x27, 0x60, 0xF4, 0xDE,
   0xF2, 0x4F, 0x6F, 0x13, 0xDA, 0x7B, 0x29, 0x3F, 0xF1, 0x41};

uint8_t kBox2[20] = {
   0x2D, 0x50, 0xD7, 0x64, 0x17, 0xAB, 0x25, 0x0B, 0xC0, 0x3E,
   0x61, 0x49, 0x20, 0x7A, 0x8E, 0x78, 0xA0, 0x67, 0x8D, 0x29};
   
uint32_t Var4 = 0;
int32_t Var8 = (kBox2[16] * kBox1[12]) * dwSize;

for(int32_t i = 0; i < dwSize; i++)
{
    uint32_t j = int32_t(Var8 & (Var4 << 11)) >> (kBox2[19-(i % 20)] % 7);
    lpBuffer[i] ^= kBox1[j % 20] ^ (j + j / 255) ^ kBox2[i % 20];
    Var4 += dwSize;
}


Files for testing are attached. I will be glad to any help and advice.

Thanks in advance :)


Attachments:
TEST_FILES.rar [431.71 KiB]
Downloaded 34 times
Top
   
 Post subject: Re: Coding help :D
PostPosted: Tue Jul 07, 2020 9:44 pm 
Site Admin
User avatar

Joined: Wed Jul 30, 2014 9:32 pm
Posts: 11690
The function works with both encryption and decryption, it's the same.

The only difference is that the encrypted file has an additional footer at the end "TGCA\x14\x10\x06\x15" so when you decrypt it you must remove the 8 bytes from dwSize.


Top
   
 Post subject: Re: Coding help :D
PostPosted: Wed Jul 08, 2020 9:55 am 

Joined: Sat Aug 09, 2014 2:34 pm
Posts: 1100
Thanks Luigi for answer.

Unfortunately, I already tried to encrypt but the data is different, except for the 1st byte. In addition, the encrypted file is not decrypted by this function - the output data is like garbage :)

Comparison:

First 0x200 bytes of original:

Image

And first 0x200 of new file

Image

Therefore, I wonder what could be the solution :)


Top
   
 Post subject: Re: Coding help :D
PostPosted: Wed Jul 08, 2020 10:11 am 

Joined: Sat Aug 09, 2014 2:34 pm
Posts: 1100
Ah, i'm idiot :lol:


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 4 posts ] 

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Limited