baby steps / giant steps algorithm