impl rsm, cd-k algorithm