Encrypting via Blowfish?

Doubts, help and support about QuickBMS and other game research tools
HenryEx
Posts: 27
Joined: Wed Aug 13, 2014 6:43 pm

Encrypting via Blowfish?

Post by HenryEx »

Hey, it's me again! It's been a while.
So i'm currently working on game files that are encrypted via blowfish, to modify them and use them in the game again. The decryption works wonderfully painless, using just these 3 lines:

Code: Select all

  Encryption blowfish KEY
  log MEMORY_FILE FILESTART FILESIZE MEMORY_FILE
  Encryption "" ""


However, it seems i can't ENcrypt with the same. If i use the above on an encrypted file once, it's plain, but when i use it on the file twice, the resulting file doesn't match the original.
I don't know much about encryptions, which is why i like using QuickBMS which supports tons of them natively, so i just assumed you could use the same command to encrypt a file again with a certain key. Is that not the case?


edit: Unrelated to this, but isn't there some kind of simple bytesum function somewhere in QuickBMS? I was looking for it, but didn't find anything. I somehow felt like there should have been, even though it's trivial to solve it with just 4 lines of code:

Code: Select all

for i = 0 < FILESIZE
    get SBYTE byte
    math SUM + SBYTE
next i
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Encrypting via Blowfish?

Post by aluigi »

To encrypt use:
Encryption blowfish KEY "" 1

Where:
"" is the field for the ivec (in this case left empty)
1 is the mode: 0=decrypt 1=encrypt

Regarding the bytesum algo, take a look at Encryption crc that contains a complete engine to calculate many types of checksums, most of which are documented only in the crc.c source code.
In your case I guess you want the following:
Encryption crc "32 0 0 6"

Where:
32 is the size of the crc
0 is the initial value of the crc
0 is the final xor value
6 is the type corresponding to "MYCRC + MYBYTE" which is what you requested

The result is stored in the QUICKBMS_CRC variable.
HenryEx
Posts: 27
Joined: Wed Aug 13, 2014 6:43 pm

Re: Encrypting via Blowfish?

Post by HenryEx »

Oh wow, that was simple. I guess i missed the MODE parameter explanation at the end of that looooong list of algorithms. :lol: I mostly had to work with xor "encryption" so far, which works both ways.
Now that they work, i'll post the scripts on the forum for posterity, over in the "Savegames" section. :)

As for the bytesum thing, i had a feeling it was somewhere in that CRC encryption thing. I didn't take too hard a look at it, since it kinda felt overqualified, like cracking a nut with a sledgehammer.

Thanks for the quick response!
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Encrypting via Blowfish?

Post by aluigi »

Yeah, I agree, the list of encryption and comtype algorithms is really huge and confusing, and the lack of documentation for the CRC algorithms doesn't help too. Luckily crc.c should be enough easy to understand and, in case of problems to recognize the correct algorithm, an idea is to use the crc scanner that provides the parameters to use.

The idea of having CRC and HASH algorithms in the Encryption command was caused by the experimental nature of this feature, probably would be better to have a separate new command for that like CalcHash or similar with the same identical syntax and usage of the Encryption command.
But it's just an idea, I would like to avoid to add new commands to quickbms.