I just read a great article on this that breaks things down very well. You can find the original article here: http://fredparke.com/blog/create-your-own-tokens-drupal-7
Basically, you need to use two hooks. The first one tells the system about your token. The second one contains the specific logic for your token.