Doom cheat code encryption
Doom cheat code encryption was used in the original 1993 version of Doom to make the cheat codes a little harder for hackers to find, so they didn't appear in the raw binary code as plain ASCII characters. (Of course, the hackers found them anyway.) Twitter user @Foone described it in a 2019 thread.
This low-grade encryption is done by shifting the bits of 8-bit numbers (which can represent single ASCII characters) which reverses the order of the bits except for those representing 4 and 32. The shifted values are stored in a lookup table in the Doom program.
As described by @Foone, who has allowed his descriptions to be released as CC0 so they can be used here:
- So Doom (1993) has a neat bit of encryption in it. It's not very strong encryption, but it's still encryption.
And it's not used in any sort of way you'd normally expect: not copy protection, or multiplayer anti-cheat, or anti-tampering on saves... It's to slow down FAQs.
- So here's the code I'm talking about, the macro SCRAMBLE
It looks annoyingly complicated but it's not, really. It's taking an 8-bit number and shifting around some of the bits.
- If you diagram out what's happening, it makes slightly (BUT ONLY SLIGHTLY) more sense.
It kinda looks like they started with a a "reverse the order of these bits" function but then switched it so the 4 and 32 don't get switched, they just go straight through.
The thread goes on to describe the lookup table used to find these values, and the cheat codes embedded in encrypted form, and more discussion of how they were used and discovered. It's worthwhile reading for people into this sort of trivia.