How do hackers program gift code generators?

I want to be a programmer when I grow up and and have been fascinated by different programs that have been made. But there's one question I would like to know. How do hackers program programs such as gift code generators. Because I know they would have to use a computer language such as C, C++, java but just how is it they do it to make legit gift codes and stuff for websites like steam powered or Minecraft. Please try to explain to me, I'm really fascinated by this concept and would really like to know.

Added (1). I've seen videos of people doing it so I don't know what to think now

There's no legit gift code generator, its impossible to do because the codes have to be activated and generators can't activate them. The only thing you get with a gift code generator is viruses and disappointment.

Most of the keygens contain only the keycode strings, they don't really generate anything. And these work only offline, only if the app doesn't check if the code is legit. And I don't think that there are any legit gift code gens. Hackers would need to hack the company's code generation engine along with the checking mechanism. That is virtually impossible and I haven't ever seen that… It doesn't really depend on programming language. You can use various programming languages to do the same thing.