Daniel Shanks' Baby step-Giant step implementation