Talk:Secret Agent encryption
With that comment about using value 0 instead of 0x31 for the 42nd byte of the map decryption, is that how the game does it? I didn't use that but the files still seem to decrypt ok. I imagine all files are encrypted the same way, so presumably this would have to happen for the image files too? -- Malvineous 04:00, 17 July 2011 (GMT)
- It doesn't matter whether you use value 0, 0x31 or any other value to decrypt the 42nd value for the level files, because the game only decrypts the first 40 bytes and it ignores the last two bytes of a level chuck. But when you do decrypt all 42 bytes of a level chunk yourself, it makes more sense to me to use value 0 instead of 0x31, because the chunk will end in a newline, or if the first 41 decrypted bytes are 0 then also the 42 decrypted byte will be 0. If you don't believe me, decrypt SAM103.GFX two times: one time using the value 0 and one time using the value 0x31. Then look at both results in a hex editor or with EDIT.COM /42 and then tell me which of the two results is the nicest.
- Because the game ignores the 41th and 42nd bytes in a level chunk, it doesn't matter what you do with those two bytes. But for the image chunks the game doesn't ignore the 41th and 42nd bytes, so for image chunks it's important to use value 0x31 for the 42nd byte and '9' for the 41th byte. Frenkel 16:56, 26 July 2011 (GMT)
- I do believe you, but in my code I am using the same algorithm to decrypt all the files, so if I am to use value 0 for the 42nd byte of maps I will need to add a special condition for only those files and treat them differently to all the others, which is more work. Since it sounds like the game doesn't do this, and your comment was just to make the files easier for a human to read, it seems I can omit the change and decompress all files in the same way. Yes it will make it more difficult for a human to read the map files in a text editor, but that's what map editors are for :-) Thanks for the clarification. Malvineous 03:06, 29 July 2011 (GMT)
- I'm glad it's more clear now, but I do have a problem with the part "this won't produce the exact original file". We don't know what the original file looks like. I think the chunks in the original file did end in 0x0D0A and that there was a bug in the encryptor that caused the last byte to not be XORed with any value. Frenkel
- It's possible, but since it would be a special case I'd like to know for sure (and given the way Crystal Caves stores the data it may or may not be the case.) I did do a memory dump of Secret Agent but couldn't locate the level data, so it looks like it processes it upon loading rather than storing the decrypted file otherwise unchanged in memory. I guess if you don't have any ideas about how to find this out for sure, you could always put a note on the page that it's unknown which way is correct. Still, would be nice to know... -- Malvineous 13:31, 31 July 2011 (GMT)