Decoding base64 encoded message with a key
That's a simple substitution cipher. Base 64 uses the following alphabet A-Za-z0-9+/. Here A encodes  000000, B encodes 000001 etc. In your case the g encodes 000000, P encodes 000001 etc.

Instead of writing your own decoder for that you can simply take the ciphertext, iterate through the characters of the ciphertext and replace g with A, P with B etc. After that you should be able to use a regular base 64 decoder to do the work for you.

Don't replace multiple characters at a time or you'll run into trouble. Put the characters in a new string instead (if you map g to A while there are still other A characters left then your algorithm will certainly fail).