A basic question, but I'm not a master and this is puzzling me-

How is it possible to authenticate a client from the server's perspective?

i.e. imagine you're the server, and you want to give the client a key, but only if you're sure that the client is really the software you wrote and not someone pretending to be your software so that they can grab the key?

The only solution I can think of is various combinations of hardcoding a private key in the client, or hardcoding a predictable algorithm (i.e. server says "n" and client must say "n\*2" back)... but any of this is crackable via decompiling... ?

In case it matters, the client-software needs to be O/S agnostic, i.e. run on windows, mac, linux, android, ios, etc.