An implementation of the Tonelli-Shanks algorithm