A Back-tracing Code to Study the Magnetosphere Transmission Function for Primary Cosmic Rays